holo
holo

Reputation: 331

Draw in the nonclient area with Direct2D

On this page : https://learn.microsoft.com/en-us/windows/win32/gdi/wm-ncpaint it is explained how to draw in the nonclient area with GDI.

How can I draw in the nonclient area of my window with Direct2D without having to deal with GDI or GDI+ ?

Upvotes: 1

Views: 1381

Answers (1)

Arush Agarampur
Arush Agarampur

Reputation: 1420

First of all, WM_NCPAINT is old. Using it will disable the DWM theme-ing for the window, giving a windows classic/7 basic look. So don't do it.

But to use any rendering API do draw in the client area, remove the standard window frame from the window by returning 0 when wParam is true in your WM_NCCALCSIZE message.

case WM_NCCALCSIZE:
    if (static_cast<bool>(wParam))
           return 0;
    return DefWindowProc(hwnd, msg, wParam, lParam);

If you want to keep the standard borders, recalculate the window bounds in WM_NCCALCSIZE.

Then to get a "client area" title bar, use DwmExtendFrameIntoClientArea and extend it from the TOP.

Make sure to handle WM_NCHITTEST so that dragging your window will work too.

Make sure to premultiply your ALPHA in direct2d. Drawing a rectangle at (0,0) will draw a rectangle in the titlebar of your new custom window.

SEE: https://github.com/oberth/custom-chrome

Upvotes: 2

Related Questions