Click to See Complete Forum and Search --> : API for minimise to systray


maron
July 29th, 2003, 04:08 AM
I wish to minimise my server.exe on startup to the systemtray. and hide the window away from the taskbar.
my server application is a command prompt type of program.

maron
July 30th, 2003, 01:24 AM
now i could create the systray icon and minimise the cmd window. using ShowWindow and Shell_NotifyIcon.
But now I don't know how to get the events (LCLICK/RCLICK on the systray icon..)
Can someone please help

Kyle Gibson
July 30th, 2003, 12:27 PM
Here ya go:

1) #define WM_TRAYNOTIFY WM_USER+1

2) Add a case WM_TRAYNOTIFY for the Window Proc for which the tray icon will be associated, like below:

long __stdcall MyWindow(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
// ... other cases
case WM_TRAYNOTIFY:
switch(lParam)
{
case WM_LBUTTONDBLCLK: // ... do code for double click
break;
case WM_RBUTTONDOWN: // ... do code for right click (down)
break;
}
break;
// ... other cases
}
return false;
}

3) Setup the icon like below:

NOTIFYICONDATA nTrayIcon;
nTrayIcon.cbSize = sizeof(NOTIFYICONDATA);
nTrayIcon.hWnd = [HWND VARIABLE GOES HERE];
nTrayIcon.uID = 0;
nTrayIcon.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE;
nTrayIcon.uCallbackMessage = WM_TRAYNOTIFY;
nTrayIcon.hIcon = hIcon;
lstrcpy(nTrayIcon.szTip, __TEXT("My Icon Toolip text!"));
Shell_NotifyIcon(NIM_ADD, &nTrayIcon);

4) Make sure you process the WM_DESTROY message for the main window, call Shell_NotifyIcon(NIM_DELETE, &nTrayIcon);


Good luck.

maron
July 30th, 2003, 08:51 PM
nothing happens when i click the icon

Fresny
July 30th, 2003, 09:34 PM
an example (http://blacksun.box.sk/aztek/winprog/format.php3?file=winprog.html#2_2)

another example (http://www.stormpages.com/bojanjurca/Downloads/CTray.zip)

ANOTHER THREAD about the same subject!!! (http://www.codeguru.com/forum/showthread.php?threadid=168433)