Solved

Adding icon to tray...

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now