@@ -69,11 +69,6 @@ void CALLBACK MenuHandler::WinEventProc(
6969 DwmSetWindowAttribute (hWnd, DWMWA_BORDER_COLOR, &dwColorBorder, sizeof (COLORREF));
7070 }
7171 }
72- else if (MENU_REDRAW_BORDER && (!MenuManager::g_bIsDarkMode || SettingsHelper::g_redrawDarkThemeBorders10))
73- {
74- // We can't draw on non-client area right after window has showed
75- WindowHelper::SendMessageDelayed (hWnd, WM_REDRAWBORDER, 160 );
76- }
7772 }
7873 break ;
7974 }
@@ -93,6 +88,8 @@ void CALLBACK MenuHandler::WinEventProc(
9388 }
9489}
9590
91+ static constexpr int nonClientMarginSize{ 3 };
92+ static constexpr int systemOutlineSize{ 1 };
9693LRESULT CALLBACK MenuHandler::SubclassProc (
9794 HWND hWnd,
9895 UINT uMsg,
@@ -102,13 +99,66 @@ LRESULT CALLBACK MenuHandler::SubclassProc(
10299 DWORD_PTR dwRefData
103100)
104101{
102+ bool handled = false ;
103+ LRESULT result{ 0 };
104+
105105 switch (uMsg)
106106 {
107- case WM_REDRAWBORDER:
107+ #if (MENU_REDRAW_BORDER == TRUE)
108+ // /
109+ // / Windows 10 has ugly white context menu borders
110+ // / As the borders are in the non-client area,
111+ // / we can't hook the painting event and need
112+ // / to redraw them manually
113+ // /
114+ // / This is enabled only for light mode menus,
115+ // / because it is noticeable, due to low contrast
116+ // / between menu background color and original white border,
117+ // / but this is very noticeable in dark mode
118+ // /
119+ // / On Windows 11, we change borders color
120+ // / natively using DwmSetWindowAttribute API
121+ // /
122+ case WM_PRINT:
123+ {
124+ handled = true ;
125+
126+ POINT pt;
127+
128+ HDC wndDC = (HDC)wParam;
129+ SaveDC (wndDC);
130+
131+ RECT rcPaint;
132+ GetClipBox (wndDC, &rcPaint);
133+ FillRect (wndDC, &rcPaint, GetStockBrush (BLACK_BRUSH));
134+
135+ SetViewportOrgEx (wndDC, nonClientMarginSize, nonClientMarginSize, &pt);
136+ result = DefSubclassProc (hWnd, WM_PRINTCLIENT, wParam, lParam);
137+
138+ SetViewportOrgEx (wndDC, pt.x , pt.y , nullptr );
139+
140+ RestoreDC (wndDC, -1 );
141+ }
142+ break ;
143+ case WM_NCPAINT:
108144 {
109- WindowHelper::RedrawMenuBorder (hWnd);
145+ handled = true ;
146+
147+ HDC wndDC = GetWindowDC (hWnd);
148+
149+ if (wParam != NULLREGION && wParam != ERROR)
150+ {
151+ SelectClipRgn (wndDC, reinterpret_cast <HRGN>(wParam));
152+ }
153+
154+ RECT rcPaint;
155+ GetClipBox (wndDC, &rcPaint);
156+ FillRect (wndDC, &rcPaint, GetStockBrush (BLACK_BRUSH));
157+
158+ ReleaseDC (hWnd, wndDC);
110159 }
111160 break ;
161+ #endif
112162 case MN_BUTTONUP:
113163 {
114164 // We need to prevent the system default menu fade out animation
@@ -163,5 +213,10 @@ LRESULT CALLBACK MenuHandler::SubclassProc(
163213 break ;
164214 }
165215
166- return DefSubclassProc (hWnd, uMsg, wParam, lParam);
216+ if (!handled)
217+ {
218+ result = DefSubclassProc (hWnd, uMsg, wParam, lParam);
219+ }
220+
221+ return result;
167222}
0 commit comments