$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)
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
ButtonClick
END IF
ELSEIF uMsg = WM_TRAYICON THEN
IF (lParam AND &HFFFF) = WM_LBUTTONDBLCLK THEN
Form.CAPTION = "I'm back!"
Form.Visible = TRUE
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
|