To add a task bar icon to your application, add a member variable to your window...
CTaskBarIcon m_ti
Then in the OnInitDialog()
event handler, initialise the icon:
LRESULT OnInitDialog(UINT /*uMsg*/,
WPARAM /*wParam*/,
LPARAM /*lParam*/,
BOOL& /*bHandled*/)
{
...
m_ti.Install(m_hWnd, 1, IDR_TASKBAR);
...
}
You now need to define the resource IDR_TASKBAR
. Create a
string resource for the tooltip, an icon resource for
the icon image and a menu for the popup. Make sure to use the
symbolic name IDR_TASKBAR
for all of them.
Then chain the class to the message map for default handling.
BEGIN_MSG_MAP(CMainDlg)
...
CHAIN_MSG_MAP_MEMBER(m_ti)
END_MSG_MAP()
The Shell Task Bar API defines a few notifications when things happen over
your new icon. For compatibility reasons, you should use the
WM_LBUTTONDOWN
and WM_RBUTTONDOWN
events with
the new TASKBAR_MESSAGE_HANDLER
message map macro.
BEGIN_MSG_MAP(CMainDlg)
...
TASKBAR_MESSAGE_HANDLER(m_ti, WM_LBUTTONDOWN, OnTaskIconClick)
...
END_MSG_MAP()
LRESULT OnTaskIconClick(LPARAM /*uMsg*/, BOOL& /*bHandled*/)
{
// code code code
return 0;
}
When you use a Task Bar icon it doesn't necessarily mean that your window
will minimize to the taskbar. This is additional functionality you must add
yourself.
You simply need to handle when you application is minimized:
LRESULT OnSize(UINT /*uMsg*/, WPARAM wParam, LPA...
{
if( wParam==SIZE_MINIMIZED) ShowWindow(SW_HIDE);
bHandled = FALSE;
return 0;
}
Call ShowWindow(SW_SHOWNORMAL)
to show the window again when someone clicks
on the icon.
Source Code Dependencies
Microsoft WTL 3.0 LibrarySee Also
A WTL sampleDownload Files
![]() | Source Code (3 Kb) |