Solved

A problem with receiving a message from a Taskbar Icon

Posted on 1999-01-05
5
207 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
ID: 1181547
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
ID: 1181548
>> 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
ID: 1181549
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
ID: 1181550
hi again
as far as i know,
Shell_NotifyIcon() function returns int value, not boolean
0
 

Author Comment

by:gilbert_chang
ID: 1181551
Thanks.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 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