Solved

Adding icon to tray...

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixing C++ & C# in Vis Studio 2013 7 239
Printing the elements of a set declared inside a map in C++. 3 59
Dialogbox API leak? 18 109
Least Squares Curve Fitting 4 117
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…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

730 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