PureBasic also allows handles but it seems not every command/function supports them.
Code: Select all
; example 1 - INDEX method
Enumeration
#win=0
#sg=1
#menu_bar
#menu_quit
EndEnumeration
If OpenWindow(#win,176,193,228,88, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "index method")
If CreateMenu(#menu_bar, WindowID())
MenuTitle("File")
MenuItem(#menu_quit, "Quit")
EndIf
EndIf
AddKeyboardShortcut(#win,#PB_SHORTCUT_Q,#menu_quit)
quit.b=#FALSE
Repeat
ev=WaitWindowEvent()
If ev=#PB_EventCloseWindow : quit=#TRUE : EndIf
If ev=#PB_EventMenu
If EventMenuID()=#menu_quit : quit=#TRUE : EndIf
EndIf
Until quit=#TRUE
End
But here I cannot use AddKeyboardShortcut()
It only accepts INDEX values:
Code: Select all
; example 2 - HANDLE method
win=OpenWindow(#PB_ANY,176,193,228,88, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "handle method")
CreateMenu(#PB_ANY, WindowID(win))
MenuTitle("File")
MenuItem(menu_quit, "Quit")
;;; AddKeyboardShortcut(WindowID(win),#PB_SHORTCUT_Q,menu_quit)
quit.b=#FALSE
Repeat
ev=WaitWindowEvent()
If ev=#PB_EventCloseWindow : quit=#TRUE : EndIf
If ev=#PB_EventMenu
If EventMenuID()=menu_quit : quit=#TRUE : EndIf
EndIf
Until quit=#TRUE
End
In an ideal situation I would prefer to drop functions like WindowID() and have the OpenWindow() return the id directly so as to make things a little more open. There are probably good reasons why Fred needs to do this though.
To me this is how the handle method *should* work.
Code: Select all
; example 3 - ideal method
win=OpenWindow(176,193,228,88, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "new method")
CreateMenu(win)
MenuTitle("File")
menu_quit=MenuItem("Quit")
AddKeyboardShortcut(win,#PB_SHORTCUT_Q,menu_quit)
quit.b=#FALSE
Repeat
ev=WaitWindowEvent()
If ev=#PB_EventCloseWindow : quit=#TRUE : EndIf
If ev=#PB_EventMenu
If EventMenuID()=menu_quit : quit=#TRUE : EndIf
EndIf
Until quit=#TRUE
End
What say you?