ReactOS 0.4.15-dev-8434-g155a7c7
CTrayShowDesktopButton Class Reference

#include <traydeskbtn.h>

Inheritance diagram for CTrayShowDesktopButton:
Collaboration diagram for CTrayShowDesktopButton:

Public Member Functions

 CTrayShowDesktopButton ()
 
INT WidthOrHeight () const
 
HRESULT DoCreate (HWND hwndParent)
 
VOID Click ()
 
BOOL PtInButton (LPPOINT pt) const
 
VOID StartHovering ()
 
LRESULT OnLButtonUp (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnLButtonDown (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 

Public Attributes

BOOL m_bPressed
 
BOOL m_bHorizontal
 

Private Member Functions

VOID OnDraw (HDC hdc, LPRECT prc)
 
LRESULT OnClick (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnSettingChanged (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnThemeChanged (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnWindowPosChanged (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
VOID EnsureWindowTheme (BOOL setTheme)
 
LRESULT OnPaint (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnPrintClient (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnMouseMove (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnTimer (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 
LRESULT OnDestroy (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 

Private Attributes

LONG m_nClickedTime
 
HTHEME m_hTheme
 
HTHEME m_hFallbackTheme
 
MARGINS m_ContentMargins
 
SIZE m_inset
 
HICON m_icon
 
SIZE m_szIcon
 
BOOL m_highContrastMode
 
BOOL m_drawWithDedicatedBackground
 
BOOL m_bHovering
 
HWND m_hWndTaskbar
 

Detailed Description

Definition at line 17 of file traydeskbtn.h.

Constructor & Destructor Documentation

◆ CTrayShowDesktopButton()

CTrayShowDesktopButton::CTrayShowDesktopButton ( )

Member Function Documentation

◆ Click()

VOID CTrayShowDesktopButton::Click ( )

Definition at line 106 of file traydeskbtn.cpp.

107{
108 // The actual action can be delayed as an expected behaviour.
110 PostMessage(TSDB_CLICK, 0, 0);
111}
#define TSDB_CLICK
Definition: traydeskbtn.h:14
LONG WINAPI GetMessageTime(void)
Definition: message.c:1361
#define PostMessage
Definition: winuser.h:5841

Referenced by OnLButtonUp(), and CTrayWindow::OnNcLButtonUp().

◆ DoCreate()

HRESULT CTrayShowDesktopButton::DoCreate ( HWND  hwndParent)

Definition at line 62 of file traydeskbtn.cpp.

63{
66
67 if (!m_hWnd)
68 return E_FAIL;
69
70 // Get desktop icon
71 bool bIconRetrievalFailed = ExtractIconExW(L"imageres.dll", -IDI_IMAGERES_DESKTOP, NULL, &m_icon, 1) == UINT_MAX;
72 if (bIconRetrievalFailed || !m_icon)
73 ExtractIconExW(L"shell32.dll", -IDI_SHELL32_DESKTOP, NULL, &m_icon, 1);
74
75 // Get appropriate size at which to display desktop icon
78
79 // Prep visual style
81
82 // Get HWND of Taskbar
85 return E_FAIL;
86
87 return S_OK;
88}
Arabic default style
Definition: afstyles.h:94
@ Create
Definition: registry.c:563
VOID EnsureWindowTheme(BOOL setTheme)
static HWND hwndParent
Definition: cryptui.c:300
#define E_FAIL
Definition: ddrawi.h:102
#define TRUE
Definition: types.h:120
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:849
#define UINT_MAX
Definition: limits.h:41
#define S_OK
Definition: intsafe.h:52
#define L(x)
Definition: ntvdm.h:50
#define WS_CHILD
Definition: pedump.c:617
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define BS_DEFPUSHBUTTON
Definition: pedump.c:652
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
#define IDI_SHELL32_DESKTOP
Definition: traydeskbtn.cpp:14
#define IDI_IMAGERES_DESKTOP
Definition: traydeskbtn.cpp:15
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define SM_CYSMICON
Definition: winuser.h:1013
#define SM_CXSMICON
Definition: winuser.h:1012
HWND WINAPI GetParent(_In_ HWND)
int WINAPI GetSystemMetrics(_In_ int)

Referenced by CTrayNotifyWnd::OnCreate().

◆ EnsureWindowTheme()

VOID CTrayShowDesktopButton::EnsureWindowTheme ( BOOL  setTheme)
private

Definition at line 171 of file traydeskbtn.cpp.

172{
173 if (setTheme)
174 SetWindowTheme(m_hWnd, m_bHorizontal ? L"ShowDesktop" : L"VerticalShowDesktop", NULL);
175
177 {
180 }
181 else
182 {
184 }
185
186 MARGINS contentMargins;
187 if (GetThemeMargins(GetWindowTheme(GetParent().m_hWnd), NULL, TNP_BACKGROUND, 0, TMT_CONTENTMARGINS, NULL, &contentMargins) == S_OK)
188 {
189 m_inset.cx = max(0, contentMargins.cxRightWidth - 5);
190 m_inset.cy = max(0, contentMargins.cyBottomHeight - 5);
191 }
192 else
193 {
194 m_inset.cx = 2;
195 m_inset.cy = 2;
196 }
197
199 if (IsThemeActive())
200 {
201 m_hTheme = OpenThemeData(m_hWnd, L"Button");
202 if (m_hTheme != NULL)
204 }
205}
HRESULT WINAPI GetThemeMargins(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, RECT *prc, MARGINS *pMargins)
Definition: property.c:216
HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
Definition: system.c:835
BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
Definition: system.c:987
HTHEME WINAPI GetWindowTheme(HWND hwnd)
Definition: system.c:851
BOOL WINAPI IsThemeActive(void)
Definition: system.c:606
Definition: misc.c:279
int cyBottomHeight
Definition: misc.c:283
int cxRightWidth
Definition: misc.c:281
#define max(a, b)
Definition: svc.c:63
HRESULT WINAPI SetWindowTheme(_In_ HWND hwnd, _In_ LPCWSTR pszSubAppName, _In_ LPCWSTR pszSubIdList)
Definition: uxthemesupp.c:69
@ TP_BUTTON
Definition: vsstyle.h:1394
@ BP_PUSHBUTTON
Definition: vsstyle.h:74
#define TMT_CONTENTMARGINS
Definition: vssym32.h:324
@ TNP_BACKGROUND
Definition: vssym32.h:543

Referenced by DoCreate(), OnSettingChanged(), OnThemeChanged(), and OnWindowPosChanged().

◆ OnClick()

LRESULT CTrayShowDesktopButton::OnClick ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 90 of file traydeskbtn.cpp.

91{
92 // The actual action can be delayed as an expected behaviour.
93 // But a too late action is an unexpected behaviour.
94 LONG nTime0 = m_nClickedTime;
95 LONG nTime1 = ::GetMessageTime();
96 if (nTime1 - nTime0 >= 600) // Ignore after 0.6 sec
97 return 0;
98
99 // Show/Hide Desktop
101
102 return 0;
103}
long LONG
Definition: pedump.c:60
#define TRAYCMD_TOGGLE_DESKTOP
Definition: undocshell.h:850
#define WM_COMMAND
Definition: winuser.h:1740
#define SendMessage
Definition: winuser.h:5852

◆ OnDestroy()

LRESULT CTrayShowDesktopButton::OnDestroy ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 287 of file traydeskbtn.cpp.

288{
289 if (m_hTheme)
290 {
292 m_hTheme = NULL;
293 }
295 {
298 }
299
300 return 0;
301}
HRESULT WINAPI CloseThemeData(HTHEME hTheme)
Definition: system.c:950

◆ OnDraw()

VOID CTrayShowDesktopButton::OnDraw ( HDC  hdc,
LPRECT  prc 
)
private

Definition at line 303 of file traydeskbtn.cpp.

304{
305 RECT rc = { prc->left, prc->top, prc->right, prc->bottom };
306 LPRECT lpRc = &rc;
307 HBRUSH hbrBackground = NULL;
308
309 if (m_hTheme)
310 {
311 HTHEME theme;
312 int part = 0;
313 int state = 0;
315 {
316 theme = m_hTheme;
317
318 if (m_bPressed)
320 else if (m_bHovering)
321 state = PBS_HOT;
322 else
324 }
325 else
326 {
327 part = TP_BUTTON;
328 theme = m_hFallbackTheme;
329
330 if (m_bPressed)
332 else if (m_bHovering)
333 state = TS_HOT;
334 else
336
337 if (m_bHorizontal)
338 rc.right -= m_inset.cx;
339 else
340 rc.bottom -= m_inset.cy;
341 }
342
345
346 ::DrawThemeBackground(theme, hdc, part, state, lpRc, lpRc);
347 }
348 else
349 {
352
353 if (m_bPressed || m_bHovering)
354 {
356 DrawEdge(hdc, lpRc, edge, BF_RECT);
357 }
358 }
359
361 {
362 /* Prepare to draw icon */
363
364 // Determine X-position of icon's top-left corner
365 int iconX = rc.left;
366 iconX += (rc.right - iconX) / 2;
367 iconX -= m_szIcon.cx / 2;
368
369 // Determine Y-position of icon's top-left corner
370 int iconY = rc.top;
371 iconY += (rc.bottom - iconY) / 2;
372 iconY -= m_szIcon.cy / 2;
373
374 // Ok now actually draw the icon itself
375 if (m_icon)
376 {
377 DrawIconEx(hdc, iconX, iconY,
378 m_icon, 0, 0,
380 }
381 }
382}
static int state
Definition: maze.c:121
HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect)
Definition: draw.c:128
BOOL WINAPI IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId)
Definition: draw.c:1883
HRESULT WINAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT *prc)
Definition: draw.c:72
HBRUSH hbrBackground
Definition: enumwnd.c:12
HDC hdc
Definition: main.c:9
static HTHEME(WINAPI *pOpenThemeDataEx)(HWND
unsigned int UINT
Definition: ndis.h:50
_Out_ LPRECT prc
Definition: ntgdi.h:1658
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
@ PBS_PRESSED
Definition: vsstyle.h:88
@ PBS_NORMAL
Definition: vsstyle.h:86
@ PBS_HOT
Definition: vsstyle.h:87
@ TS_PRESSED
Definition: vsstyle.h:1407
@ TS_NORMAL
Definition: vsstyle.h:1405
@ TS_HOT
Definition: vsstyle.h:1406
#define DI_NORMAL
Definition: wingdi.h:72
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define BDR_SUNKENOUTER
Definition: winuser.h:443
HBRUSH WINAPI GetSysColorBrush(_In_ int)
BOOL WINAPI DrawEdge(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
BOOL WINAPI DrawIconEx(_In_ HDC, _In_ int, _In_ int, _In_ HICON, _In_ int, _In_ int, _In_ UINT, _In_opt_ HBRUSH, _In_ UINT)
Definition: cursoricon.c:2072
#define BDR_RAISEDINNER
Definition: winuser.h:444
#define BF_RECT
Definition: winuser.h:462
#define COLOR_3DFACE
Definition: winuser.h:929

Referenced by OnPaint(), and OnPrintClient().

◆ OnLButtonDown()

LRESULT CTrayShowDesktopButton::OnLButtonDown ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)

Definition at line 126 of file traydeskbtn.cpp.

127{
129 SetCapture();
130 Invalidate(TRUE);
131 return 0;
132}
HWND WINAPI SetCapture(_In_ HWND hWnd)

Referenced by CTrayWindow::OnNcLButtonDown().

◆ OnLButtonUp()

LRESULT CTrayShowDesktopButton::OnLButtonUp ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)

Definition at line 113 of file traydeskbtn.cpp.

114{
117 Invalidate(TRUE);
118
119 POINT pt;
121 if (PtInButton(&pt))
122 Click(); // Left-click
123 return 0;
124}
BOOL PtInButton(LPPOINT pt) const
#define pt(x, y)
Definition: drawing.c:79
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2714

Referenced by CTrayWindow::OnLButtonUp(), and CTrayWindow::OnNcLButtonUp().

◆ OnMouseMove()

LRESULT CTrayShowDesktopButton::OnMouseMove ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 262 of file traydeskbtn.cpp.

263{
265 return 0;
266}

◆ OnPaint()

LRESULT CTrayShowDesktopButton::OnPaint ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 207 of file traydeskbtn.cpp.

208{
209 RECT rc;
210 GetClientRect(&rc);
211
212 PAINTSTRUCT ps;
213 HDC hdc = BeginPaint(&ps);
214 OnDraw(hdc, &rc);
215 EndPaint(&ps);
216
217 return 0;
218}
VOID OnDraw(HDC hdc, LPRECT prc)
static HDC
Definition: imagelist.c:92
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)

◆ OnPrintClient()

LRESULT CTrayShowDesktopButton::OnPrintClient ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 220 of file traydeskbtn.cpp.

221{
223 return 0;
224
225 RECT rc;
226 GetClientRect(&rc);
227
228 HDC hdc = (HDC)wParam;
229 OnDraw(hdc, &rc);
230
231 return 0;
232}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define PRF_CHECKVISIBLE
Definition: winuser.h:2523
BOOL WINAPI IsWindowVisible(_In_ HWND)

◆ OnSettingChanged()

LRESULT CTrayShowDesktopButton::OnSettingChanged ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 134 of file traydeskbtn.cpp.

135{
136 LRESULT ret = OnThemeChanged(uMsg, wParam, lParam, bHandled);
138 return ret;
139}
LRESULT OnThemeChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
int ret
LONG_PTR LRESULT
Definition: windef.h:209

◆ OnThemeChanged()

LRESULT CTrayShowDesktopButton::OnThemeChanged ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 141 of file traydeskbtn.cpp.

142{
143 HIGHCONTRAST hcInfo;
144 hcInfo.cbSize = sizeof(hcInfo);
145 if (SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hcInfo), &hcInfo, FALSE))
147
148 if (m_hTheme)
149 {
151 m_hTheme = NULL;
152 }
154 {
157 }
158
160
161 Invalidate(TRUE);
162 return 0;
163}
#define HCF_HIGHCONTRASTON
Definition: winuser.h:2134
#define SystemParametersInfo
Definition: winuser.h:5867

Referenced by OnSettingChanged().

◆ OnTimer()

LRESULT CTrayShowDesktopButton::OnTimer ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 268 of file traydeskbtn.cpp.

269{
271 return 0;
272
273 POINT pt;
275 if (!PtInButton(&pt)) // The end of hovering?
276 {
279 Invalidate(TRUE);
280
282 }
283
284 return 0;
285}
#define SHOW_DESKTOP_TIMER_ID
Definition: traydeskbtn.cpp:17
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define WM_NCPAINT
Definition: winuser.h:1687

◆ OnWindowPosChanged()

LRESULT CTrayShowDesktopButton::OnWindowPosChanged ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
BOOL bHandled 
)
private

Definition at line 165 of file traydeskbtn.cpp.

166{
168 return 0;
169}

◆ PtInButton()

BOOL CTrayShowDesktopButton::PtInButton ( LPPOINT  pt) const

Definition at line 234 of file traydeskbtn.cpp.

235{
236 if (!ppt || !IsWindow())
237 return FALSE;
238
239 RECT rc;
240 GetWindowRect(&rc);
242 ::InflateRect(&rc, max(cxEdge, 1), max(cyEdge, 1));
243
244 return m_bHorizontal
245 ? (ppt->x > rc.left)
246 : (ppt->y > rc.top);
247}
int32_t INT
Definition: typedefs.h:58
#define SM_CYEDGE
Definition: winuser.h:1009
#define SM_CXEDGE
Definition: winuser.h:1008
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)

Referenced by OnLButtonUp(), CTrayNotifyWnd::OnMouseMove(), CTrayNotifyWnd::OnNcHitTest(), CTrayWindow::OnNcHitTest(), CTrayWindow::OnNcLButtonDown(), and OnTimer().

◆ StartHovering()

VOID CTrayShowDesktopButton::StartHovering ( )

Definition at line 249 of file traydeskbtn.cpp.

250{
251 if (m_bHovering)
252 return;
253
255 Invalidate(TRUE);
256
258
260}
#define SHOW_DESKTOP_TIMER_INTERVAL
Definition: traydeskbtn.cpp:18
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)

Referenced by OnMouseMove(), and CTrayNotifyWnd::OnMouseMove().

◆ WidthOrHeight()

INT CTrayShowDesktopButton::WidthOrHeight ( ) const

Definition at line 33 of file traydeskbtn.cpp.

34{
36 {
38 {
39 if (GetSystemMetrics(SM_TABLETPC))
40 {
41 //TODO: DPI scaling - return logical-to-physical conversion of 24, not fixed value
42 return 24;
43 }
44 else
45 return 15;
46 }
47 else
48 {
49 INT CurMargin = m_bHorizontal
52 return max(16 + CurMargin, 18) + 6;
53 }
54 }
55 else
56 {
59 }
60}
int cyTopHeight
Definition: misc.c:282
int cxLeftWidth
Definition: misc.c:280
#define SM_CYBORDER
Definition: winuser.h:965
#define SM_CXBORDER
Definition: winuser.h:964

Referenced by CTrayNotifyWnd::AlignControls(), and CTrayNotifyWnd::GetMinimumSize().

Member Data Documentation

◆ m_bHorizontal

BOOL CTrayShowDesktopButton::m_bHorizontal

◆ m_bHovering

BOOL CTrayShowDesktopButton::m_bHovering
private

Definition at line 29 of file traydeskbtn.h.

Referenced by OnDraw(), OnTimer(), and StartHovering().

◆ m_bPressed

BOOL CTrayShowDesktopButton::m_bPressed

Definition at line 33 of file traydeskbtn.h.

Referenced by OnDraw(), OnLButtonDown(), OnLButtonUp(), and CTrayWindow::OnNcLButtonUp().

◆ m_ContentMargins

MARGINS CTrayShowDesktopButton::m_ContentMargins
private

Definition at line 23 of file traydeskbtn.h.

Referenced by EnsureWindowTheme(), and WidthOrHeight().

◆ m_drawWithDedicatedBackground

BOOL CTrayShowDesktopButton::m_drawWithDedicatedBackground
private

Definition at line 28 of file traydeskbtn.h.

Referenced by EnsureWindowTheme(), OnDraw(), and WidthOrHeight().

◆ m_hFallbackTheme

HTHEME CTrayShowDesktopButton::m_hFallbackTheme
private

Definition at line 22 of file traydeskbtn.h.

Referenced by EnsureWindowTheme(), OnDestroy(), OnDraw(), and OnThemeChanged().

◆ m_highContrastMode

BOOL CTrayShowDesktopButton::m_highContrastMode
private

Definition at line 27 of file traydeskbtn.h.

Referenced by OnDraw(), OnThemeChanged(), and WidthOrHeight().

◆ m_hTheme

HTHEME CTrayShowDesktopButton::m_hTheme
private

Definition at line 21 of file traydeskbtn.h.

Referenced by EnsureWindowTheme(), OnDestroy(), OnDraw(), and OnThemeChanged().

◆ m_hWndTaskbar

HWND CTrayShowDesktopButton::m_hWndTaskbar
private

Definition at line 30 of file traydeskbtn.h.

Referenced by DoCreate(), EnsureWindowTheme(), OnClick(), OnTimer(), and StartHovering().

◆ m_icon

HICON CTrayShowDesktopButton::m_icon
private

Definition at line 25 of file traydeskbtn.h.

Referenced by DoCreate(), and OnDraw().

◆ m_inset

SIZE CTrayShowDesktopButton::m_inset
private

Definition at line 24 of file traydeskbtn.h.

Referenced by EnsureWindowTheme(), and OnDraw().

◆ m_nClickedTime

LONG CTrayShowDesktopButton::m_nClickedTime
private

Definition at line 20 of file traydeskbtn.h.

Referenced by Click(), and OnClick().

◆ m_szIcon

SIZE CTrayShowDesktopButton::m_szIcon
private

Definition at line 26 of file traydeskbtn.h.

Referenced by DoCreate(), and OnDraw().


The documentation for this class was generated from the following files: