Tutorial - Write Icon in the Taskbar Window
Posted
by Roberto Cagnetti
on November 2nd, 2001
Environment: VC6 SP4, W9x, NT 4
This simple program code show how to write or remove an icon from the window taskbar and add a tool tip text. It also show how you can define a user message for trap events generate with mouse action (click on the icon). The sample application is an MFC exe dialog based program.

The routine for write and remove icon:
void CWriteTaskBarDlg::OnWrite()
{
// handle to icon
HICON hIcon;
// text for tool tip
char lpszTip[] = "Mouse is on the Icon !!";
HINSTANCE hInst =
AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON1),
RT_GROUP_ICON);
hIcon = (HICON)LoadImage( hInst,
MAKEINTRESOURCE(IDI_ICON1),
IMAGE_ICON,
16,
16,
LR_DEFAULTCOLOR);
// set NOTIFYCONDATA structure
NOTIFYICONDATA tnid;
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = m_hWnd;
tnid.uID = IDI_ICON1;
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnid.uCallbackMessage = WM_TASKBAR; // my user message
tnid.hIcon = hIcon;
if (lpszTip)
lstrcpyn(tnid.szTip, lpszTip, sizeof(tnid.szTip));
else
tnid.szTip[0] = '\0';
// call to Shell_NotifyIcon with NIM_ADD parameter
Shell_NotifyIcon(NIM_ADD, &tnid);
// free icon
if (hIcon)
DestroyIcon(hIcon);
}
For remove icon:
void CWriteTaskBarDlg::OnRemove()
{
// for remove, only provide cbSize, hWnd and uID!
NOTIFYICONDATA tnid;
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = m_hWnd;
tnid.uID = IDI_ICON1;
// call to Shell_NotifyIcon with NIM_DEL parameter
Shell_NotifyIcon(NIM_DELETE, &tnid);
}
For Mouse Message:
LRESULT CWriteTaskBarDlg::OnTaskbar(WPARAM wParam,
LPARAM lParam)
{
UINT uMouseMsg = (UINT) lParam;
switch (uMouseMsg)
{
case WM_LBUTTONDOWN:
AfxMessageBox("Mouse click on the Icon !");
break;
default: break;
}
return 0;
}

Comments
Jordan shoes mentioned Gene to buy the discredit, a disunion of Nike
Posted by TaddyGaffic on 04/22/2013 09:17amWhere did that get us? A bunch of banks writing loans that they didnt care if poeple would be able to pay for because they were conforming [url=http://markwarren.org.uk/property-waet.cfm]air max 90 uk[/url] loans and Fannie and Freddie would back them. And their $150+ billion losses show that they are just as unable to predict or control the market as the rest of us. It won't work because it doesn't reward investors for taking the risks involved. In order to set a good example of following your dreams, you may wish to consider strictly limiting, or eliminating TV from your life. When people are involved in pursuing their dreams they often find that they do not have the time to watch TV. TV just gets in the way of pursuing other dreams.. Take a limousine ride with Aerosmith on one of the fastest rollercoaster you have to face. Live shows throughout the day from Beauty and the Beast [url=http://markwarren.org.uk/goodbuy.cfm]nike free uk[/url] will bring memories flooding back for young and old. You can get closer to the action and feel that he wanted to be in the spotlight. Other technology advancements are the midsole. It has a compression molded EVA for lasting impact protection. A Vibrakill shock-absorber in the heel provides a lot of [url=http://northernroofing.co.uk/roofins.cfm]nike free run uk[/url] comfort, and the Exact Pro technology combines a pebax plate and a Dynamic camflex in the forefoot for improved energy return on every step. Meindl Borneo Lady Pro - This shoe is just one of my wifes most popular hiking boots. It is appropriate for lengthy outdoor hikes and you can actually do a tiny stretch of hill hiking whilst sporting them. This product also includes memory foam
ReplyActually...
Posted by grahamr (work) on 10/03/2006 04:59am...it's not taskbar or traybar, but SystemTray as most of the literature I've read calls it.
ReplyGenerating a mouse click
Posted by Legacy on 11/02/2003 12:00amOriginally posted by: Seth D.
Hi,
I'm trying to find a simple code(visual C++)
that will generate a mouse click in a specific area(like clicking on the Start menu).
Thanx,
Seth.
ReplyNope, it's taskbar and not traybar.
Posted by Legacy on 05/26/2002 12:00amOriginally posted by: Zack
Search for Shell_NotifyIcon in the MSDN docs and check out the following in the remarks sections.
The taskbar notification area is sometimes erroneously called the "tray."
I couldn't find a "Tray bar" options in Windows. However, when I hide the taskbar in windows, the so called "tray bar" disappears along with it. I guess that would mean that this "tray bar" is apart of the taskbar?
However, it seems that "Traybar" is a popular term for the task bar notification area. The term was probably coined by a marketing department at some company that is now out of business.
Calling someone an idiot for using the proper terminology is well... Do your research first.
Reply
Dammit it's not the taskbar it's the tray bar!!
Posted by Legacy on 02/08/2002 12:00amOriginally posted by: DaaZ
No wonder I can't find anything about hiding a window from the taskbar! There are countless morons who write stuff about adding/removing an icon from the taskbar but who, like our idiot here,are actually talking about the FUCKING TRAY BAR!!!
Dammit it's not that complicated!
ReplyGood One, But..
Posted by Legacy on 11/06/2001 12:00amOriginally posted by: Praveen Dandu
It's a good one..but the exactly same example has been provided in the MSDN itself..
Replyreply
Posted by Legacy on 11/05/2001 12:00amOriginally posted by: Erwan
Resourceful..
ReplySomeone had wrote a class for this: CTrayIcon
Posted by Legacy on 11/03/2001 12:00amOriginally posted by: DaFu Chen
Someone had wrote a class for this situation, the class is named CTrayIcon.
ReplyBetter tutorial @ http://www.maxcode.com/
Posted by Legacy on 11/02/2001 12:00amOriginally posted by: clemens
check the BETTER tutorial @MAXcode
Reply