Link to home
Start Free TrialLog in
Avatar of Hifiger
Hifiger

asked on

Main Menu auto dropdown

Hi Guys,

Do you know how to create a program that will dropdown the MainMenu, automatically with Item selected specifically.

Please let me know

thanks in advance
Avatar of Hifiger
Hifiger

ASKER

example:

      Main menu                                   Button1.Onclick(sender:tobject)
           ... entry                                   begin     Mainmenu.dropdown
           ... edit                                         Mainmenu.dropdown
           ... delete                                      Mainmenu.select (item) = true
                                                         end;



      I don't know I how to do it in delphi that will click the button and the Menu will just dropdown
      and at the same time the item will be selected.

      Please help thanks

     
Hi,  Hifiger

procedure TForm1.Button1Click(Sender: TObject);

  procedure DropMenuAndSelectItem(MainMenuItemIndexAccel,ItemIndex:integer);
  var
    n : integer;
  begin
    //Activate MainMenu
    keybd_event( VK_MENU, Mapvirtualkey( VK_MENU, 0 ), 0, 0 );
    keybd_event( VK_MENU, Mapvirtualkey( VK_MENU, 0 ), KEYEVENTF_KEYUP, 0 );

    keybd_event( VK_RETURN, MapVirtualKey( VK_RETURN, 0), 0, 0 );
    keybd_event( VK_RETURN, MapVirtualKey( VK_RETURN, 0), KEYEVENTF_KEYUP, 0 );

    //Select MainMenuItem
    while (MainMenuItemIndexAccel>0) do begin
      keybd_event( VK_RIGHT, MapVirtualKey( VK_RIGHT, 0), 0, 0 );
      keybd_event( VK_RIGHT, MapVirtualKey( VK_RIGHT, 0), KEYEVENTF_KEYUP, 0 );
      Dec(MainMenuItemIndexAccel);
    end;

    //Select SubItem
    while (ItemIndex>0) do begin
      keybd_event( VK_DOWN, MapVirtualKey( VK_DOWN, 0), 0, 0 );
      keybd_event( VK_DOWN, MapVirtualKey( VK_DOWN, 0), KEYEVENTF_KEYUP, 0 );
      Dec(ItemIndex);
    end;
  end;
begin
  //Drop and select second item of the first MainMenuItem
  DropMenuAndSelectItem(0,2);
end;
Sorry, third Intem in the example (count begins in 0)
Again... (too many rums tonight...)

procedure TForm1.Button1Click(Sender: TObject);

  procedure DropMenuAndSelectItem(MainMenuItemIndex,ItemIndex:integer);
  var
    n : integer;
  begin
    //Activate MainMenu
    keybd_event( VK_MENU, Mapvirtualkey( VK_MENU, 0 ), 0, 0 );
    keybd_event( VK_MENU, Mapvirtualkey( VK_MENU, 0 ), KEYEVENTF_KEYUP, 0 );

    keybd_event( VK_RETURN, MapVirtualKey( VK_RETURN, 0), 0, 0 );
    keybd_event( VK_RETURN, MapVirtualKey( VK_RETURN, 0), KEYEVENTF_KEYUP, 0 );

    //Select MainMenuItem
    while (MainMenuItemIndex>0) do begin
      keybd_event( VK_RIGHT, MapVirtualKey( VK_RIGHT, 0), 0, 0 );
      keybd_event( VK_RIGHT, MapVirtualKey( VK_RIGHT, 0), KEYEVENTF_KEYUP, 0 );
      Dec(MainMenuItemIndex);
    end;

    //Select SubItem
    while (ItemIndex>0) do begin
      keybd_event( VK_DOWN, MapVirtualKey( VK_DOWN, 0), 0, 0 );
      keybd_event( VK_DOWN, MapVirtualKey( VK_DOWN, 0), KEYEVENTF_KEYUP, 0 );
      Dec(ItemIndex);
    end;
  end;
begin
  //Drop and select third item of the first MainMenuItem
  DropMenuAndSelectItem(0,2);
end;
Avatar of Hifiger

ASKER

Hi RadikalQ3 ,

Yes, It works by clicking the button and the menu drops down. But what I mean, was how can I select a certain item... example I will going to select the 2nd item, what are the codes needed inorder for the item to be highlighted? : )
Avatar of Hifiger

ASKER

example:

      Main menu                                   Button1.Onclick(sender:tobject)
           entry                                       begin    
           edit                                             MainMenu.('Edit').selected:=True
           delete                                      
                                                         end;



How do we do it, from your code?
ASKER CERTIFIED SOLUTION
Avatar of RadikalQ3
RadikalQ3
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hifiger

ASKER

ops! yes, it was located at the bottom of your source code.

Thanks
too many rums too? jeejeje