Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding an icon to the taskbar using Shell_NotifyIcon

Posted on 2000-03-02
12
Medium Priority
?
715 Views
Last Modified: 2012-05-05
Hello,
I'm tyring to add an icon to the taskbar with a menu and all.. I'm using VC++ 6 and created a dialog based project. everything seems fine, the icon appears and stays there when i move the mouse over it, however, i don't seem to be able to track it's callback function down, i created a const
#define MYWM_NOTIFYICON 1000

and was passing that as the callback, i also mapped it:
(were the other functions were mapped)
ON_NOTIFY(MYWM_NOTIFYICON, 1, OnClickDoTest)

and declared the OnClickDoTest functions with afx_msg like so:

afx_msg void CTestDlg::OnClickDoTest(WPARAM wParam, LPARAM lParam)

in the class protected section under the rest of it's kind...

however, no i receive no messages, any help? sample code would greatly help...

and also one more thing, if this succeeds, i would like to get rid of the button that windows puts in the taskbar for my dialog, how is that achievable?!
only giving 100 points, although i think it deserves more, but sorry i'm new here and only got 200 points.
Thanx in advance
0
Comment
Question by:narcotic030200
[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
  • 9
  • 3
12 Comments
 
LVL 5

Accepted Solution

by:
Wyn earned 400 total points
ID: 2579104
Code below also needed for you purpose:

hIcon = LoadIcon(IDR_MAINFRAME);
NOTIFYICONDATA pnid;
pnid.cbSize = sizeof(NOTIFYICONDATA);
pnid.hWnd = AfxGetMainWnd()->m_hWnd;
pnid.uID = IDR_MAINFRAME;
pnid.uFlags = NIF_ICON;
pnid.hIcon = hIcon;
pnid.uCallbackMessage = MYWM_NOTIFYICON; ;
::Shell_NotifyIcon(NIM_ADD,&pnid);
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2579115

0
 
LVL 5

Expert Comment

by:Wyn
ID: 2579127
Here is all for the menu ,
LRESULT CTestDlg::OnClickDoTest(WPARAM wParam, LPARAM lParam)
{
UINT uID       = (UINT)wParam;
UINT uMouseMsg = (UINT)lParam;

if (uID != ID_TRAYICON) return 0L;

switch(uMouseMsg)
{
case WM_RBUTTONDOWN :
{
CMenu cTaskBarMenu;

if (!cTaskBarMenu.LoadMenu(IDM_TASKBARICON))
return 0L;

CMenu *pcTaskBarMenu = cTaskBar.GetSubMenu(0);

CPoint point;
GetCursorPos(&point);
SetForegroundWindow();
pcTaskBarMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x, point.y,this);
PostMessage(NULL,0,0);
cTaskBarMenu.DestroyMenu();                                        
}
break;
}
return 0L;
}

===========



In case you use plain c++,here is c++ code for the menu,sometimes You also need use SetForegroundWindow(YourMainWindowHandle) before call TrackPopupMenu and call post(null,0,0):
//suppose you have the window handle.
   int PopMenuRet;
   POINT aPoint;

   PopMenu = CreatePopupMenu();

   AppendMenu(PopMenu,MFT_STRING,IDM_OPTION1,"Option 1");
   AppendMenuPopMenu,MFT_STRING,IDM_OPTION2,"Option 2");
   AppendMenu(PopMenu,MFT_SEPARATOR,0,NULL);
   AppendMenu(PopMenu,MFT_STRING,IDM_OPTION3,"Option 3");
   AppendMenu(PopMenu,MFT_STRING,IDM_OPTION4,"Option 4");
   AppendMenu(PopMenu,MFT_STRING,IDM_OPTION5,"Option 5");
   AppendMenu(PopMenu,MFT_STRING,IDM_OPTION6,"Option 6");
   AppendMenuPopMenu,MFT_STRING,IDM_CANCELOPTION,"Cancel");

   GetCursorPos(&aPoint);

   PopMenuRet = TrackPopupMenu(PopMenu,
                               TPM_RIGHTBUTTON |
       TPM_TOPALIGN |
                               TPM_LEFTALIGN |
                               TPM_RETURNCMD,
                               aPoint.x,
                               aPoint.y,
                               0,
                               hwnd,
                               NULL);
   DestroyMenu(PopMenu);

   switch (PopMenuRet) {
   case IDM_OPTION1:
              /* Do Option 1 Stuff */
              break;
   case IDM_OPTION2:
              /* Do Option 2 Stuff */
              break;
   case IDM_OPTION3:
              /* Do Option 3 Stuff */
              break;
   case IDM_OPTION4:
              /* Do Option 4 Stuff */
              break;
   case IDM_OPTION5:
              /* Do Option 5 Stuff */
              break;
   case IDM_CANCELOPTION:
              /* Do Cancel Stuff */
              break;
   }
   return 0;
}


->if this succeeds, i would like to get rid of the button that windows puts in the taskbar for my dialog
=======================
What do you mean by getting rid of ?
If you want it disppear when you minimize the window,it's easy:

case WM_SIZE:
 if(wparam==SIZE_MINIMIZED)
 ShowWindow(hwnd,SW_HIDE);

this will hide the button in task bar.
Regards
W.Yinan
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:Wyn
ID: 2579133
->ON_NOTIFY(MYWM_NOTIFYICON, 1, OnClickDoTest)
=======
Try ON_MESSAGE Macro.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2579137
->ON_NOTIFY(MYWM_NOTIFYICON, 1, OnClickDoTest)
=======
Try ON_MESSAGE Macro.

For a complete sample,try:

http://www.codeguru.com/shell/systemtray.shtml

Regards
W.Yinan
0
 
LVL 1

Author Comment

by:narcotic030200
ID: 2579140
Thank you very much, i haven't gone through the whole code in detail, but i think you pointed out what i needed to know...
Thanks
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2579146
P.S:
FYI,the ON_MESSAGE macro should be this way:

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CNiconDlg)
        ....
//}}AFX_MSG_MAP
ON_MESSAGE(MYWM_NOTIFYICON,OnClickDoTest)
END_MESSAGE_MAP()

Final point , the button cannot be gotten rid of if window has show-style,except the tool window.

Help all above have thoroughly solve your problems...


0
 
LVL 5

Expert Comment

by:Wyn
ID: 2579148
->Thank you very much, i haven't gone through the whole code in detail, but i think you pointed out what i needed to know...
Thanks
===========

if you dont care alot.I think you can simple change the ON_NOTIFY to ON_MESSAGE , the later is the correct one for user-defined message.

Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2579149
->Thank you very much, i haven't gone through the whole code in detail, but i think you pointed out what i needed to know...
Thanks
===========

if you dont care alot.I think you can simple change the ON_NOTIFY to ON_MESSAGE , the later is the correct one for user-defined message.

plz give me a feedback if you read the last two comments.
Regards
W.Yinan
0
 
LVL 1

Author Comment

by:narcotic030200
ID: 2579152
I will run the code you gave me tomorrow, it's 2:30am here now and i'm Very tired, i'll let you know what happens...
Thanks again
0
 
LVL 1

Author Comment

by:narcotic030200
ID: 2580482
Ok, all i had to do is change the ON_NOTIFY to ON_MESSAGE and it worked like a charm :)
However, the problem of having the normal button in the taskbar is still there, i don't know if you get what i meant by deleting it, what i'm aiming to do is an application that is accesed through the icon in the taskbar online and not it's button.... in VB i usually set the ShowInTaskBar value to FALSE, i can't figure out how to do it in VC++... shouldn't be too hard i guess...
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2580723
Again,if you wanna the button hidden if your window is minimized.Using way above and the button cannot be gotten rid of if window has show-style,except the tool window.
If I dont help you alot.I suggest you post another question(50pts enough for this) and let another expert help you.
Sincerely
W.Yinan
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

597 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