Solved

A problem with receiving a message from a Taskbar Icon

Posted on 1999-01-05
5
210 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

790 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