Link to home
Start Free TrialLog in
Avatar of gilbert_chang
gilbert_chang

asked on

A problem with receiving a message from a Taskbar Icon

In my application's main function I create a new taskbar icon with:
bool fAdded;
NOTIFYICONDATA tnd;
LPCTSTR g_szState1="You are over the icon...";
lstrcpyn (tnd.szTip, g_szState1, sizeof (tnd.szTip));
tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnd.uID = (UINT)IDI_MYICON;
tnd.cbSize = sizeof (NOTIFYICONDATA);
tnd.hWnd = m_pMainWnd->m_hWnd;
tnd.uCallbackMessage = MYWM_NOTIFYICON;
tnd.hIcon = AfxGetApp()->LoadIcon(IDI_MYICON);

when m_mMainWnd is:
CMyAppDlg dlg;
m_pMainWnd = &dlg;

In CMyAppDlg I wrote:
BEGIN_MESSAGE_MAP(CMyAppDlg, CDialog)
      //{{AFX_MSG_MAP(CMyAppDlg)
ON_MESSAGE(MYWM_NOTIFYICON, TrayCallback)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

and TrayCallback is defined:
void CMyAppDlg::TrayCallback (WPARAM wParam, LPARAM lParam)
{
      UINT uID;
      UINT uMouseMsg;

      uID = (UINT)wParam;
      uMouseMsg = (UINT)lParam;

      if (uMouseMsg == WM_LBUTTONDOWN)
      {
            if (uID == (UINT)IDR_MAINFRAME)
                  MessageBox ("This sure is fun!", "Click!", MB_OK);
      }
}

The Taskbar icon is displayed properly, but when I pass the mouse over it, it disappears, and the message box isn't displayed. (the TrayCallback function is not even entered.)
Help would be appreciated.
Thanks
 



Avatar of gilbert_chang
gilbert_chang

ASKER

I forgot to add that I actually put the icon by:
fAdded = Shell_NotifyIcon(NIM_ADD, &tnd);
right after all the icon's definitions.
>> The Taskbar icon is displayed properly, but when I pass the mouse over it, it disappears
It usually happens when the program is either terminated without removing the icon or is not in a message loop.
ASKER CERTIFIED SOLUTION
Avatar of _serega
_serega

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
hi again
as far as i know,
Shell_NotifyIcon() function returns int value, not boolean
Thanks.