declare function shell_notifyicon lib "shell32.dll" (byval dwmessage as long, lpdata as notifyicondata) as long 'if you get an error message at the beginning of the program, 'use the declaration below: 'declare function shell_notifyicon lib "shell32.dll" alias " shell_notifyicona" (byval dwmessage as long, lpdata as notifyicondata) as long 'these public public public
three const const const
constants specify what you want to do nim_add = &h0 nim_delete = &h2 nim_modify = &h1
public const nif_icon = &h2 public const nif_message = &h1 public const nif_tip = &h4 public public public public public public public
const const const const const const const
wm_lbuttondblclk = &h203 wm_lbuttondown = &h201 wm_lbuttonup = &h202 wm_mousemove = &h200 wm_rbuttondblclk = &h206 wm_rbuttondown = &h204 wm_rbuttonup = &h205
type notifyicondata cbsize as long hwnd as long uid as long uflags as long ucallbackmessage as long hicon as long sztip as string * 64 end type public icondata as notifyicondata _______ in the form private sub form_activate() call shell_notifyicon(nim_add, icondata) 'this is an option to show icon without minimizing the form end sub private sub form_resize() 'this is the option to show icon on minimizing the form if me.windowstate = 1 then 'the user has minimized his window 'call shell_notifyicon(nim_add, icondata) ' add the form's icon to the tray me.hide ' hide the button at the taskbar
end if end sub private sub form_load() with icondata .cbsize = len(icondata) ' the length of the notifyicondata type .hicon = me.icon ' a reference to the form's icon .hwnd = me.hwnd ' hwnd of the form .sztip = "my tooltip" & chr(0) ' tooltip string delimited with a null character .ucallbackmessage = wm_mousemove ' the icon we're placing will send messages to the mousemove event .uflags = nif_icon or nif_tip or nif_message ' it will have message handling and a tooltip .uid = vbnull ' uid is not used by vb, so it's set to a null value end with end sub private sub mnuexit_click() unload me ' unload the form end ' just to be sure the program has ended end sub private sub mnushow_click() me.windowstate = vbnormal shell_notifyicon nim_delete, icondata me.show end sub private sub form_mousemove(button as integer, shift as integer, x as single, y as single) dim msg as long msg = x ' the message is passed to the x value
' you must set your form's scalemode property to pixels in order to get the correct message if msg = wm_lbuttondblclk then ' the user has double-clicked your icon call mnushow_click ' show the window elseif msg = wm_rbuttondown then ' right-click popupmenu mnupopup ' popup the menu end if end sub private sub form_unload(cancel as integer) shell_notifyicon nim_delete, icondata end sub