Главная страница | назад





Article #16707: Programmatically dropping down a menu

 Question and Answer Database

FAQ1707D.txt   Programmatically dropping down a menu
Category   :VCL
Platform    :All
Product    :All 32 bit  

Question:
How can I programmatically drop a menu down in code?

Answer:
The following example demonstrates both dropping down a menu and
selecting a menu item by synthesize menu shortcut keys. If your
application does not have shortcut keys assigned to the menu items,
you can send combinationsof the VK_MENU, VK_LEFT, VK_DOWN, and
VK_RETURN keys to programmatically navigate the menu.

procedure TForm1.Button1Click(Sender: TObject);
begin
//Allow button to finish painting in response to the click
  Application.ProcessMessages;
 {Alt Key Down}
  keybd_Event(VK_MENU, 0, 0, 0);
 {F Key Down - Drops the menu down}
  keybd_Event(ord('F'), 0, 0, 0);
 {F Key Up}
  keybd_Event(ord('F'), 0, KEYEVENTF_KEYUP, 0);
 {Alt Key Up}
  keybd_Event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
 {F Key Down}
  keybd_Event(ord('S'), 0, 0, 0);
 {F Key Up}
  keybd_Event(ord('S'), 0, KEYEVENTF_KEYUP, 0);
end;


7/16/98 4:31:28 PM
 

Last Modified: 01-SEP-99