1 /////////////////////////////////////////////////////////////////////////
3 // Purpose: Implements wxTaskBarIcon class for manipulating icons on
4 // the Windows task bar.
5 // Author: Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////
14 #pragma implementation "taskbar.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
30 #include <wx/msw/taskbar.h>
33 #include <wx/msw/private.h>
36 #include <wx/msw/gnuwin32/extra.h>
39 LRESULT APIENTRY _EXPORT
wxTaskBarIconWindowProc( HWND hWnd
, unsigned msg
,
40 UINT wParam
, LONG lParam
);
42 char *wxTaskBarWindowClass
= "wxTaskBarWindowClass";
44 wxList
wxTaskBarIcon::sm_taskBarIcons
;
45 bool wxTaskBarIcon::sm_registeredClass
= FALSE
;
46 UINT
wxTaskBarIcon::sm_taskbarMsg
= 0;
48 wxTaskBarIcon::wxTaskBarIcon(void)
55 if (RegisterWindowClass())
56 m_hWnd
= CreateTaskBarWindow();
59 wxTaskBarIcon::~wxTaskBarIcon(void)
70 ::DestroyWindow((HWND
) m_hWnd
);
76 bool wxTaskBarIcon::SetIcon(const wxIcon
& icon
, const wxString
& tooltip
)
81 NOTIFYICONDATA notifyData
;
83 memset(¬ifyData
, 0, sizeof(notifyData
));
84 notifyData
.cbSize
= sizeof(notifyData
);
85 notifyData
.hWnd
= (HWND
) m_hWnd
;
86 notifyData
.uCallbackMessage
= sm_taskbarMsg
;
87 notifyData
.uFlags
= NIF_MESSAGE
;
90 notifyData
.uFlags
|= NIF_ICON
;
91 notifyData
.hIcon
= (HICON
) icon
.GetHICON();
94 if (((const char*) tooltip
!= NULL
) && (tooltip
!= ""))
96 notifyData
.uFlags
|= NIF_TIP
;
97 lstrcpyn(notifyData
.szTip
, (char*) (const char*) tooltip
, sizeof(notifyData
.szTip
));
103 return (Shell_NotifyIcon(NIM_MODIFY
, & notifyData
) != 0);
106 m_iconAdded
= (Shell_NotifyIcon(NIM_ADD
, & notifyData
) != 0);
111 bool wxTaskBarIcon::RemoveIcon(void)
116 NOTIFYICONDATA notifyData
;
118 memset(¬ifyData
, 0, sizeof(notifyData
));
119 notifyData
.cbSize
= sizeof(notifyData
);
120 notifyData
.hWnd
= (HWND
) m_hWnd
;
121 notifyData
.uCallbackMessage
= sm_taskbarMsg
;
122 notifyData
.uFlags
= NIF_MESSAGE
;
123 notifyData
.hIcon
= 0 ; // hIcon;
127 return (Shell_NotifyIcon(NIM_DELETE
, & notifyData
) != 0);
131 void wxTaskBarIcon::OnMouseMove(void)
135 void wxTaskBarIcon::OnLButtonDown(void)
139 void wxTaskBarIcon::OnLButtonUp(void)
143 void wxTaskBarIcon::OnRButtonDown(void)
147 void wxTaskBarIcon::OnRButtonUp(void)
151 void wxTaskBarIcon::OnLButtonDClick(void)
155 void wxTaskBarIcon::OnRButtonDClick(void)
159 wxTaskBarIcon
* wxTaskBarIcon::FindObjectForHWND(WXHWND hWnd
)
161 wxNode
*node
= sm_taskBarIcons
.First();
164 wxTaskBarIcon
* obj
= (wxTaskBarIcon
*) node
->Data();
165 if (obj
->GetHWND() == hWnd
)
172 void wxTaskBarIcon::AddObject(wxTaskBarIcon
* obj
)
174 sm_taskBarIcons
.Append(obj
);
177 void wxTaskBarIcon::RemoveObject(wxTaskBarIcon
* obj
)
179 sm_taskBarIcons
.DeleteObject(obj
);
182 bool wxTaskBarIcon::RegisterWindowClass()
184 if (sm_registeredClass
)
187 // Also register the taskbar message here
188 sm_taskbarMsg
= ::RegisterWindowMessage("wxTaskBarIconMessage");
193 HINSTANCE hInstance
= GetModuleHandle(NULL
);
196 * set up and register window class
198 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
199 wc
.lpfnWndProc
= (WNDPROC
) wxTaskBarIconWindowProc
;
202 wc
.hInstance
= hInstance
;
205 wc
.hbrBackground
= 0;
206 wc
.lpszMenuName
= NULL
;
207 wc
.lpszClassName
= wxTaskBarWindowClass
;
208 rc
= (::RegisterClass( &wc
) != 0);
210 sm_registeredClass
= (rc
!= 0);
215 WXHWND
wxTaskBarIcon::CreateTaskBarWindow()
217 HINSTANCE hInstance
= GetModuleHandle(NULL
);
219 HWND hWnd
= CreateWindowEx (0, wxTaskBarWindowClass
,
231 return (WXHWND
) hWnd
;
234 long wxTaskBarIcon::WindowProc( WXHWND hWnd
, unsigned int msg
, unsigned int wParam
, long lParam
)
236 if (msg
!= sm_taskbarMsg
)
237 return DefWindowProc((HWND
) hWnd
, msg
, wParam
, lParam
);
257 case WM_LBUTTONDBLCLK
:
261 case WM_RBUTTONDBLCLK
:
275 LRESULT APIENTRY _EXPORT
wxTaskBarIconWindowProc( HWND hWnd
, unsigned msg
,
276 UINT wParam
, LONG lParam
)
278 wxTaskBarIcon
* obj
= wxTaskBarIcon::FindObjectForHWND((WXHWND
) hWnd
);
280 return obj
->WindowProc((WXHWND
) hWnd
, msg
, wParam
, lParam
);
282 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);