Page 1 of 1

Multitasking Menu and Popup Menu, plus auto menu timeout.

Posted: Sun Nov 27, 2011 10:26 am
by Rescator
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?

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

Re: Multitasking Menu and Popup Menu, plus auto menu timeout

Posted: Sun Nov 27, 2011 11:01 am
by Rescator
*sigh* seems there is a conflict somewhere. keyboard navigation (pressing ALT then arrow down for example) does not open the menu,
not sure why keyboard arrows are ignored if the menu is non-modal...

Re: Multitasking Menu and Popup Menu, plus auto menu timeout

Posted: Sun Nov 27, 2011 11:08 am
by c4s
This looks helpful. Especially if we e.g. have a WindowTimer() enabled.

Interestingly I've noticed that the shadow of the main menu goes away if the mouse is in the submenu and multi-tasking is enabled.

Re: Multitasking Menu and Popup Menu, plus auto menu timeout

Posted: Tue Nov 29, 2011 11:27 am
by void
This fails for me (PB 4.60 x64, windows 7)...

It looks like SetMenuInfo_ fails for some reason, but I'm unable to discern why.