Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tray icon

Status
Not open for further replies.

Pinpoint

Programmer
Dec 23, 2001
49
0
0
GB
Hi,
I have a tray icon which calls up a popup menu when the mouse is over it using:
ON_REGISTERED_MESSAGE(TaskbarCallbackMsg, OnTaskbarNotify)

NOTIFYICONDATA * pNotify = new NOTIFYICONDATA;
pNotify->hWnd = this->m_hWnd;
pNotify->uFlags = NIF_MESSAGE|NIF_ICON;
pNotify->hIcon = officon;
pNotify->uCallbackMessage = TaskbarCallbackMsg;
Shell_NotifyIcon(NIM_ADD, pNotify);

LRESULT CMainFrame::OnTaskbarNotify(WPARAM wParam, LPARAM lParam)
{ ShowPopup(); // create popup menu
return 0;}

That's fine in debug mode, but when I compile as release the tray icon no longer appears. Any idea why ?

Secondly, can I get the popup menu to appear only when the right-mouse-button is clicked, currently it also appears when the mouse is over the icon...I have enabled OnRbuttondown, but the function OnTaskbarNotify seems to get in first and the menu pops up before the mouse click.

Thanks in advance.
 
1. Sorry. Can't understand from the code provided why it doesn't work in release.

2. To be able to show the "tray menu" only when the user pressed the right mouse button, you should do it this way:

LRESULT CMainFrame::OnTaskbarNotify(WPARAM wParam, LPARAM lParam)
{
// The code bellow is for handling right mouse button
// to handle left mouse button, use:
// if (lParam == WM_LBUTTONDOWN) or
// if (lParam == WM_LBUTTONUP)


if (lParam == WM_RBUTTONDOWN)
// or if (lParam == WM_RBUTTONUP)
{
ShowPopup(); // create popup menu
return 1;
}

return 0;
}
 
Thanks, that works now.
Re the Debug/Release problem; here are other bits of related code:

UINT TaskbarCallbackMsg = ::RegisterWindowMessage(_T("Trayicon"));

void CMainFrame::OnClose()
{
NOTIFYICONDATA* pNotify = new (NOTIFYICONDATA);
pNotify->hWnd = this->m_hWnd;
Shell_NotifyIcon(NIM_DELETE, pNotify); // delete tray icon
delete pNotify;

CFrameWnd::OnClose();
}

Must admit I dont know the relevence of the "Trayicon" string. It doesnt get used anywhere... Are there any other factors which might cause problems in Release but not in Debug ?
Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top