Solved

Adding icon to tray... again

Posted on 1998-09-04
9
269 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
Independent Software Vendors: 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

Industry Leaders: 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!

Question has a verified solution.

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

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

738 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