Solved

Adding icon to tray...

Posted on 1998-09-02
1
171 Views
Last Modified: 2010-04-10
Hi everyone, I have a MFC application that is dialog based. I now want to add the option to "close" the application but have it running in the tray. And if the application is not selected to go to they tray, it must still operate as the normal dialog based application. How do I do this and where in my program do I place all the commands, etc. Thanks,
0
Comment
Question by:rose337
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 70 total points
ID: 1171910
Here''s the steps

1. Override OnClose for the dialog
i. Don't close the dialog (default base class calls DestroyWindow)
ii. Instead hide the dialog using something like
ShowWindow (SW_HIDE)
iii. Create a dummy hidden window (using CreateWindow)
iv. Add an item to the system tray using Shell_NotifyIcon (NIM_ADD, and a NOTIFYICONDATA structure are parameters).  The NOTIFYICONDATA message includes the hWnd of the dummy hidden window - this window will receive messages when the icon is clicked on or whatever.

2.In the dummy hidden window code
i. Wait for double click or whatever
ii. When you get one, reshow the dialog using ShowWindow
iii. Destroy the dummy hidden window

BTW - how does the user really close your app ?  Might it be better to do it on minimizing ?

One final point, when debugging I suggest you make the dummy window visible and don't bother show/hiding the dialog.  After the basic structure is working then add the code to hide the dummy window and show/hide the app's dialog.

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to programmatically differentiate between C and Java 10 204
C++ Language error 28 246
passing data from one form to another form in c++ 27 83
Finding Divisors 5 20
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question