现在的位置: 首页 > 综合 > 正文

非客户区的绘制

2013年08月27日 ⁄ 综合 ⁄ 共 5741字 ⁄ 字号 评论关闭

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.

抱歉!评论已关闭.