Click to See Complete Forum and Search --> : Application Try Icon events


sader
July 6th, 2007, 07:02 PM
I wont minimize my appliciotion to try icons bar (near windows clock) when I close it (when I click nice red button [ x ] :)) but the point is that I wont just minimize application not to exit from it.

Also I have another problem I am trying minimize application to try icons bar when it starts, but I cant't make it to work. The Icon is shown but I still can see **** application tab[Application...] at the bottom of the screen.

I am warking with borland and I have TrayIcon object on main form but it doesn't help much

Ali Imran
July 6th, 2007, 09:00 PM
First things first :)

First you need to minimize application to tray, that actually means you must not show up your main program window when created, remove WS_VISIBLE style, or if you are using ShowWindow function anywhere, simply remove it, so that main window is not visible when applciation starts.


Then we come to tray things :

1. create some custom message

DWORD WM_MYCUSTOM = WM_USER+100;

2. then add icon to tray
NOTIFYICONDATA __tnd;
__tnd.uID = WM_MYCUSTOM;
__tnd.uCallbackMessage = WM_MYCUSTOM;
__tnd.hIcon = theHICON; //handle to your icon HICON
__tnd.hWnd = hwnd; //main window handle, that will recieve notification
strcpy(__tnd.szTip, "This is my tooltip text");

Shell_NotifyIcon(NIM_ADD, &__tnd);


3. Now the main thing, capture mouse events when tray icon is clicked.
if(message == WM_MYCUSTOM) {
//ya it is notification from my tray icon
if(lParam == WM_LBUTTONDOWN) {
//oh, it was left moue button down,
//check for WM_RBUTTONDOWN etc
}
}


4. Now when it is clicked, it is your job to decide either to hide or show the window, and respectively capture minimize message too.

One last thing to take care of: Remember to remove icon when you exit the eapplciation:

Shell_NotifyIcon(NIM_DELETE, &__tnd);


It hope it helps some.

regards