在Win32 / MFC中处理非客户区域。 [英] Handling Non-Client Area in Win32/MFC.

查看:307
本文介绍了在Win32 / MFC中处理非客户区域。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义我的窗口。我想绘制标题栏,窗口边框并关闭,自己最小化按钮。我通过互联网搜索了一个教程或一个样本应用程序来完成这项工作,但没有找到任何东西。



我知道我必须处理 WM_NCPAINT WM_NCCALCSIZE ,...我自己的消息。甚至MSDN也没有关于处理窗口非客户区的教程。



我只需要一个示例应用程序,一些源代码,一个教程或教授如何处理的任何东西窗口的非客户区域(主要是绘画)。只要它能完成这项任务,它对我来说无关紧要。



干杯!

I want to customize my window. I want to paint title bar, window borders and close, minimize buttons myself. I searched through internet looking for a tutorial or a sample application that does the job, but nothing was found.

I know that i have to handle WM_NCPAINT, WM_NCCALCSIZE ,... messages myself. Even MSDN does not have a tutorial about handling a window's nonclient area.

I just need a sample application, some source code, a tutorial or anything that teaches how to handle the non client area of a window (mainly painting). It does not matter for me if it's MFC or Win32 as long as it does the job.

Cheers !

推荐答案

你会在所谓的皮肤库中找到很多例子。例如:

基于图片皮肤系统和MPEG解码器 [ ^ ]

只需在CodeProject中的皮肤下搜索,你会发现很多示例代码。



但正如谢尔盖已经指出的那样:如果Windows API的文档已经讲述了整个故事,为什么还要寻找教程和示例。只需研究API文档,特别是关于更新区域的部分
You will find lots of examples in so-called skinning libraries. For example:
A picture based skin system and MPEG decoder[^]
Just search under "skin" in CodeProject and you will find lots of example code.

But as Sergey already pointed out: Why do you look for tutorials and examples if the documentation of the Windows API already tells the whole story. Just study the API documentation, particularly the part about the update region.


找到一篇好文章:

样式工具包 - 使用高级图形技术创建自定义用户界面 [ ^ ]
Found a great article :
Style Toolkit - Use advanced graphics techniques to create a custom user interface[^]


自己管理非客户区确实是一个没有太多文档和杂乱的主题,并且有很多陷阱,比如你必须在窗口最大化时隐藏边框。 ..如果你想要的只是一个自定义绘制的窗口(就像一个典型的花式媒体播放器的窗口),那么我建议您使用以下内容:通常更容易创建一个没有非客户区域的单个像素的窗口,只需用WM_POPUP创建窗口没有标题和边框/框架的样式(可选w系统菜单可以在任务栏上显示右键菜单)并自己绘制/处理所有内容。无边框无标题WM_POPUP窗口只是一个矩形,此矩形的每个像素都是客户区的一部分。



在某些情况下,非客户区的位置很重要这种技术不是一个好的解决方案,但在很多情况下,它是一个非常可行的选择。当然,对于仅客户区域的窗口,您必须自己处理每个系统功能(比如绘制标题栏[某处]并在抓取标题栏时移动窗口,例如通过抓取客户区来抓取窗口移动操作:正确使用SetCapture()和ReleaseCapture()(通常在拖放期间)操作)。 [ ^ ])和可选窗口调整大小或最大化功能......
Managing the nonclient area yourself is indeed a not too well documented and messy topic and there are a lot of pitfalls like you have to hide the borders when the window is maximized... If all you want is a custom drawn window (like that of a typical fancy media player) then I recommend you the following: Often its much easier to create a window without a single pixel of nonclient area, just create the window with WM_POPUP style without caption and border/frame (optionally with system menus to be able to bring up right click menus on the taskbar) and draw/handle everything yourself. A borderless captionless WM_POPUP window is just a rectangle and every single pixel of this rectangle is part of the client area.

In some scenarios where the location of the nonclient area matters this technique isn't a good solution but in many cases it is a quite viable option. Of course with a client-area-only window you have to handle every system functionality yourself (like drawing a title bar [somewhere] and moving the window when the title bar is grabbed, example to a grabbing window move operation by grabbing the client area: Using SetCapture() and ReleaseCapture() correctly (usually during a drag n' drop operation).[^]) and optional window resize or maximize features...


这篇关于在Win32 / MFC中处理非客户区域。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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