Page 1 of 1
SetApplicationDockTileMenu [solved]
Posted: Mon May 19, 2008 1:24 pm
by lexvictory
ive managed to use SetApplicationDockTileMenu (carbon) to add items to the dock tile, but i cant seem to find a way to receive the menu events..
anyone know how?
Posted: Mon May 19, 2008 2:59 pm
by Progi1984
As quoted in the
Carbon Documentation
Before the menu is displayed, it receives the Carbon events kEventMenuPopulate, kEventMenuOpening, and kEventMenuEnableItems, so any event handlers for these events can update the menu appropriately. You can receive notifications of and handle selections from the menu using kEventCommandProcess Carbon event handlers installed in the application event target.
Source :
http://developer.apple.com/documentatio ... ckTileMenu
Posted: Tue May 20, 2008 7:54 am
by lexvictory
i saw that, but i need to know how to receive it in PB; windowevent doesnt generate anything. not even a menu event
Posted: Tue May 20, 2008 11:56 am
by lexvictory
ok, managed to dig around (used finder to search for things inside files)
and so ive finally got it working!
may be a bit rough around the edges, but here goes
Code: Select all
#noErr = 0
#kEventClassCommand = 'cmds'
#kEventCommandProcess = 1
#eventNotHandledErr = -9874;return when not our event
#kEventParamDirectObject = '----'
#typeHICommand = 'hcmd'
Structure EventTypeSpec
eventClass.l
eventKind.l
EndStructure
Structure menu
*menuRef
menuItemIndex.w
EndStructure
Structure HICommand
attributes.l
commandID.l
*menu
EndStructure
ProcedureDLL EventHandler(*nextHandler, theEvent, *userData)
;MessageRequester("Hello", "I got me a message!!!")
If geteventkind_(theEvent) = #kEventCommandProcess
GetEventParameter_(theEvent, #kEventParamDirectObject, #typeHICommand, #Null, SizeOf(HICommand), @size.l, @hicommand.HICommand)
Select hicommand\commandID
Case 1
Debug "menu item 1"
Default
Debug "menu item "+Str(hicommand\commandID)
EndSelect
EndIf
If *nexthandler
ProcedureReturn CallNextEventHandler_(*nextHandler, theEvent)
Else
ProcedureReturn #eventNotHandledErr
EndIf
EndProcedure
If OpenWindow(0, 100, 100, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
CreatePopupMenu(0)
MenuItem(1, "test")
MenuItem(2, "test2")
MenuItem(50, "test 50")
setapplicationdocktilemenu_(MenuID(0))
functionupp = NewEventHandlerUPP_(@eventhandler())
eventTypes.EventTypeSpec\eventClass = #kEventClassCommand
eventtypes\eventKind = #kEventCommandProcess
InstallEventHandler_(GetApplicationEventTarget_(), functionupp, 1, @eventtypes, 0, @handlerref.l)
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
ElseIf eventid = #PB_Event_Menu
Debug "menu"
Select EventMenu()
Case #PB_Menu_Quit
Debug "got told to quit by dock or app menu"
Default
Debug EventMenu()
EndSelect
EndIf
Until Quit = 1
EndIf
pbl file:
Code: Select all
;
-framework Carbon
GetApplicationDockTileMenu 0
SetApplicationDockTileMenu 1
OverlayApplicationDockTileImage 1
SetApplicationDockTileImage 1
RestoreApplicationDockTileImage 0
;InstallEventHandler 6
GetApplicationEventTarget 0
CallNextEventHandler 2
GetEventParameter 7
GetEventKind 1