Well, you still need a window of some sort to handle the messages, (im assuming your on windows here)
If you have MaxGUI id suggest hooking it up to a hidden panel with the PANEL_ACTIVE flag, and set the tray icon to use WM_MOUSEMOVE. That way you get easy access to it via EVENT_MOUSEMOVE on the panel.
Or you could make your own hidden window, win32api style ;)
heres some code...
SuperStrict
'
' tray icons
'
Const NIM_ADD:Int = 0
Const NIM_MODIFY:Int = 1
Const NIM_DELETE:Int = 2
Const NIM_SETFOCUS:Int = 3
Const NIM_SETVERSION:Int = 4
Const NIF_MESSAGE:Int = $00000001
Const NIF_ICON:Int = $00000002
Const NIF_TIP:Int = $00000004
Const NIF_STATE:Int = $00000008
Const NIF_INFO:Int = $00000010
Const NIF_GUID:Int = $00000020
Type TNotifyIconData
Field Size:Int
Field HWND:Int
Field ID:Int
Field Flags:Int
Field CallbackMessage:Int
Field Icon:Int ' HICON
Field Tip:Long ' array [0..63] of AnsiChar;
Field Tip2:Long
Field Tip3:Long
Field Tip4:Long
Field Tip5:Long
Field Tip6:Long
Field Tip7:Long
Field Tip8:Long
EndType
Extern "WIN32"
Function Shell_NotifyIcon:Int( message:Int, notifyicondata:Byte Ptr) = "Shell_NotifyIconA@8"
EndExtern
Function SetNotifyIconDataTip( nid:TNotifyIconData, s:String)
MemClear( Varptr nid.Tip, 64)
If s.Length > 0 Then
Local p:Byte Ptr = s.ToCString()
If s.Length < 64 Then
MemCopy( Varptr nid.Tip, p, s.Length)
Else
MemCopy( Varptr nid.Tip, p, 63)
EndIf
MemFree( p)
EndIf
EndFunction
'
' window messages (allso used by tray icon)
'
Const WM_MOUSEMOVE:Int = $0200
Const WM_LBUTTONDOWN:Int = $0201
Const WM_LBUTTONUP:Int = $0202
Const WM_LBUTTONDBLCLK:Int = $0203
Const WM_RBUTTONDOWN:Int = $0204
Const WM_RBUTTONUP:Int = $0205
Const WM_RBUTTONDBLCLK:Int = $0206
Const WM_MBUTTONDOWN:Int = $0207
Const WM_MBUTTONUP:Int = $0208
Const WM_MBUTTONDBLCLK:Int = $0209
'
' icon resources
'
Const IMAGE_BITMAP:Int = 0
Const IMAGE_ICON:Int = 1
Const IMAGE_CURSOR:Int = 2
Const IMAGE_ENHMETAFILE:Int = 3
Const LR_DEFAULTSIZE:Int = 64
Const LR_DEFAULTCOLOR:Int = 0
Const LR_MONOCHROME:Int = 1
Const LR_COLOR:Int = 2
Const LR_COPYRETURNORG:Int = 4
Const LR_COPYDELETEORG:Int = 8
Const LR_LOADFROMFILE:Int = 16
Const LR_LOADTRANSPARENT:Int = 32
Const LR_LOADREALSIZE:Int = 128
Const LR_LOADMAP3DCOLORS:Int = 4096
Const LR_CREATEDIBSECTION:Int = 8192
Const LR_COPYFROMRESOURCE:Int = $4000 ' 0x4000
Const LR_SHARED:Int = 32768
Extern "WIN32"
Function LoadImage_:Int( Instance:Int, Name$z, Type_:Int, DesiredX:Int, DesiredY:Int, Load:Int) = "LoadImageA@24"
EndExtern
Function LoadIcon:Int( filename:String, width:Int=16,height:Int=16, flags:Int=LR_SHARED)
Return LoadImage_( 0, filename, IMAGE_ICON, width,height, LR_LOADFROMFILE | flags)
EndFunction
'
' EXAMPLE
'
Local window:TGadget = CreateWindow( "Window", 80,80,640,480)
Local panel:TGadget = CreatePanel( 0,0, 0,0, window, PANEL_ACTIVE)
' register tray icon
Local nid:TNotifyIconData = New TNotifyIconData
nid.Size = SizeOf(TNotifyIconData)
nid.HWND = QueryGadget( panel, QUERY_HWND)
nid.ID = 0
nid.CallbackMessage = WM_MOUSEMOVE
'nid.Icon = LoadIcon( "icon.ico")
nid.Flags = NIF_MESSAGE | NIF_TIP | NIF_ICON
SetNotifyIconDataTip( nid, "Tooltip")
Shell_NotifyIcon( NIM_ADD, nid)
Repeat
WaitEvent()
Select EventID()
Case EVENT_MOUSEMOVE
If EventSource() = panel Then
Select EventX()
Case WM_MOUSEMOVE Print "mouse move"
Case WM_LBUTTONDOWN Print "left down"
Case WM_LBUTTONUP Print "left up"
Case WM_LBUTTONDBLCLK Print "left double click"
Case WM_RBUTTONDOWN Print "right down"
Case WM_RBUTTONUP Print "right up"
Case WM_RBUTTONDBLCLK Print "right doucle click"
Case WM_MBUTTONDOWN Print "middle down"
Case WM_MBUTTONUP Print "middle up"
Case WM_MBUTTONDBLCLK Print "middle double click"
Default
Print "unknown " + EventX()
EndSelect
EndIf
Case EVENT_WINDOWCLOSE
Exit
EndSelect
Forever
' unregister tray icon
Shell_NotifyIcon( NIM_DELETE, nid)
End
|