简体   繁体   English

使用 Direct2D 在非客户区绘图

[英]Draw in the nonclient area with Direct2D

On this page: https://docs.microsoft.com/en-us/windows/win32/gdi/wm-ncpaint it is explained how to draw in the nonclient area with GDI.在此页面上: https://docs.microsoft.com/en-us/windows/win32/gdi/wm-ncpaint解释了如何使用 GDI 在非客户区绘图。

How can I draw in the nonclient area of my window with Direct2D without having to deal with GDI or GDI+?如何使用 Direct2D 在 window 的非客户区绘图,而无需处理 GDI 或 GDI+?

First of all, WM_NCPAINT is old.首先, WM_NCPAINT是旧的。 Using it will disable the DWM theme-ing for the window, giving a windows classic/7 basic look.使用它将禁用 window 的 DWM 主题,从而提供 windows 经典/7 基本外观。 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.但是要使用任何渲染 API 在客户区绘制,请从 window 中删除标准 window 帧,方法是在WM_NCCALCSIZE消息中的 wParam 为真时返回 0。

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 .如果要保留标准边界,请重新计算 WM_NCCALCSIZE 中的WM_NCCALCSIZE边界。

Then to get a "client area" title bar, use DwmExtendFrameIntoClientArea and extend it from the TOP .然后要获得“客户区”标题栏,请使用DwmExtendFrameIntoClientArea并从TOP扩展它。

Make sure to handle WM_NCHITTEST so that dragging your window will work too.确保处理WM_NCHITTEST以便拖动 window 也可以工作。

Make sure to premultiply your ALPHA in direct2d.确保在 direct2d 中预乘您的ALPHA Drawing a rectangle at (0,0) will draw a rectangle in the titlebar of your new custom window.在 (0,0) 处绘制一个矩形将在您的新自定义 window 的标题栏中绘制一个矩形。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM