如何在非客户区绘图?
我希望能够在窗口的非客户区域中的菜单栏右侧进行一些绘图。
使用 C++/MFC 这可能吗?
I'd like to be able to do some drawing to the right of the menu bar, in the nonclient area of a window.
Is this possible, using C++ / MFC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您只想在菜单栏中添加某些内容,也许将其添加为右对齐菜单项会更容易/更干净。 这样它也可以与不同的 Windows 主题等一起使用。
If you just want something in the menu bar, maybe it is easier/cleaner to add it as a right-aligned menu item. This way it'll also work with different Windows themes, etc.
Charlie 通过
WM_NCPAINT
找到了答案。 如果您使用 MFC,代码将如下所示:Charlie hit on the answer with
WM_NCPAINT
. If you're using MFC, the code would look something like this:为了在非客户区绘制,需要获取“窗口”DC(而不是“客户”DC),并在“窗口”DC中绘制。
In order to draw in the non-client area, you need to get the "window" DC (rather than "client" DC), and draw in the "window" DC.
您应该尝试处理 WM_NCPAINT。 这与普通的 WM_PAINT 消息类似,但处理整个窗口,而不仅仅是客户区。 WM_NCPAINT 上的 MSDN 文档提供了以下示例代码:
该代码旨在用在应用程序的消息循环中,该消息循环使用大型“switch”语句进行规范组织。
正如 Shog 的 MFC 示例中所述,请确保调用默认版本,在本示例中这意味着调用 DefWindowProc。
You should try handling WM_NCPAINT. This is similar to a normal WM_PAINT message, but deals with the entire window, rather than just the client area. The MSDN documents on WM_NCPAINT provide the following sample code:
This code is intended to be used in the message loop of your applicaton, which is canonically organized using a large 'switch' statement.
As noted in the MFC example from Shog, make sure to call the default version, which in this example would mean a call to DefWindowProc.