我可以使用MFC更改窗口边框的厚度吗?

问题描述:

通常,窗口的厚度为4像素,可以通过GetSystemMetrics方法检索.我可以更改其值,例如2像素吗?

Normally, the thickness of a window is 4 pixels, which can be retrieved by GetSystemMetrics method. Can I change its value, for example 2 pixels?

非常感谢!

简单答案:否.不适用于特定窗口.

Simple answer: No. Not for a specific window.

复杂的答案:边框被绘制为窗口的非客户端"区域的一部分.所有这些都由默认处理(即DefWindowProc)(在标题下)以及标题,最小化,最大化按钮等进行处理.您可以通过处理WM_NCPAINT消息来覆盖此内容.然后,您将负责绘制窗口的整个非客户区域.您还需要处理WM_NCCALCSIZE消息,以便Windows知道要为客户区留出多少剩余空间.

Complicated answer: The border is drawn as part of the "non-client" region of the window. This is all handled (under the hood) by the default processing (i.e. DefWindowProc), along with the caption, minimize, maximize buttons, etc. You can override this by handling the WM_NCPAINT message. You'll then be responsible for drawing the entire non-client area of your window. You'll also want to handle the WM_NCCALCSIZE message, so that Windows knows how much of the remaining space to give to your client area.

或者,您可以将窗口的边框样式设置为无. Windows可以为您绘制标题,尽管看上去可能略有不同.不幸的是,这样做会丢失拖动到调整大小功能.为此,您需要处理WM_NCHITTEST消息.

Alternatively, you can set the border style of your window to none. This will allow Windows to draw the caption for you, although it'll probably look slightly different. Unfortunately, by doing this, you lose the drag-to-resize functionality. For that, you'll need to handle the WM_NCHITTEST message.