W
(D)Evil schrieb:
Dafür müsste hier jemand mal nen ganz sauber und schön erklärten Code reinsetzen...
LRESULT CALLBACK AppWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
static CTrayIcon* TrayIcon;
switch(uiMsg)
{
case WM_CREATE:
// Create the tray icon
TrayIcon = new CTrayIcon(((LPCREATESTRUCT)lParam)->hInstance,
hwnd,
ID_ICO_MYICON, // Die in der Resource definierte Konstante für das Icon
TEXT("My Tool Tip Text")
);
// Set a new popup menu
TrayIcon->SetPopupMenu(ID_MENU, 0);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam)) // Switch between control IDs
{
// The menu item "Show" was clicked
case ID_MI_SHOW:
SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
break;
// The menu item "Show Balloon" was clicked
case ID_MI_SHOWBALLOON:
TrayIcon->ShowBalloon(TEXT("BalloonTitle"), TEXT("BalloonInfo"), 2000, NIIF_USER);
break;
// The menu item "Exit" was clicked
case ID_MI_EXIT:
SendMessage(hwnd, WM_CLOSE, 0, 0);
break;
}
return 0;
case WM_SYSCOMMAND:
if(wParam == SC_MINIMIZE) // The main window shall be minimized
{
TrayIcon->Show(); // Show the tray icon
ShowWindow(hwnd, SW_HIDE); // Hide the main window
return 0;
}
if(wParam == SC_RESTORE) // The main window shall be restored
{
TrayIcon->Hide(); // Hide the tray icon
SetForegroundWindow(hwnd); // Show main window and put it on the top of the Z order
}
break;
// A mouse action was performed over the tray icon
case WM_TRAYMESSAGE:
if(lParam == WM_LBUTTONUP) // The tray icon was leftclicked
SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
return 0;
case WM_DESTROY:
delete TrayIcon;
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}