Mega Code Archive

 
Categories / Delphi / Examples
 

Programmatically simulate click on mainmenu

Title: programmatically simulate click on mainmenu Question: I recently came accross this problem and just noticed that is not in Delphi 3000, the problem is simple how do I "click" (or open) on a mainmenu programmatically? the solution, you would think it would be something like mainmenu.dropdown or something, but it doesn't actually provide methods for that, so you have to workaround that... Answer: one way (I suppose there are others) is to send keyboard events to the menu, you could also send mouse events, but that would be more complicated, as you would need to know the position of the menu and size, etc... anyhow... to drop down a mainmenu subitems you simply send keyboard events like this, in this case supposing that the accelerator key is "F", you would simply do: keybd_event( VK_MENU, Mapvirtualkey( VK_MENU, 0 ), 0, 0 ); keybd_event( Ord('F'), MapVirtualKey( Ord('F'), 0), 0, 0 ); keybd_event( Ord('F'), MapVirtualKey( Ord('F'), 0), KEYEVENTF_KEYUP, 0 ); keybd_event( VK_MENU, Mapvirtualkey( VK_MENU, 0 ), KEYEVENTF_KEYUP, 0 ); that's it keep up coding EberSys