Multitasking Menu and Popup Menu, plus auto menu timeout.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Multitasking Menu and Popup Menu, plus auto menu timeout.

Post 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
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

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

Post 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...
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post 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.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
void
Enthusiast
Enthusiast
Posts: 116
Joined: Sat Aug 27, 2011 9:50 pm
Location: Washington, USA

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

Post 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.
Post Reply