Solved

A problem with receiving a message from a Taskbar Icon

Posted on 1999-01-05
5
202 Views
Last Modified: 2012-05-04
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
 



0
Comment
Question by:gilbert_chang
  • 2
  • 2
5 Comments
 

Author Comment

by:gilbert_chang
Comment Utility
I forgot to add that I actually put the icon by:
fAdded = Shell_NotifyIcon(NIM_ADD, &tnd);
right after all the icon's definitions.
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
>> 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.
0
 

Accepted Solution

by:
_serega earned 50 total points
Comment Utility
hi gilbert_chang
i suppose that you put an incorrect value in tnd.hWnd
i've got your code and set
tnd.hWnd = this -> m_hWnd;
(in my OnInitDialog )
and all works
regards

0
 

Expert Comment

by:_serega
Comment Utility
hi again
as far as i know,
Shell_NotifyIcon() function returns int value, not boolean
0
 

Author Comment

by:gilbert_chang
Comment Utility
Thanks.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now