Multitasking Menu and Popup Menu, plus auto menu timeout.
Posted: Sun Nov 27, 2011 10:26 am
PureBasic menus are modal, however many may not know this but Windows (seemingly as far back as Windows 2000 at least) actually support non-modal menus.
The following example is the OpenSubMenu() example from the manual.
Run this code, "Test" should be printed once per second.
Now click on the menu, and move around in it. "Test" no longer prints.
Now un-comment ;MenuSetMultitasking(0)
then do the same as you just did.
"Test" continues to print even while you are in the menu, the main loop is no longer "stuck" waiting for the menu to close.
Additionally if you move the mouse outside the menu, the menu will autoclose (as if the user pressed ESC), the OS timeout is about be the same as Doubleclicktime()*10
I'd really love to see this feature added to PureBasic, maybe a flag could be added to the CreateMenu() and the other createmenu commands?
The following example is the OpenSubMenu() example from the manual.
Run this code, "Test" should be printed once per second.
Now click on the menu, and move around in it. "Test" no longer prints.
Now un-comment ;MenuSetMultitasking(0)
then do the same as you just did.
"Test" continues to print even while you are in the menu, the main loop is no longer "stuck" waiting for the menu to close.
Additionally if you move the mouse outside the menu, the menu will autoclose (as if the user pressed ESC), the OS timeout is about be the same as Doubleclicktime()*10
I'd really love to see this feature added to PureBasic, maybe a flag could be added to the CreateMenu() and the other createmenu commands?
Code: Select all
Structure MENUINFO
cbSize.l
fMask.l
dwStyle.l
cyMax.l
hbrBack.i
dwContextHelpID.l
dwMenuData.i
EndStructure
#MIM_STYLE=$00000010
#MIM_APPLYTOSUBMENUS=$80000000
#MNS_AUTODISMISS=$10000000
#MNS_MODELESS=$40000000
Procedure.i MenuSetMultitasking(menu.i)
Protected result.i,mi.MENUINFO
mi\cbSize=SizeOf(mi)
mi\fMask=#MIM_STYLE|#MIM_APPLYTOSUBMENUS
mi\dwStyle=#MNS_AUTODISMISS|#MNS_MODELESS
result=SetMenuInfo_(MenuID(menu),mi)
Procedurereturn result
EndProcedure
If OpenWindow(0, 200, 200, 220, 100, "SubMenu Example")
If CreateMenu(0, WindowID(0))
MenuTitle("Project")
MenuItem(1, "Open")
MenuItem(2, "Close")
MenuBar()
OpenSubMenu("Recent files") ; begin sub-menu
MenuItem( 3, "C:\Autoexec.bat")
MenuItem( 4, "D:\Test.txt")
CloseSubMenu() ; end sub-menu
;MenuSetMultitasking(0) ;un-comment this for multitasking menus.
EndIf
Define ms.l,oldms.l
ms=ElapsedMilliseconds()
oldms=ms
Repeat
ms=ElapsedMilliseconds()
If (ms-oldms)>=1000
Debug "Test"
oldms=ms
EndIf
Delay(1)
Until WindowEvent()=#PB_Event_CloseWindow
EndIf