Page 1 of 1
How do I check if a menu item has been clicked in another pr
Posted: Wed Aug 18, 2004 3:15 am
by coderchris
Ok, I have made a dll with ALL pb menu functions. I open up a window and draw some menu items and thats works well. However, I have this function :
Code: Select all
ProcedureDLL menu_check()
WaitWindowEvent()
ProcedureReturn Str(EventMenuID())
EndProcedure
which is supposed to return if/which of the menu items are being pressed
but it wont work. Is there a way I can check if a menu item is bein pressed on this menu?
Posted: Thu Aug 19, 2004 4:40 pm
by Sparkie
Posted: Thu Aug 19, 2004 10:28 pm
by fweil
coderchris,
First you should return EventMenuID() and not Str(EventMenuID()) (which is a string address in fact).
But then you also should not use WaitWindowEvent() in a DLL procedure I guess, except if you are sure not to need it somewhere else in your program.
Here is an example using such a DLL you suggest (to be compared to the menu.pb source code available in the PureBasic's user's manual - Press F1 and select Menu library functions) :
Code: Select all
ProcedureDLL menu_check()
WaitWindowEvent()
ProcedureReturn EventMenuID()
EndProcedure
If OpenWindow(0, 100, 150, 195, 260, #PB_Window_SystemMenu, "PureBasic - Menu")
If CreateMenu(0, WindowID())
MenuTitle("File")
MenuItem( 1, "&Load...")
MenuItem( 2, "Save")
MenuItem( 3, "Save As...")
MenuBar()
OpenSubMenu("Recents")
MenuItem( 5, "C:\Autoexec.bat")
MenuItem( 6, "D:\Test.txt")
OpenSubMenu("Even more !")
MenuItem( 12, "Test")
CloseSubMenu()
MenuItem( 13, "C:\Ok.bat")
CloseSubMenu()
MenuBar()
MenuItem( 7, "&Quit")
MenuTitle("Edition")
MenuItem( 8, "Cut")
MenuItem( 9, "Copy")
MenuItem(10, "Paste")
MenuTitle("?")
MenuItem(11, "About")
EndIf
DisableMenuItem(3, 1)
DisableMenuItem(13, 1)
Repeat
menu_check = menu_check()
Until menu_check = 7
EndIf
End
Rgrds