Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding icon to tray...

Posted on 1998-09-02
1
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 280 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

670 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