使用 Direct2D 在非客户区绘图 [英] Draw in the nonclient area with Direct2D

查看:46
本文介绍了使用 Direct2D 在非客户区绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此页面上:https://docs.microsoft.com/en-us/windows/win32/gdi/wm-ncpaint 解释了如何使用 GDI 在非客户区绘图.

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.

如何在不处理 GDI 或 GDI+ 的情况下使用 Direct2D 在窗口的非客户区中绘图?

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

推荐答案

首先,WM_NCPAINT 是旧的.使用它将禁用窗口的 DWM 主题,提供 Windows 经典/7 基本外观.所以不要这样做.

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.

但是要使用任何渲染 API 在客户区进行绘制,请在 WM_NCCALCSIZE 消息中的 wParam 为 true 时返回 0,从而从窗口中移除标准窗口框架.

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);

如果要保留标准边框,请在WM_NCCALCSIZE中重新计算窗口边界.

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

然后为了得到一个客户区"标题栏,使用DwmExtendFrameIntoClientArea并从TOP扩展它.

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

确保处理 WM_NCHITTEST 以便拖动窗口也能工作.

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

确保在 direct2d 中预乘您的 ALPHA.在 (0,0) 处绘制矩形将在新自定义窗口的标题栏中绘制一个矩形.

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.

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

这篇关于使用 Direct2D 在非客户区绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆