1

I've implemented a WindowProc in which I handle the WM_NCPAINT message, but I can't get the result I want. As I only want to add a colored rectangle the width of the window at the bottom of the title bar, I first let defWindowProc handle the message and then proceed to (try to) draw over that.

In my first attempt I got a dc from GetWindowDC. Although my code was executed, the result was not visible.

In my second attempt I got a dc by calling GetDCEx (I'm using a region created from the windowRect) and passing DCX_WINDOW | DCX_INTERSECTRGN | DCX_LOCKWINDOWUPDATE as the flags (without DCX_LOCKWINDOWUPDATE GetDCEx returns null). The visual result however, is the same as in my first attempt: completely invisible.

In both instances I've (temporarily) attempted to paint the entire frame red:

RECT windowRect;
::GetWindowRect( hwnd, & windowRect );

HBRUSH hbrush = ::CreateSolidBrush(RGB(255, 0, 0));
FillRect( hdc, &windowRect, hbrush );
::DeleteObject(hbrush);
::ReleaseDC(hwnd, hdc);

Can someone point me to what I'm doing wrong? Forgot to mention: I'm working in Windows 10.

gvanvoor
  • 11
  • 2
  • Can this link [Draw a custom text on title bar using DWM](https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/2cefdb26-094c-43cd-917a-97b6922916a1/draw-a-custom-text-on-title-bar-using-dwm?forum=windowsgeneraldevelopmentissues) help you ? – YangXiaoPo-MSFT Jun 03 '21 at 07:27
  • @YangXiaoPo Unfortunately not: that creates a whole custom frame while I want to keep the default window frame (which in windows 10 is basically frameless on the sides) – gvanvoor Jun 03 '21 at 09:15
  • How about [How to correctly draw simple non-client area (4 px red border)?](https://stackoverflow.com/questions/50132757/how-to-correctly-draw-simple-non-client-area-4-px-red-border) and [Can't draw in title bar on WM_NCPAINT?](https://stackoverflow.com/questions/61885460/cant-draw-in-title-bar-on-wm-ncpaint). – YangXiaoPo-MSFT Jun 04 '21 at 01:59
  • @YangXiaoPo I tried that and it doesn't work. Either I call defWindowProc and my drawing has no effect, or I don't and then windows 7 style borders appear. – gvanvoor Jun 04 '21 at 06:28
  • You can refer to [Draw in the nonclient area with Direct2D](https://stackoverflow.com/questions/58605718/draw-in-the-nonclient-area-with-direct2d) which explains why you should use DWM and includes a GitHub project. – YangXiaoPo-MSFT Jun 08 '21 at 07:13
  • @YangXiaoPo Unless I'm missing something that page contains a link to the "Draw a custom text on title bar using DWM" from your first answer but nothing more useful. – gvanvoor Jun 08 '21 at 11:45
  • Changing based on [https://github.com/oberth/custom-chrome](https://github.com/oberth/custom-chrome) works for you. – YangXiaoPo-MSFT Jun 09 '21 at 01:25

0 Answers0