Lazarus

Programming => LCL => Topic started by: AlexTP on April 02, 2019, 09:46:36 am

Title: Show hidden MainMenu by single Alt press (Windows)
Post by: AlexTP on April 02, 2019, 09:46:36 am
I have the CudaText app. by option it hides MainMenu (it sets MainMenu1.Parent:= nil).
Now I want to show menu again when user presses Alt key (press+release).
And when menu item is chosen, hide menu again.
How to do it?

Lazarus 2.0, FPC 3.2, Win32.
Title: Re: Show hidden MainMenu by single Alt press (Windows)
Post by: 440bx on April 02, 2019, 10:10:22 am
I have the CudaText app. by option it hides MainMenu (it sets MainMenu1.Parent:= nil).
Now I want to show menu again when user presses Alt key (press+release).
And when menu item is chosen, hide menu again.
How to do it?

Lazarus 2.0, FPC 3.2, Win32.
I don't have a "Lazarus" solution but, using the API a call to SetMenu solves that problem.  Presuming you have/know the menu handle, SetMenu(WindowHandle, MenuHandle) adds and shows the menu and, SetMenu(WindowHandle, 0) removes the menu.   Just make sure the menu handle is available to be used.

If you need to get the menu handle and, presuming the program starts with the menu showing, a call to GetMenu(WindowHandle) will return the menu handle for you, once you have that value you can manipulate the menu to your heart's content (you can have multiple different menus for one window - i.e, context sensitive menus)

To beat that dead menu even further, as long as you know the menu name, you can use LoadMenu to load any menu in the program's resource section. 

HTH.
Title: Re: Show hidden MainMenu by single Alt press (Windows)
Post by: AlexTP on April 02, 2019, 11:25:28 am
This was very good hint. thanks. I added workaround for CudaText. using WinAPI.
Title: Re: Show hidden MainMenu by single Alt press (Windows)
Post by: 440bx on April 02, 2019, 12:47:40 pm
This was very good hint. thanks. I added workaround for CudaText. using WinAPI.
You're welcome. I'm pleased you found it useful.
TinyPortal © 2005-2018