MFC toolbar hidden and displayed

Source: Internet
Author: User

Recently learning MFC, watching is xinxin Sun VC + + video, feel good. When I see the Nineth class, when I talk about the toolbar, I do a little function: The toolbar is hidden and displayed, but there is a bug that a suspended toolbar is hidden and then displayed, it becomes docked. Here I again the hidden and display of the toolbar has been implemented again, remove the bug, to do with the MFC in the menu bar View-like toolbar menu items the same function.

In fact, about the hidden and display of the toolbar, only need to consider three states: (1) in the docking state of the display and hide the toolbar, (2) in the suspended state of the display and hide the toolbar, (3) in the suspended state, by clicking the Close button to close the toolbar, and then display the toolbar problem.

For the second case described above, remember that the toolbar is in the window coordinates (x, y) of the moment it will be hidden, which can be done when the menu item is clicked to hide the toolbar. Also for the third case, remember the coordinates of the toolbar at the closing moment, where we can create a class Cmytoolbar, which inherits from CToolBar, and adds wm_ to this class. Windowposchanged Message handler function onwindowposchanged. This message is triggered whenever the size or position of the toolbar changes, so we will first interpret the message as if it is suspended in its processing function, and then save it if the position of the current window is taken.

Well, it says so much now, start with the code. First look at the variable members you want to add in CMainFrame.h.

Then add the corresponding function for the toolbar menu item in CMainFrame.cpp, with the following code:

Finally, we will create a Cmytoolbar class that inherits from the CToolBar class, where CMyToolbar.h adds the following code:

Then implement the OnWindowPosChanged function in the Cmytoolbar

Here, the Code section is all over. Run Results Demo:

MFC toolbar hidden and displayed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.