// Main Windowproc
function DlgProc(dlgHandle: HWND; Msg: UINT; wParam : Integer; lParam: Integer) : BOOL;
stdcall;
begin
case Msg
of
WM_INITDIALOG:
begin
// Wähle das erste Option Control
SendDlgItemMessage(dlgHandle, 101, BM_SETCHECK, BST_CHECKED, 0);
// Setze das Menu Handle
hMenu := GetSubMenu(LoadMenu(g_hInst, '
POPUPMENU'), 0);
// Addiere das Tray Icon
ti.cbSize := SIZEOF(TNotifyIconData);
ti.Wnd := dlgHandle;
ti.uID := g_hInst;
ti.uFlags := NIF_ICON
or NIF_MESSAGE
or NIF_TIP;
ti.uCallbackMessage := WM_TRAYICON;
ti.hIcon := LoadIcon(g_hInst, '
FACE1');
ti.szTip := '
Water Gadgets';
Shell_NotifyIcon(NIM_ADD, @ti);
DestroyIcon(ti.hIcon);
Result := True;
exit;
end;
WM_TRAYICON:
case lParam
of
// Linker Button gedrückt
WM_LBUTTONDOWN:
if IsWindowVisible(dlgHandle) = False
then
ShowWindow( dlgHandle, SW_SHOW);
// Rechter Button gedrückt
WM_RBUTTONDOWN:
begin
if IsWindowVisible(dlgHandle) = False
then
SetForegroundWindow(dlgHandle);
GetCursorPos(TrayMenuP);
TrackPopupMenu(hMenu, 0, TrayMenuP.x,
TrayMenuP.y, 0, dlgHandle,
nil);
Postmessage(dlgHandle, WM_NULL, 0, 0);
end;
end;
WM_COMMAND:
begin
case LoWord(WParam)
of
101 , 102, 103, 104, 105:
begin
// Ändere das TrayIcon
ti.hIcon := LoadIcon(g_hInst, MAKEINTRESOURCE('
FACE' + IntToStr(LOWORD(wParam) - 100)));
Shell_NotifyIcon(NIM_MODIFY, @ti);
DestroyIcon(ti.hIcon);
end;
IDOK:
// AboutBox aus der Resource Anzeigen - siehe Tray.rc
DialogBox(g_hInst, MAKEINTRESOURCE(101), HWND_DESKTOP, @AboutProc);
IDCANCEL:
begin
if MessageBox(dlgHandle,
'
Möchten Sie das Programm wirklich beenden?',
'
Water Gadget',
MB_ICONEXCLAMATION
or MB_OKCANCEL) = IDOK
then
EndDialog(dlgHandle, 0);
end;
end;
end;
WM_SYSCOMMAND:
case wParam
and $FFF0
of
SC_MINIMIZE:
begin
ShowWindow(dlgHandle, SW_HIDE);
Result := True;
Exit;
end;
SC_CLOSE:
begin
ShowWindow(dlgHandle, SW_HIDE);
Result := True;
Exit;
end;
end;
WM_DESTROY:
begin
Shell_NotifyIcon(NIM_DELETE, @ti);
PostQuitMessage(0);
end;
end;
Result := False;
end;