Hi,
Did someone already look into how to add MenuItems to an Applications Dock-Menu?
Found something for Swift that I will try out (possibly this evening) but was wondering if someone already came across this and has a working solution in PureBasic.
Thanks
Adding MenuItems to an Applications Dock-Menu
Adding MenuItems to an Applications Dock-Menu
I am to provide the public with beneficial shocks.
Alfred Hitshock
Re: Adding MenuItems to an Applications Dock-Menu
The following code demonstrates how to add own menu entries to the dock menu of your application:
Code: Select all
Define SharedApp.I = CocoaMessage(0, 0, "NSApplication sharedApplication")
Define AppDelegate.I = CocoaMessage(0, SharedApp, "delegate")
Define DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
ProcedureC DockMenuCallback(Object.I, Selector.I, Sender.I)
Shared MyDockMenu.I
; ----- Return own custom menu to be integrated into your app's dock menu
ProcedureReturn MyDockMenu
EndProcedure
OpenWindow(0, 270, 100, 300, 20, "Please right click my dock icon!")
; ----- Initialize dock menu callback
class_addMethod_(DelegateClass, sel_registerName_("applicationDockMenu:"),
@DockMenuCallback(), "v@:@")
CocoaMessage(0, SharedApp, "setDelegate:", AppDelegate)
; ----- Create own custom menu
CreateMenu(0, 0)
MenuTitle("My menu")
MenuItem(1, "My menu item 1")
MenuItem(2, "My menu item 2")
MyDockMenu = CocoaMessage(0, MenuID(0), "objectAtIndex:", 0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
SelectedMenuItem = EventMenu()
Select SelectedMenuItem
Case 1, 2
MessageRequester("Info", "'My menu item " + Str(SelectedMenuItem) +
"' was selected.")
EndSelect
EndSelect
ForEver
Re: Adding MenuItems to an Applications Dock-Menu
Hello Shardik,
this is working really great.
Awesome
Thank you.
this is working really great.
Awesome
Thank you.
I am to provide the public with beneficial shocks.
Alfred Hitshock