Starcraft
January 17th, 2000, 12:04 PM
How do i put my program in the system tray?
|
Click to See Complete Forum and Search --> : SHOW IN SYSTEM TRAY Starcraft January 17th, 2000, 12:04 PM How do i put my program in the system tray? AndyK January 17th, 2000, 12:43 PM OK follow this: You need to make: 1) picturebox (picture1) 2) Place a image into it (size of image should be approximately size of an icon) 3) Place this code into module Declare Function Shell_NotifyIconA Lib "SHELL32" (byval dwMessage as Long, lpData as NOTIFYICONDATA) as Long Type NOTIFYICONDATA cbze as Long hwnd as Long exid as Long flags as Long backmessage as Long icon as Long tip as string * 64 End Type Global Const IcD_ADD = &H0& Global Const IcD_MODIFY = &H1 Global Const IcD_DELETE = &H2 Global Const IcD_BACKMESSAGE = &H1 Global Const IcD_ICON = &H2 Global Const IcD_TIP = &H4 Global Const WM_MOUSEMOVE = &H200 Global IcD as NOTIFYICONDATA 4) Place this code into form private Sub Form_Load() IcD.cbze = len(IcD) IcD.hwnd = Picture1.hwnd IcD.exid = 0 IcD.exid = IcD.exid + 1 IcD.flags = IcD_BACKMESSAGE Or IcD_ICON Or IcD_TIP IcD.icon = Picture1.Picture IcD.tip = "tooltip for picture1 (tray icon)" + Chr$(0) IcD.backmessage = WM_MOUSEMOVE lResult = Shell_NotifyIconA(IcDM_ADD, IcD) End Sub private Sub Form_Unload(Cancel as Integer) Shell_NotifyIconA IcD_DELETE, IcD 'removes the icon from the tray End Sub private Sub Picture1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single) Dim tray as Long tray = (X And &HFF) * &H100 Select Case tray Case 0 'mouse moves Case &HF00 'left mouse button down MsgBox "left mouse button down" Case &H1E00 'left mouse button up Case &H2D00 'left mouse button double click Case &H3C00 'right mouse button down MsgBox "right mouse button down" Case &H4B00 'right mouse button up Case &H5A00 'right mouse button double click End Select End Sub Ok on Form_Load image in picture1 goes into systemtray, on Form_Unload it gets removed, on Picture1_MouseMove you specify what to do on mouse clicks, like popup menu or unload form, etc. Johnny101 January 17th, 2000, 03:41 PM I have always wondered about doing that, but never got around to asking. This is excellent! Two little things though... The lResult variable isn't defined, and in the line "lResult = Shell_NotifyIconA(IcDM_ADD, IcD)" the "IcDM_ADD" is wrong, it should be "IcD_ADD" as it is declared in the global section above. These aren't major, and some people may never notice them, but i always have Option Explicit on and so i happened to catch it. Thank you thank you thank you!! John John Pirkey MCSD www.ShallowWaterSystems.com Goat January 17th, 2000, 03:58 PM This is a great technique. One thing though : How do you add the "pop" up menu when you right-click on the icon for example? Johnny101 January 17th, 2000, 04:33 PM This was my first questions as well. It turns out that, it is as easy as doing it regularly. In the series of case statements to test for the action of the mouse above, for the test of the right mouse click paste this code: PopupMenu mnuPopupMenu where mnuPopupMenu is the name of root menu item you want to show up on when the user right clicks the icon in the system tray. mnuPopupMenu would then be created on the form with the picturebox. if you would rather use a menu list from another form, just prefix the menu name with the name of the form (eg. mdiMain.mnuPopupMenu). Hope this helps, John John Pirkey MCSD www.ShallowWaterSystems.com codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |