|
Post by johnnyd on Jul 10, 2020 11:23:28 GMT -5
Hi, Back again,
I know there is a method to disable menu items via api (I've used it), but is there a way to disable the main menu control itself? Have Googled it but only found references to menu items.
Cheers,
John.
|
|
|
Post by Chris Iverson on Jul 10, 2020 13:41:29 GMT -5
I think you may be able to simulate it by disabling the top-level menus on the window(basically, get the window handle, get the menu handle from the window handle, and then disable every menu item on the window menu, which should disable all the top-level menus), but I don't think you can just disable the menu bar directly.
'Form created with the help of Freeform 3 v07-15-08 'Generated on Jul 10, 2020 at 13:26:31
[setup.main.Window]
'-----Begin code for #main
nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin menu code
menu #main, "Menu1",_ "SubItem1", [item]
menu #main, "Menu2",_ "SubItem2", [item]
'-----End menu code
open "untitled" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]"
[main.inputLoop] 'wait here for input event hMenu = GetMenu(hwnd(#main))
items = GetMenuItemCount(hMenu)
for x = 0 to (items - 1) a = EnableMenuItem(hMenu, x, _MF_DISABLED) next x
a = DrawMenuBar(hwnd(#main)) wait
[item] 'Perform action for menu Menu1, item SubItem1
'Insert your own code here
wait
[quit.main] 'End the program close #main end
Function GetMenu(hWnd) CallDLL #user32, "GetMenu",_ hWnd as ulong,_ GetMenu as ulong End Function
Function GetMenuItemCount(hMenu) CallDLL #user32, "GetMenuItemCount",_ hMenu as ulong,_ GetMenuItemCount as long End Function
Function EnableMenuItem(hMenu, itemPos, status) uEnable = status or _MF_BYPOSITION
CallDLL #user32, "EnableMenuItem",_ hMenu as ulong,_ itemPos as long,_ uEnable as long,_ EnableMenuItem as long End Function
Function DrawMenuBar(hWnd) CallDLL #user32, "DrawMenuBar",_ hWnd as ulong,_ DrawMenuBar as long End Function
|
|
|
Post by Rod on Jul 10, 2020 13:50:32 GMT -5
|
|
|
Post by johnnyd on Jul 11, 2020 9:30:08 GMT -5
Hi Chris,
This is exactly what I wanted, thank you.
As long as the main Menu can't be accessed during parts of the operation, magic!
John.
|
|
|
Post by Brandon Parker on Jul 12, 2020 15:37:50 GMT -5
John, Out of curiosity, are you trying to prevent the user from popping up a menu at specific times to prevent them from freezing the process while the menu is active? I only ask because, if this is the case, you will want to close the default context popup menu any time it is accessed; this context menu can be observed by either right-clicking on the window title bar or clicking on a window's icon at the top left. To resolve this you would need to trap the _WM_CONTEXTMENU message as well as the _WM_INITMENUPOPUP message and end the menu immediately in a function. Should you need this functionality, just let me know and I can post the code. I would do it now, but my 8-month old daughter is ... NOT HAPPY ... {:0) Brandon Parker
|
|
|
Post by johnnyd on Jul 17, 2020 3:54:29 GMT -5
Hi Brandon,
The application is a multiple timer and the menu accesses setup parameters, so I don't want people messing with these while it's running.
Ive got it working as I want it now but thanks for your offer.
It's been many years since my daughter was that young and I sympathise!
John.
|
|