' How to put your application icon into the system tray area. ' Double click your icon to "re-display" the application. ' Written in Rapid-Q by William Yu $TYPECHECK ON TYPE TNOTIFYICONDATA cbSize AS DWORD hWnd AS LONG uID AS LONG uFlags AS LONG uCallbackMessage AS LONG hIcon AS LONG szTip AS STRING*64 END TYPE DECLARE SUB Shell_NotifyIcon LIB "SHELL32" ALIAS "Shell_NotifyIconA" _ (dwMessage AS LONG, NIDATA AS TNOTIFYICONDATA) CONST FALSE = 0 CONST TRUE = 1 CONST NIM_ADD = 0 CONST NIM_MODIFY = 1 CONST NIM_DELETE = 2 CONST NIM_MESSAGE = 1 CONST NIM_ICON = 2 CONST NIM_TIP = 4 CONST WM_USER = &H400 CONST WM_TRAYICON = WM_USER + 400 CONST WM_COMMAND = &H111 CONST WM_SYSCOMMAND = &H112 CONST WM_LBUTTONDOWN = &H201 CONST WM_LBUTTONDBLCLK = &H203 CONST WM_RBUTTONDOWN = &H204 CONST WM_RBUTTONDBLCLK = &H206 CONST SC_MINIMIZE = 61472 CONST SC_CLOSE = 61536 DIM Form AS QForm DIM Button AS QButton DIM NI AS TNotifyIconData DIM AlreadyTrayed AS INTEGER AlreadyTrayed = FALSE SUB FormClose IF AlreadyTrayed THEN Shell_NotifyIcon(NIM_DELETE, NI) '-- Remove our tray icon END IF Application.Terminate END SUB SUB ButtonClick IF NOT AlreadyTrayed THEN NI.cbSize = SIZEOF(NI) NI.hWnd = Form.Handle NI.uID = Application.hInstance NI.uFlags = NIM_ICON OR NIM_MESSAGE OR NIM_TIP NI.hIcon = Application.Icon NI.uCallBackMessage = WM_TRAYICON NI.szTip = "Rapid-Q Tray Example"+CHR$(0) Shell_NotifyIcon(NIM_ADD, NI) AlreadyTrayed = TRUE END IF Form.Visible = FALSE END SUB SUB FormWndProc (Handle AS INTEGER, uMsg AS DWORD, wParam AS LONG, lParam AS LONG) IF uMsg = WM_SYSCOMMAND THEN IF wParam = SC_MINIMIZE THEN '-- Minimize to system tray ButtonClick END IF ELSEIF uMsg = WM_TRAYICON THEN IF (lParam AND &HFFFF) = WM_LBUTTONDBLCLK THEN '-- Respond on double click Form.Caption = "I'm back!" Form.Visible = TRUE '-- Bring back our form Form.WindowState = 0 END IF END IF END SUB Button.Parent = Form Button.Caption = "Tray me" Button.OnClick = ButtonClick Form.Caption = "Tray Example" Form.Center Form.OnClose = FormClose Form.WndProc = FormWndProc Form.ShowModal