Link to home
Start Free TrialLog in
Avatar of rose337
rose337

asked on

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);
}
Avatar of chensu
chensu
Flag of Canada image

What are you doing with
do
{
}
while (LOWORD(lParam) == WM_LBUTTONDBLCLK);
?
Avatar of rose337
rose337

ASKER

I am doing nothing with it... it mst just loop until left button is hit...
ASKER CERTIFIED SOLUTION
Avatar of WxW
WxW

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry it is NOTIFYICONDATA nn; and not n
It is better to use WM_APP than WM_USER.
Yeah another mistake of mine...
>> Yeah another mistake of mine...
Stop worrying.  You're doing fine.
Avatar of rose337

ASKER

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...
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() .