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;
49 #if !USE_SHARED_LIBRARY
50 BEGIN_EVENT_TABLE(wxTaskBarIcon
, wxEvtHandler
)
51 EVT_TASKBAR_MOVE (wxTaskBarIcon::OnMouseMove
)
52 EVT_TASKBAR_LEFT_DOWN (wxTaskBarIcon::OnLButtonDown
)
53 EVT_TASKBAR_LEFT_UP (wxTaskBarIcon::OnLButtonUp
)
54 EVT_TASKBAR_RIGHT_DOWN (wxTaskBarIcon::OnRButtonDown
)
55 EVT_TASKBAR_RIGHT_UP (wxTaskBarIcon::OnRButtonUp
)
56 EVT_TASKBAR_LEFT_DCLICK (wxTaskBarIcon::OnLButtonDClick
)
57 EVT_TASKBAR_RIGHT_DCLICK (wxTaskBarIcon::OnRButtonDClick
)
61 IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon
, wxEvtHandler
)
65 wxTaskBarIcon::wxTaskBarIcon(void)
72 if (RegisterWindowClass())
73 m_hWnd
= CreateTaskBarWindow();
76 wxTaskBarIcon::~wxTaskBarIcon(void)
87 ::DestroyWindow((HWND
) m_hWnd
);
93 bool wxTaskBarIcon::SetIcon(const wxIcon
& icon
, const wxString
& tooltip
)
98 NOTIFYICONDATA notifyData
;
100 memset(¬ifyData
, 0, sizeof(notifyData
));
101 notifyData
.cbSize
= sizeof(notifyData
);
102 notifyData
.hWnd
= (HWND
) m_hWnd
;
103 notifyData
.uCallbackMessage
= sm_taskbarMsg
;
104 notifyData
.uFlags
= NIF_MESSAGE
;
107 notifyData
.uFlags
|= NIF_ICON
;
108 notifyData
.hIcon
= (HICON
) icon
.GetHICON();
111 if (((const char*) tooltip
!= NULL
) && (tooltip
!= ""))
113 notifyData
.uFlags
|= NIF_TIP
;
114 lstrcpyn(notifyData
.szTip
, (char*) (const char*) tooltip
, sizeof(notifyData
.szTip
));
120 return (Shell_NotifyIcon(NIM_MODIFY
, & notifyData
) != 0);
123 m_iconAdded
= (Shell_NotifyIcon(NIM_ADD
, & notifyData
) != 0);
128 bool wxTaskBarIcon::RemoveIcon(void)
133 NOTIFYICONDATA notifyData
;
135 memset(¬ifyData
, 0, sizeof(notifyData
));
136 notifyData
.cbSize
= sizeof(notifyData
);
137 notifyData
.hWnd
= (HWND
) m_hWnd
;
138 notifyData
.uCallbackMessage
= sm_taskbarMsg
;
139 notifyData
.uFlags
= NIF_MESSAGE
;
140 notifyData
.hIcon
= 0 ; // hIcon;
144 return (Shell_NotifyIcon(NIM_DELETE
, & notifyData
) != 0);
148 void wxTaskBarIcon::OnMouseMove(wxEvent
&)
152 void wxTaskBarIcon::OnLButtonDown(wxEvent
&)
156 void wxTaskBarIcon::OnLButtonUp(wxEvent
&)
160 void wxTaskBarIcon::OnRButtonDown(wxEvent
&)
164 void wxTaskBarIcon::OnRButtonUp(wxEvent
&)
168 void wxTaskBarIcon::OnLButtonDClick(wxEvent
&)
172 void wxTaskBarIcon::OnRButtonDClick(wxEvent
&)
176 wxTaskBarIcon
* wxTaskBarIcon::FindObjectForHWND(WXHWND hWnd
)
178 wxNode
*node
= sm_taskBarIcons
.First();
181 wxTaskBarIcon
* obj
= (wxTaskBarIcon
*) node
->Data();
182 if (obj
->GetHWND() == hWnd
)
189 void wxTaskBarIcon::AddObject(wxTaskBarIcon
* obj
)
191 sm_taskBarIcons
.Append(obj
);
194 void wxTaskBarIcon::RemoveObject(wxTaskBarIcon
* obj
)
196 sm_taskBarIcons
.DeleteObject(obj
);
199 bool wxTaskBarIcon::RegisterWindowClass()
201 if (sm_registeredClass
)
204 // Also register the taskbar message here
205 sm_taskbarMsg
= ::RegisterWindowMessage("wxTaskBarIconMessage");
210 HINSTANCE hInstance
= GetModuleHandle(NULL
);
213 * set up and register window class
215 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
216 wc
.lpfnWndProc
= (WNDPROC
) wxTaskBarIconWindowProc
;
219 wc
.hInstance
= hInstance
;
222 wc
.hbrBackground
= 0;
223 wc
.lpszMenuName
= NULL
;
224 wc
.lpszClassName
= wxTaskBarWindowClass
;
225 rc
= (::RegisterClass( &wc
) != 0);
227 sm_registeredClass
= (rc
!= 0);
232 WXHWND
wxTaskBarIcon::CreateTaskBarWindow()
234 HINSTANCE hInstance
= GetModuleHandle(NULL
);
236 HWND hWnd
= CreateWindowEx (0, wxTaskBarWindowClass
,
248 return (WXHWND
) hWnd
;
251 long wxTaskBarIcon::WindowProc( WXHWND hWnd
, unsigned int msg
, unsigned int wParam
, long lParam
)
253 wxEventType eventType
= 0;
255 if (msg
!= sm_taskbarMsg
)
256 return DefWindowProc((HWND
) hWnd
, msg
, wParam
, lParam
);
261 eventType
= wxEVT_TASKBAR_LEFT_DOWN
;
265 eventType
= wxEVT_TASKBAR_LEFT_UP
;
269 eventType
= wxEVT_TASKBAR_RIGHT_DOWN
;
273 eventType
= wxEVT_TASKBAR_RIGHT_UP
;
276 case WM_LBUTTONDBLCLK
:
277 eventType
= wxEVT_TASKBAR_LEFT_DCLICK
;
280 case WM_RBUTTONDBLCLK
:
281 eventType
= wxEVT_TASKBAR_RIGHT_DCLICK
;
285 eventType
= wxEVT_TASKBAR_MOVE
;
294 event
.SetEventType(eventType
);
295 event
.SetEventObject(this);
302 LRESULT APIENTRY _EXPORT
wxTaskBarIconWindowProc( HWND hWnd
, unsigned msg
,
303 UINT wParam
, LONG lParam
)
305 wxTaskBarIcon
* obj
= wxTaskBarIcon::FindObjectForHWND((WXHWND
) hWnd
);
307 return obj
->WindowProc((WXHWND
) hWnd
, msg
, wParam
, lParam
);
309 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);