![]() |
|
#1
|
|||
|
|||
How to minimize a application to the system tray?im wondering could anyone tell me how to minimize my app to the system tray im using borland c++ builder if you can can you also explain how to when a right click is pressed a menu comes up from the icon in the system tray.
|
|||
|
#2
|
|||
|
|||
|
OK, this is a very good question and I will try to give a full answer, as I have done this a couple of times with my own applications.
I don't know about Borland C++ Builder, but my explanation will work in Dev-C++ at least and comes pretty much directly from MSDN so should be univeresal C/C++ code. Ok, first of all you need to know when the user wants you to minimize to the tray. This is usually done by a menu item or button or whatever. I assume if you are at this stage you know how to do this, but if not reply and I'll give a general overview of that. So, pretend at the point in your program we are concerned with, you know that the user wants you to minimize to the tray. The following psuedocode would presumably be in an event handler, or a function called from one. Code:
Now for some real code. Step 1. Set up necessary structures. CPP / C++ / C Code:
OK, got our struct all set up. Now to actually call the function to add our icon to the tray. Did I say "function"? As in, singular? Yup, there is only ONE function to interface with the system tray. it takes two parameters: A flag that tells it what to do, and a pointer to a NOTIFYICONDATA struct. CPP / C++ / C Code:
Step 2. There are two ways to do this. You can go the easy, simple, and proven route: CPP / C++ / C Code:
CPP / C++ / C Code:
But we're not done. How do you know stuff about the icon, such as when it is clicked? That's where uCallbackMessage comes in. Here's a snippet from hwnd's window procedure: CPP / C++ / C Code:
One more thing: Like all things Microsoft, Explorer and therefore the system tray crash once every so often. Then the tray icons disappear. This is rather annoying. to replace your icon in the tray when Explorer restarts, do CPP / C++ / C Code:
Sources: MSDN page on NOTIFYICONDATA: http://msdn.microsoft.com/library/de...fyicondata.asp MSDN page on DrawAnimatedRects: http://msdn.microsoft.com/library/de...tdraw_6qnn.asp "Secrets of the System Tray" (told me the classname to use in FindWindow and about TaskbarCreated): http://www.cs.kent.edu/~kschaffe/sdn...s/systray.html MSDN page on CreatePopupMenu: http://msdn.microsoft.com/library/de...epopupmenu.asp MSDN page on AppendMenu: http://msdn.microsoft.com/library/de...epopupmenu.asp MSDN page on GetMessagePos: http://msdn.microsoft.com/library/de...messagepos.asp MSDN page on TrackPopupMenu: http://msdn.microsoft.com/library/de...epopupmenu.asp |
|
#3
|
|||
|
|||
|
it almost compiles but i get 4 errors:
[C++ Error] Unit1.cpp(271): E2451 Undefined symbol 'nid' [C++ Error] Unit1.cpp(273): E2451 Undefined symbol 'hwnd' [C++ Error] Unit1.cpp(27 [C++ Error] Unit1.cpp(281): E2451 Undefined symbol 'IDI_ICON' how and were should i define these. |
|
#4
|
|||
|
|||
|
nid:
Define this locally in Step 1: CPP / C++ / C Code:
hwnd: Presumable Step 1 is encapsulated in a function. That function needs to be passed a parameter called hwnd, of type HWND. This will identify your app's window. This will be easy if it is called from the window procedure. MSG_MINTRAYICON: CPP / C++ / C Code:
IDI_ICON: CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
|
i still get 3 probs.
[C++ Error] Unit1.cpp(271): E2451 Undefined symbol 'nid' [C++ Error] Unit1.cpp(273): E2451 Undefined symbol 'hwnd' [C++ Error] Unit1.cpp(287): E2238 Multiple declaration for 'nid' |
|
#6
|
|||
|
|||
|
i posted my code in chunks. post some complete functions, and we can see what is wrong. if your code is not too long, go ahead and post all of it.
|
|
#7
|
|||
|
|||
|
here is all of the problems with the part of code that there in
[C++ Error] Unit1.cpp(271): E2451 Undefined symbol 'nid' CPP / C++ / C Code:
[C++ Error] Unit1.cpp(273): E2451 Undefined symbol 'hwnd' CPP / C++ / C Code:
[C++ Error] Unit1.cpp(314): E2451 Undefined symbol 'msg' CPP / C++ / C Code:
[C++ Error] Unit1.cpp(321): E2451 Undefined symbol 'Wparam' CPP / C++ / C Code:
[C++ Error] Unit1.cpp(327): E2451 Undefined symbol 'ID_MINTRAYICON' CPP / C++ / C Code:
[C++ Error] Unit1.cpp(33 CPP / C++ / C Code:
[C++ Error] Unit1.cpp(339): E2451 Undefined symbol 'IDM_TRAYHELP' CPP / C++ / C Code:
[C++ Error] Unit1.cpp(340): E2451 Undefined symbol 'IDM_TRAYABOUT' CPP / C++ / C Code:
[C++ Error] Unit1.cpp(345): E2268 Call to undefined function 'GET_X_LPARAM' CPP / C++ / C Code:
[C++ Error] Unit1.cpp(345): E2268 Call to undefined function 'GET_Y_LPARAM' CPP / C++ / C Code:
[C++ Warning] Unit1.cpp(354): W8004 'WM_TASKBARCREATED' is assigned a value that is never used CPP / C++ / C Code:
|
|
#8
|
|||
|
|||
|
for GET_X_LPARAM and GET_Y_LPARAM, #include <windowsx.h> along with the standard <windows.h>. For the last warning, it is never used because I didn't say anything about implementing it. You will probably want to put that in a header file somewhere, and then in your window procedure, handle the WM_TASKBARCREATED message. In that handler, you will want to call the function that adds your tray icons. As for the nid and hwnd variables, I would still need to see more code. However, I can try. If all this is in a function (called MinimizeToTray or whatever), declare NOTIFYICONDATA nid; at the beginning of the function. HWND hwnd will have to be passed as a parameter (it is the handle to your main window). About wParam: if that code is in your window procedure, as it should be, change "wParam" to whatever you named the WPARAM window procedure parameter.
|
|
#9
|
|||
|
|||
|
Dear ubergeek,
can you create a small example programm and send the source code to my email adress? (mapa@marcus-2000.de) Because i have problems to understand your instructions!!!! (Sorry my english is not very good) Bye Marcus |
|
#10
|
|||
|
|||
|
sure, why not. i'll just post here instead of emailing so that other people can learn from it too. here is the source:
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
And there you have it--Tray Example. NB: I don't know Borland, so you'll have to use tray.rc however one uses resource files in Borland--perhaps through the IDE somehow, or with a #pragma |
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gcc-grouping instructions of diff. types for application | bravetanveer | C++ Forum | 1 | 25-Mar-2005 09:01 |
| Help! Some basal questions about MFC | xutingnjupt | MS Visual C++ / MFC Forum | 1 | 05-Dec-2004 03:38 |
| Track change in system time | Poolan | C++ Forum | 3 | 19-Nov-2004 04:08 |
| i = system ("cd c:\text"); :( | kyle | C Programming Language | 1 | 25-Aug-2003 11:43 |
| PHP doc system - for when you need to write up some documentation | jrobbio | MySQL / PHP Forum | 0 | 22-May-2003 08:43 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The