Solved

Adding icon to tray... again

Posted on 1998-09-04
9
270 Views
Last Modified: 2010-04-02
Hi everyone... I tried and failed. I have made a simple dialog based MFC application. I added a control to the dialog to place an icon in the tray. If the icon is clicked, I want the dialog to reappear and the icon in the tray to disappear. What is wrong with this short cut...? How do I fix it and allow myself to click it closed and have a caption when the mouse passes over it? Thanks

if (Tray == 1)
{
ShowWindow(SW_HIDE);
m_NotifyIconData.cbSize = sizeof(m_NotifyIconData);
m_NotifyIconData.uFlags = NIF_ICON;
m_NotifyIconData.hIcon = m_hIcon;
uCallbackMessage;
m_NotifyIconData.szTip, "Dialog Application";
Shell_NotifyIcon(NIM_ADD,&m_NotifyIconData);
do
{
}
while (LOWORD(lParam) == WM_LBUTTONDBLCLK);
m_NotifyIconData.uFlags = 0;
Shell_NotifyIcon(NIM_DELETE,&m_NotifyIconData);
ShowWindow(SW_SHOW);
}
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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1172029
What are you doing with
do
{
}
while (LOWORD(lParam) == WM_LBUTTONDBLCLK);
?
0
 

Author Comment

by:rose337
ID: 1172030
I am doing nothing with it... it mst just loop until left button is hit...
0
 
LVL 6

Accepted Solution

by:
WxW earned 70 total points
ID: 1172031
This is the correct method to "wait" for a message caused by an icon in the system tray

#define MESSAGE_CALLBACK (WM_USER + 4)
NOTIFYICONDATA n;

      nn.cbSize = sizeof(nn);
      nn.hWnd = HWindow; // The handle of the window to post the message
      nn.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
      nn.hIcon = hIconMain; // The handle of the icon
      nn.uCallbackMessage = MESSAGE_CALLBACK;
   lstrcpy(nn.szTip,"Your Tip Here");
      Shell_NotifyIcon(NIM_ADD,&nn);

Then your WindowProc should catch the MESSAGE_CALLBACK as follows

      switch(message)
            {
            case MESSAGE_CALLBACK:
                  {
                  if (lParam == WM_LBUTTONDBLCLK)
                        {
                        Shell_NotifyIcon(NIM_DELETE,&nn);
                        }
       return 0;
                  }

For example I did a NIM_DELETE , if a Double Click occurs . You can specify any other mouse message || action .
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:WxW
ID: 1172032
Sorry it is NOTIFYICONDATA nn; and not n
0
 
LVL 11

Expert Comment

by:alexo
ID: 1172033
It is better to use WM_APP than WM_USER.
0
 
LVL 6

Expert Comment

by:WxW
ID: 1172034
Yeah another mistake of mine...
0
 
LVL 11

Expert Comment

by:alexo
ID: 1172035
>> Yeah another mistake of mine...
Stop worrying.  You're doing fine.
0
 

Author Comment

by:rose337
ID: 1172036
Thanks WxW... I have tried it and I am lost with an error...
firstly, what message should I place in switch to make sure that it will accept my mouse click and does not run through this segment of code and never return to accept the click...
secondly, the complier does not like the line
case MESSAGE_CALLBACK:
it gives errors of no closing bracket or semicolons, etc.
and then when I work around that, an icon appears but does not accept the click to disappear.
I now have seven of the same icons in my tray with no way to close them ;-)
By the way, the way the program is structured is that I have a dialog, then the user hits a property sheet button and the option for a tray icon is there. If he selects it, and closes the property sheet, the dialog disapears and the icon should be in the tray. All icon manipulation (placing and removing it) occurs in the OnProperties segment that is executed when the property sheet is closed.
Thanks for any help that you can give...
0
 
LVL 6

Expert Comment

by:WxW
ID: 1172037
you need to check for example WM_LBUTTONDOWN for a left mouse click .  I used DLBCLICK to check for a double click .

You have possibly defined MESSAGE_CALLBACK in that way :

#define MESSAGE_CALLBACK WM_APP + 4;

remove the ; from the end

You can create the icon tray then by using some property like ON CLOSE or OR DESTROY . If you use plain C++ , just handle the WM_CLOSE message .

The handling of MESSAGE_CALLBACK is your work . If you need just to remove the icon tray , use the Shell_NotifyIcon to remove it . You may want also to reshow the dialog box ... in that case you need to handle WM_CLOSE and just hide ( but not destroy ) the dialog . Then withing the MESSAGE_CALLBACK handle you just reshow the dialog with ShowWindow() .



0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.

623 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