Using this code I wrote in one of my apps and figured I'd share it...not really "source code" worthy as it is just a simple function but figured it might help someone.
Basically this allows you to "one-line" many of the tray icon functions using the same syntax...
Examples:
Initially add icon: TrayIcon CB.HNDL, %NIM_ADD, %resStartingIconID, "This is my programs Tip Text", %WMU_TRAYCALLBACK
Change icon: TrayIcon CB.HNDL, %NIM_MODIFY, %resAlertIconID, "", 0
Change Tip Text: TrayIcon CB.HNDL, %NIM_MODIFY, 0, "some new tip text", 0
Remove tray icon: TrayIcon CB.HNDL, %NIM_DELETE, 0, "", 0
Basically this allows you to "one-line" many of the tray icon functions using the same syntax...
Examples:
Initially add icon: TrayIcon CB.HNDL, %NIM_ADD, %resStartingIconID, "This is my programs Tip Text", %WMU_TRAYCALLBACK
Change icon: TrayIcon CB.HNDL, %NIM_MODIFY, %resAlertIconID, "", 0
Change Tip Text: TrayIcon CB.HNDL, %NIM_MODIFY, 0, "some new tip text", 0
Remove tray icon: TrayIcon CB.HNDL, %NIM_DELETE, 0, "", 0
Code:
FUNCTION TrayIcon( BYVAL hDlg AS DWORD, lngCommand AS LONG, lngIconID AS LONG, strTipText AS STRING, lngCallbackMessage AS LONG ) AS LONG LOCAL udtNotifyIconData AS NOTIFYICONDATA udtNotifyIconData.cbSize = SIZEOF( udtNotifyIconData ) udtNotifyIconData.hWnd = hDlg udtNotifyIconData.uID = GETWINDOWLONG( hDlg, %GWL_HINSTANCE ) ' Delete the tray icon? IF lngCommand = %NIM_DELETE THEN FUNCTION = SHELL_NOTIFYICON( %NIM_DELETE, udtNotifyIconData ) EXIT FUNCTION END IF ' Was an icon specified? IF lngIconID <> 0 THEN udtNotifyIconData.uFlags = udtNotifyIconData.uFlags OR %NIF_ICON udtNotifyIconData.hIcon = LOADICON( udtNotifyIconData.uID, "#" + FORMAT$( lngIconID )) END IF ' Was a callback message set? IF lngCallbackMessage <> 0 THEN udtNotifyIconData.uFlags = udtNotifyIconData.uFlags OR %NIF_MESSAGE udtNotifyIconData.uCallbackMessage = lngCallbackMessage END IF ' Was a tip set? IF strTipText <> "" THEN udtNotifyIconData.uFlags = udtNotifyIconData.uFlags OR %NIF_TIP udtNotifyIconData.szTip = strTipText END IF ' Perform the action FUNCTION = SHELL_NOTIFYICON( lngCommand, udtNotifyIconData ) ' clean up icon handle if an icon was specified IF ( udtNotifyIconData.uFlags AND %NIF_ICON ) = %NIF_ICON THEN DESTROYICON udtNotifyIconData.hIcon END IF END FUNCTION