Solved

A problem with receiving a message from a Taskbar Icon

Posted on 1999-01-05
5
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

696 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