[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Adding icon to tray... again

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
rose337
Asked:
rose337
  • 4
  • 2
  • 2
  • +1
1 Solution
 
chensuCommented:
What are you doing with
do
{
}
while (LOWORD(lParam) == WM_LBUTTONDBLCLK);
?
0
 
rose337Author Commented:
I am doing nothing with it... it mst just loop until left button is hit...
0
 
WxWCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
WxWCommented:
Sorry it is NOTIFYICONDATA nn; and not n
0
 
alexoCommented:
It is better to use WM_APP than WM_USER.
0
 
WxWCommented:
Yeah another mistake of mine...
0
 
alexoCommented:
>> Yeah another mistake of mine...
Stop worrying.  You're doing fine.
0
 
rose337Author Commented:
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
 
WxWCommented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now