Tray function

Hi there, i have this function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void tt() {

NOTIFYICONDATA Tray;
HWND hWnd;

//window handle
hWnd=FindWindow("ConsoleWindowClass",NULL);

//hide the window
ShowWindow(hWnd,0);

//tray info
Tray.cbSize=sizeof(Tray);
Tray.hIcon=LoadIcon(NULL,IDI_WINLOGO);
Tray.hWnd=hWnd;
strcpy(Tray.szTip,"My Application");
Tray.uCallbackMessage=WM_LBUTTONDOWN;
Tray.uFlags=NIF_ICON | NIF_TIP | NIF_MESSAGE;
Tray.uID=1;

//set the icon in tasbar tray
Shell_NotifyIcon(NIM_ADD, &Tray);
}

The app is going to tray ok but how to restore it? Something like click/double-click on it..?
Last edited on
In order to operate an icon in the notification area (a. k. a. the system tray), you need a message pump and a window (visible or invisible).

Since console windows don't have windows or message pumps, you probably won't find any examples of a system tray icon in console.

So start a new project, this time make it a Windows GUI project, create a new window (invisible or visible), and use that HWND to set up the icon in the notification area.

Once it is set up, you can receive the clicks and double-clicks in the window procedure of the (visible or invisible) window.

Note that you should be using a user-defined message in uCallbackMessage (one defined as WM_USER + <some arbitrary positive number>).

To fully understand how you receive messages in response to interactions of the end user with the icon or any ballong shown, see http://msdn.microsoft.com/en-us/library/windows/desktop/bb773352(v=vs.85).aspx .
So not possible as a console app? I have tried to switch from project options to gui app but then it won;t work anymore, the program is executed in background with 100% cpu load.
Don't change the project type. Best to just create a new project using the Visual Studio wizard and making sure you select the appropriate type of project.
Topic archived. No new replies allowed.