MFC toolbar hide and display, and mfc toolbar hide

Source: Internet
Author: User

MFC toolbar hide and display, and mfc toolbar hide

Recently I was studying MFC and watched sun Xin's VC ++ video. I feel pretty good. When I saw the ninth lesson, I made a small function when talking about the toolbar: hiding and displaying the toolbar, but a bug is that a floating toolbar is hidden and then displayed, it will become a stopped status. Here, I have hidden and displayed the toolbar again. I removed this bug and achieved the same functionality as the toolbar menu items in the menu bar embedded in MFC.

In fact, you only need to consider the following three States for hiding and displaying the toolbar: (1) Displaying and hiding the toolbar in the stopped state; (2) display and hide the toolbar in the floating state; (3) Click the close button to close the toolbar in the floating state, and then display problems in the toolbar.

For the second case described above, remember the window coordinates (x, y) of the time when the toolbar is to be hidden. This can be done when you click the menu item to hide the toolbar. In the third case, remember the coordinates of the toolbar at the close time. Here we can create a CMyToolbar class, which inherits from the CToolbar class, add the OnWindowPosChanged message processing function to this class. This message is triggered whenever the size or position of the toolbar changes. Therefore, when we trigger this message, we first determine whether the message is in a suspended state in its processing function, obtain the position of the current window and save it.

Okay. Now we have mentioned so much code. First, let's take a look at the variable member to be added in CMainFrame. h.

Then add the corresponding function of the toolbar menu item in CMainFrame. cpp. The specific code is as follows:

 

Finally, we need to create a CMyToolbar class that inherits from the CToolbar class. The code for adding CMyToolbar. h is as follows:

 

Then implement the OnWindowPosChanged function in the CMyToolbar.

At this point, all the code is complete. Demo of running result:

Related Article

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.