Solved

Adding icon to tray...

Posted on 1998-09-02
1
177 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 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

626 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