Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Taskbar icon dissagears!

Posted on 1999-07-22
16
Medium Priority
?
221 Views
Last Modified: 2013-11-20
I create a taskbar icon using:
BOOL res;
NOTIFYICONDATA tnd;
tnd.cbSize            = sizeof(NOTIFYICONDATA);
tnd.hWnd            = hParent;
tnd.uID                  = uID;
tnd.uFlags            = NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage      = MYWM_NOTIFYICON;
tnd.hIcon            = hIcon;

res = Shell_NotifyIcon(dwMessage, &tnd);

The icon appears, but disappears the moment the mouse passes over it.
In the parent object I do something in the case of a MYWM_NOTIFYICON message, but the program never gets there.
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
  • 8
  • 8
16 Comments
 
LVL 4

Accepted Solution

by:
nil_dib earned 150 total points
ID: 1311099
make the NOTIFYICONDATA tnd object as a member of your class!
0
 

Author Comment

by:gilbert_chang
ID: 1311100
This does not work.
I should explain - The code above is in a class that has functions which perform the creation of the taskbar.
I create this class (either using 'new' or by using it as a member in my parent class) and use it's functions to create the icon.
Following your advice I changed the creation of the class from usage of 'new' in the parent function to usage of the class as a member of my parent object. It still does not work.
Is there any other suggestion?
Thanks.
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1311101
Your App is Dialog based?
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:gilbert_chang
ID: 1311102
Yup.
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1311103
answer comming ...
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1311104
the ico disappears in the following case:

Header of main app:
NOTIFYICONDATA m_tnd;

BOOL CMyApp::InitInstance()
{
    .....
    CMyDlg dlg;
    m_pMainWnd = &dlg;
 
    BOOL res;
    m_tnd.cbSize = sizeof(NOTIFYICONDATA);

    m_tnd.hWnd = m_pMainWnd->m_hWnd;
    m_tnd.uID = 10;
    m_tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
    m_tnd.uCallbackMessage = 0x4711;
    m_tnd.hIcon = LoadIcon(IDR_MAINFRAME);
    res = Shell_NotifyIcon(NIM_ADD, &m_tnd);

    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        ......

I suppose it disspears because the main window (dlg) is not created because auf the DoModal() method wich is called AFTER the Shell_NotifyIcon function.
Anyway if you do the icon creation in the OnInitDialog() of you Dlg the icon will not disspear:

Header of dlg:
NOTIFYICONDATA m_tnd;

BOOL CMyDlg::OnInitDialog()
{
   ......

    BOOL res;
    CMyApp * pApp = (CMyApp*)AfxGetApp();

    m_tnd.cbSize = sizeof(NOTIFYICONDATA);
    m_tnd.hWnd = this->m_hWnd;
    m_tnd.uID = 10;
    m_tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
    m_tnd.uCallbackMessage = 0x4711;
    m_tnd.hIcon = pApp->LoadIcon(IDR_MAINFRAME);
    strcpy(m_tnd.szTip, "hello");
   
    res = Shell_NotifyIcon(NIM_ADD, &m_tnd);

    return TRUE;
}


0
 

Author Comment

by:gilbert_chang
ID: 1311105
Now the icon doesn't disappear, but still does not pass the message to the dialog object, since when I pass over it with the mouse , click on it etc. it does not get into the function defined in:
ON_MESSAGE(MYWM_NOTIFYICON,OnTrayNotify)
Thanks.

0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1311106
mhhh ...
this works fine in my app ...
what I did:

Dlg Header:
afx_msg LONG OnTaskBarIcon(WPARAM wParam, LPARAM lParam);

CPP:
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
      //{{AFX_MSG_MAP(CMyDlg)
      .....
      //}}AFX_MSG_MAP
      ON_MESSAGE( 0x4711, OnTaskBarIcon)
END_MESSAGE_MAP()



LONG CMyDlg::OnTaskBarIcon(UINT wparam, LONG lparam)
{
        switch (lparam)
        {
        case WM_RBUTTONDOWN:
             // do something
             break;
        case WM_LBUTTONDOWN:
             // do something else
            break;
        case WM_LBUTTONDBLCLK:
             // do something else
            break;
        case WM_RBUTTONDBLCLK:
             // do something else
          break;
       default:            
            // or do nothing
          break;
     }
     return TRUE;
}

0
 

Author Comment

by:gilbert_chang
ID: 1311107
This still does not work for me.
Thanks anyway...
Can you think of a reason the app does not recieve a certain message?
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1311108
mhhh ...
what is the value of your MYWM_NOTIFYICON ?
0
 

Author Comment

by:gilbert_chang
ID: 1311109
107
0
 

Author Comment

by:gilbert_chang
ID: 1311110
There is another thing - I send the message to the app (click on the taskbar icon)
while the app is waiting for some event (WaitOnSingleObject). Does that explain why it isn't there to recieve the message?
Thanks
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1311111
ahh,
107 (hex?)
anyway 107 is to low ...

0 through WM_USER (WM_USER = 0x400) - 1 is reserved for internal Windows Messages.
 
WM_USER through 0x7FFF: Integer messages for use by private window classes!!!

so your user defined messge should be defined as

#define MYWM_NOTIFYICON (WM_USER + x )
// x could be 1
 

0
 

Author Comment

by:gilbert_chang
ID: 1311112
Still does not work. Have you seen my second comment (the one after the 107)?
Thanks.
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 1311113
I've seen it ...
should be no problem ...
give me your email, I will send you my dummy project...
0
 

Author Comment

by:gilbert_chang
ID: 1311114
gilbert_chang@hotmail.com
Thanks for your help.
0

Featured Post

Independent Software Vendors: 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

704 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