非客户区的绘制

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值