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: