非客户区的绘制

As we know, it is relatively easy to draw in the client area of the applicaiton.But how to draw in the nonclient area if we want to have custom title bar or menu.I supply one way to implement that object.
First, override the DefWindowProc function to direct some messages to your DrawTitleBar function as shown below.

Note:The WM_MOVE message is sent after a window has been moved. 

        The WM_NCPAINT message is sent to a window when its frame must be painted. 

        The WM_NCACTIVATE message is sent to a window when its nonclient area needs to be changed to indicate an active or inactive state. 

        The WM_NOTIFY message is sent by a common control to its parent window when an event has occurred or the control requires some information.

 

Then you can draw the title bar in the DrawTitleBar function. There are some necessary operation to do in this function, such as draw the title bar, draw the window border, draw the exit button, draw the application icon in the title bar and draw the title.It's essential to know the size of those areas if we want to draw them.Thus, the GetSystemMetrics function which can retrieves various system metrics is very useful here. Besides, the draw functions is the same as used in the client area.

And the OnNcMouseMove which the framework call when the cursor is moved within a nonclient area is also recommended to be implemented.It's intended to redraw the exit button, minimize button and the maximize butoon when the cursor is moved within them.


To have a custom menu is desirable to derive a class from CMenu.Then there are three steps to complete it.First, attach the custom menu. I finish that in the following way.

The code above is added into the CXXXApp::InitInstance, and  CustomMenuAttach is implemented as follow:

  

 

And there are three functions to be implemented in the CMainFrame:

 

 


Well, what the menu looks like depends on how you implement the derived class from CMenu.

客户自绘wtl版本指的是在Windows模板库(WTL)基础上通过自主绘制客户来定制界面的版本。 WTL是一个开源的C++模板库,用于简化Windows桌面应用程序的开发。它相较于MFC更轻量级,更容易学习和使用。WTL提供了一系列的模板类和宏,可以快速开发具有Windows UI风格的应用程序。 在WTL中,客户(Non-Client Area)是指窗口边框以及标题栏、菜单栏、状态栏等装饰性的部分。传统上,这部分通常由操作系统负责绘制和管理。但是对于一些特殊需求,比如自定义的窗口样式、矩形窗口等,我们需要对客户进行自主绘制客户自绘wtl版本即是基于WTL框架,在需要自定义客户的情况下,通过手动绘制实现。这种方式需要重载WTL框架中的客户绘制相关的函数,比如`OnNcPaint()`、`OnNcCalcSize()`等,来处理客户绘制逻辑。 客户自绘wtl版本的好处在于可以完全控制客户的外观。可以根据自己的需要,实现各种特殊的样式和效果,如渐变色、图案填充、自定义按钮等。这样可以使应用程序更加美观和独特,增强用户体验。 但是客户自绘wtl版本也存在一些挑战。首先,自绘客户需要较高的绘制技术和图形处理能力。其次,自绘客户还会涉及到一些与系统相关的问题,如窗口移动、窗口关闭等操作的处理。因此,需要对WTL框架有较深入的理解和熟练的编程技巧。 总之,客户自绘wtl版本是在WTL框架基础上,通过自主绘制实现自定义客户的一种方式。它可以让我们灵活控制客户的外观,提升应用程序的美观程度和用户体验。然而,也需要考虑到相关的技术和系统问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值