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 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 NI AS TNotifyIconData
DIM AlreadyTrayed AS INTEGER
AlreadyTrayed = 0
DECLARE SUB FormWndProc(Handle AS INTEGER, uMsg AS DWORD, wParam AS LONG, lParam AS LONG)
DECLARE SUB Form_OnPaint
DECLARE SUB TermApp
CREATE Form AS QFORM
OnPaint = Form_OnPaint
WndProc = FormWndProc
CAPTION = "Form"
END CREATE
CREATE ParentForm AS QFORM
OnClose = TermApp
CAPTION = "Parent"
Center
END CREATE
form.SHOWMODAL
SUB Form_OnPaint
IF ParentForm.Visible = 0 THEN ParentForm.Show
Form.Visible = 0
END SUB
SUB TermApp
Shell_NotifyIcon(NIM_DELETE, NI)
Application.Terminate
END SUB
SUB FormClose
IF AlreadyTrayed THEN
Shell_NotifyIcon(NIM_DELETE, NI)
END IF
Application.Terminate
END SUB
SUB FormWndProc (Handle AS INTEGER, uMsg AS DWORD, wParam AS LONG, lParam AS LONG)
IF ParentForm.WindowState = 1 THEN
ParentForm.Visible = 0
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 = 1
END IF
END IF
IF uMsg = WM_TRAYICON THEN
IF (lParam AND &HFFFF) = WM_LBUTTONDBLCLK THEN
Shell_NotifyIcon(NIM_DELETE, NI)
ParentForm.WindowState = 0
ParentForm.Visible = 1
END IF
END IF
END SUB
|