1919#include < shdeprecated.h>
2020#include < propkey.h>
2121#include < algorithm>
22+ #include < uxtheme.h>
2223
2324// /////////////////////////////////////////////////////////////////////////////
2425
@@ -229,6 +230,17 @@ LRESULT CALLBACK CBandWindow::ToolbarSubclassProc( HWND hWnd, UINT uMsg, WPARAM
229230 // Also refresh the buttons when the folder settings change
230231 if (pThis->HasFolderSettings ())
231232 ::PostMessage ((HWND )dwRefData,CBandWindow::BWM_UPDATETOOLBAR,0,0);
233+
234+ if (IsColorSchemeChangeMessage (lParam))
235+ {
236+ HWND tooltips=(HWND )::SendMessage (pThis->GetToolbar (),TB_GETTOOLTIPS ,0 ,0 );
237+ if (tooltips)
238+ SetWindowTheme (tooltips,ShouldAppsUseDarkMode ()?L" DarkMode_Explorer" :NULL ,NULL );
239+
240+ HWND rebar=::GetParent ((HWND )dwRefData);
241+ if (rebar)
242+ ::RedrawWindow (rebar,NULL ,NULL ,RDW_INVALIDATE |RDW_ERASE |RDW_FRAME |RDW_ALLCHILDREN );
243+ }
232244 }
233245 if (uMsg==WM_PAINT )
234246 {
@@ -239,8 +251,149 @@ LRESULT CALLBACK CBandWindow::ToolbarSubclassProc( HWND hWnd, UINT uMsg, WPARAM
239251 return DefSubclassProc (hWnd,uMsg,wParam,lParam);
240252}
241253
254+ // Custom-draw the Classic Explorer toolbar on Windows 10+ so it follows the
255+ // Windows application theme. Keeping this on the band window preserves the
256+ // existing toolbar message handling and right-click behavior.
257+ LRESULT CALLBACK CBandWindow::BandSubclassProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData )
258+ {
259+ CBandWindow *pThis=(CBandWindow*)uIdSubclass;
260+ if (uMsg!=WM_NOTIFY || !lParam || !pThis || GetWinVersion ()<WIN_VER_WIN10 )
261+ return DefSubclassProc (hWnd,uMsg,wParam,lParam);
262+
263+ LPNMHDR header=(LPNMHDR )lParam;
264+ if (header->hwndFrom !=pThis->GetToolbar () || header->code !=NM_CUSTOMDRAW )
265+ return DefSubclassProc (hWnd,uMsg,wParam,lParam);
266+
267+ LPNMTBCUSTOMDRAW draw=(LPNMTBCUSTOMDRAW )lParam;
268+ DWORD stage=draw->nmcd .dwDrawStage ;
269+ if (!ShouldAppsUseDarkMode ())
270+ return DefSubclassProc (hWnd,uMsg,wParam,lParam);
271+
272+ if (stage==CDDS_PREPAINT )
273+ {
274+ FillRect (draw->nmcd .hdc ,&draw->nmcd .rc ,pThis->m_DarkBackgroundBrush );
275+ return CDRF_DODEFAULT |CDRF_NOTIFYITEMDRAW ;
276+ }
277+
278+ if (stage==CDDS_ITEMPREPAINT )
279+ {
280+ TBBUTTONINFO info={sizeof (info),TBIF_STYLE |TBIF_STATE |TBIF_IMAGE };
281+ if (::SendMessage (pThis->GetToolbar (),TB_GETBUTTONINFO ,(WPARAM )draw->nmcd .dwItemSpec ,(LPARAM )&info)==-1 )
282+ return CDRF_DODEFAULT ;
283+
284+ bool dropDown=(info.fsStyle &(BTNS_DROPDOWN |BTNS_WHOLEDROPDOWN ))!=0 ;
285+ bool checked=(info.fsState &TBSTATE_CHECKED )!=0 ;
286+
287+ // Checked toolbar buttons need explicit rendering. The standard toolbar
288+ // theme otherwise paints a light checked background in dark mode.
289+ if (checked && !dropDown && info.iImage !=I_IMAGENONE )
290+ {
291+ size_t itemIndex=(size_t )draw->nmcd .lItemlParam ;
292+ HIMAGELIST images=(HIMAGELIST )::SendMessage (header->hwndFrom ,TB_GETIMAGELIST ,0 ,0 );
293+ if (images && itemIndex<pThis->m_Items .size ())
294+ {
295+ const wchar_t *label=pThis->m_Items [itemIndex].label ;
296+ int iconSize=GetSettingInt (GetSettingBool (L" UseBigButtons" )?L" LargeIconSize" :L" SmallIconSize" );
297+ SIZE textSize={};
298+ RECT itemRect=draw->nmcd .rc ;
299+ RECT paintRect=itemRect;
300+ paintRect.right ++;
301+ HDC hdc=draw->nmcd .hdc ;
302+
303+ int saved=SaveDC (hdc);
304+ HBRUSH brush=(HBRUSH )GetStockObject (DC_BRUSH );
305+ SetDCBrushColor (hdc,RGB (0x4D ,0x4D ,0x4D ));
306+ HRGN background=CreateRoundRectRgn (paintRect.left ,paintRect.top ,paintRect.right ,paintRect.bottom ,4 ,4 );
307+ if (background)
308+ {
309+ FillRgn (hdc,background,brush);
310+ SetDCBrushColor (hdc,RGB (0x63 ,0x63 ,0x63 ));
311+ FrameRgn (hdc,background,brush,1 ,1 );
312+ }
313+
314+ if (label)
315+ {
316+ SetBkMode (hdc,TRANSPARENT );
317+ SetTextColor (hdc,RGB (0xFF ,0xFF ,0xFF ));
318+ SelectObject (hdc,(HGDIOBJ )::SendMessage (header->hwndFrom ,WM_GETFONT ,0 ,0 ));
319+ GetTextExtentPoint32 (hdc,L" T" ,1 ,&textSize);
320+ }
321+
322+ if (!GetSettingBool (L" ToolbarListMode" ))
323+ {
324+ int iconY=itemRect.top +((itemRect.bottom -itemRect.top )/2 -(iconSize+(label?textSize.cy :0 ))/2 )+1 -(label?2 :0 );
325+ ImageList_Draw (images,info.iImage ,hdc,itemRect.left +((itemRect.right -itemRect.left )/2 -iconSize/2 )+1 ,iconY,ILD_NORMAL );
326+ if (label)
327+ {
328+ RECT textRect=itemRect;
329+ textRect.left ++;
330+ textRect.top =iconY+iconSize+1 ;
331+ DrawText (hdc,label,-1 ,&textRect,DT_SINGLELINE |DT_TOP |DT_CENTER );
332+ }
333+ }
334+ else
335+ {
336+ int iconX=itemRect.left +(label?4 :5 );
337+ ImageList_Draw (images,info.iImage ,hdc,iconX,itemRect.top +((itemRect.bottom -itemRect.top )/2 -iconSize/2 )+1 ,ILD_NORMAL );
338+ if (label)
339+ {
340+ RECT textRect=itemRect;
341+ textRect.left =iconX+iconSize+4 ;
342+ textRect.top +=(textRect.bottom -textRect.top )/2 -textSize.cy /2 ;
343+ DrawText (hdc,label,-1 ,&textRect,DT_SINGLELINE |DT_TOP |DT_LEFT );
344+ }
345+ }
346+
347+ if (background)
348+ DeleteObject (background);
349+ RestoreDC (hdc,saved);
350+ return CDRF_SKIPDEFAULT ;
351+ }
352+ }
353+
354+ draw->clrText =RGB (0xFF ,0xFF ,0xFF );
355+ UINT flags=CDRF_DODEFAULT |TBCDRF_USECDCOLORS ;
356+ if (dropDown)
357+ flags|=CDRF_NOTIFYPOSTPAINT ;
358+ else
359+ {
360+ draw->clrHighlightHotTrack =RGB (0x47 ,0x47 ,0x47 );
361+ flags|=TBCDRF_HILITEHOTTRACK ;
362+ }
363+ return flags;
364+ }
365+
366+ if (stage==CDDS_ITEMPOSTPAINT )
367+ {
368+ RECT rc=draw->nmcd .rc ;
369+ UINT dpi=GetDpi (hWnd);
370+ int triangleLeft=rc.right -(dpi>USER_DEFAULT_SCREEN_DPI ?ScaleForDpi (hWnd,10 ):9 );
371+ int triangleTop=(rc.bottom -rc.top )/2 +MulDiv (2 ,USER_DEFAULT_SCREEN_DPI ,dpi);
372+ int width=ScaleForDpi (hWnd,6 );
373+ width-=width%2 ;
374+ POINT vertices[]={{triangleLeft,triangleTop},{triangleLeft+width,triangleTop},{triangleLeft+width/2 ,triangleTop+width/2 }};
375+
376+ int saved=SaveDC (draw->nmcd .hdc );
377+ SetDCPenColor (draw->nmcd .hdc ,RGB (0xDE ,0xDE ,0xDE ));
378+ SetDCBrushColor (draw->nmcd .hdc ,RGB (0xDE ,0xDE ,0xDE ));
379+ SelectObject (draw->nmcd .hdc ,GetStockObject (DC_PEN ));
380+ SelectObject (draw->nmcd .hdc ,GetStockObject (DC_BRUSH ));
381+ Polygon (draw->nmcd .hdc ,vertices,_countof (vertices));
382+ RestoreDC (draw->nmcd .hdc ,saved);
383+ return CDRF_DODEFAULT ;
384+ }
385+
386+ return CDRF_DODEFAULT ;
387+ }
388+
242389LRESULT CBandWindow::OnCreate ( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled )
243390{
391+ if (GetWinVersion ()>=WIN_VER_WIN10 )
392+ {
393+ m_DarkBackgroundBrush=CreateSolidBrush (RGB (0x19 ,0x19 ,0x19 ));
394+ m_DarkBorderBrush=CreateSolidBrush (RGB (0x3A ,0x3A ,0x3A ));
395+ }
396+
244397 ParseToolbar ();
245398
246399 bool bLabels=false ;
@@ -261,6 +414,14 @@ LRESULT CBandWindow::OnCreate( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
261414 m_Toolbar.SendMessage (TB_SETMAXTEXTROWS ,1 );
262415 SetWindowSubclass (m_Toolbar,ToolbarSubclassProc,(UINT_PTR )this ,(DWORD_PTR )m_hWnd);
263416
417+ if (GetWinVersion ()>=WIN_VER_WIN10 )
418+ {
419+ SetWindowSubclass (m_hWnd,BandSubclassProc,(UINT_PTR )this ,(DWORD_PTR )m_hWnd);
420+ HWND tooltips=(HWND )m_Toolbar.SendMessage (TB_GETTOOLTIPS ,0 ,0 );
421+ if (tooltips && ShouldAppsUseDarkMode ())
422+ SetWindowTheme (tooltips,L" DarkMode_Explorer" ,NULL );
423+ }
424+
264425 int iconSize=GetSettingInt (GetSettingBool (L" UseBigButtons" )?L" LargeIconSize" :L" SmallIconSize" );
265426 if (iconSize<8 ) iconSize=8 ;
266427 else if (iconSize>128 ) iconSize=128 ;
@@ -397,6 +558,20 @@ LRESULT CBandWindow::OnDestroy( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& b
397558 if (it->menuIconD ) DeleteObject (it->menuIconD );
398559 }
399560 m_Items.clear ();
561+
562+ if (GetWinVersion ()>=WIN_VER_WIN10 )
563+ RemoveWindowSubclass (m_hWnd,BandSubclassProc,(UINT_PTR )this );
564+ if (m_DarkBackgroundBrush)
565+ {
566+ DeleteObject (m_DarkBackgroundBrush);
567+ m_DarkBackgroundBrush=NULL ;
568+ }
569+ if (m_DarkBorderBrush)
570+ {
571+ DeleteObject (m_DarkBorderBrush);
572+ m_DarkBorderBrush=NULL ;
573+ }
574+
400575 bHandled=FALSE ;
401576 return 0 ;
402577}
@@ -2031,6 +2206,34 @@ LRESULT CALLBACK CExplorerBand::RebarSubclassProc( HWND hWnd, UINT uMsg, WPARAM
20312206 }
20322207 }
20332208
2209+ if (GetWinVersion ()>=WIN_VER_WIN10 && ShouldAppsUseDarkMode ())
2210+ {
2211+ CExplorerBand *pThis=(CExplorerBand*)uIdSubclass;
2212+ if (uMsg==WM_ERASEBKGND )
2213+ {
2214+ HDC hdc=(HDC )wParam;
2215+ RECT rc;
2216+ if (GetClipBox (hdc,&rc)!=ERROR )
2217+ FillRect (hdc,&rc,pThis->m_BandWindow .GetDarkBackgroundBrush ());
2218+ return 1 ;
2219+ }
2220+ if (uMsg==WM_NCPAINT )
2221+ {
2222+ LRESULT result=DefSubclassProc (hWnd,uMsg,wParam,lParam);
2223+ HDC hdc=GetWindowDC (hWnd);
2224+ if (hdc)
2225+ {
2226+ RECT rc;
2227+ GetWindowRect (hWnd,&rc);
2228+ OffsetRect (&rc,-rc.left ,-rc.top );
2229+ rc.top =rc.bottom -1 ;
2230+ FillRect (hdc,&rc,pThis->m_BandWindow .GetDarkBorderBrush ());
2231+ ReleaseDC (hWnd,hdc);
2232+ }
2233+ return result;
2234+ }
2235+ }
2236+
20342237 return DefSubclassProc (hWnd,uMsg,wParam,lParam);
20352238}
20362239
0 commit comments