Recent

Author Topic: Show hidden MainMenu by single Alt press (Windows)  (Read 1310 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
Show hidden MainMenu by single Alt press (Windows)
« 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.

440bx

  • Hero Member
  • *****
  • Posts: 4023
Re: Show hidden MainMenu by single Alt press (Windows)
« Reply #1 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.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

AlexTP

  • Hero Member
  • *****
  • Posts: 2401
    • UVviewsoft
Re: Show hidden MainMenu by single Alt press (Windows)
« Reply #2 on: April 02, 2019, 11:25:28 am »
This was very good hint. thanks. I added workaround for CudaText. using WinAPI.

440bx

  • Hero Member
  • *****
  • Posts: 4023
Re: Show hidden MainMenu by single Alt press (Windows)
« Reply #3 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.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018