I. Introduction
In editing software orProgramCodeYou often encounter text or code with a very large length in editing programs, especially for editing program source code. If the editing interface is too small, you need to pull the scroll bar frequently, it is reluctant for programmers, because it will interrupt the program design ideas and affect the programming effect. Therefore, many software have the full screen zoom function, which can zoom in the editing interface to the full screen to minimize the dependence on the scroll bar. I believe many programmers are very fond of programming in the full-screen editing status of VC. In this article, Visual C ++ 6.0 is used as the development environment to extend the single-document editing view program to the full-screen editing function.
Ii. Program Design Ideas
The reason why General programs fail to achieve full screen while maximizing the number of windows is that the status bar, tool bar, system menu, title bar, and other Windows occupy part of the screen space, therefore, to achieve full-screen display of a view, you must first hide the above forms before you can consider maximizing the view.
Hiding the status bar and toolbar can be used as a floating form. You only need to set the parameters of the showwindow () function to sw_hide through their respective handles to hide these forms, which are very similar to the view, you can use the sw_show flag to display it as needed. Note that you need to save the current view settings before performing full screen operations, which is required to restore the full screen to the original state. This operation is also relatively simple, just call the API function getwindowrect. The hiding of the title bar is not a simple hiding window. This involves modifying the form style. The ws_caption style should be removed from the existing form style. You can use getwindowlong () to obtain the current form style, separate the ws_caption style from the logic operation, and use setwindowlong () the function sets the modified form style to the current form style. You can easily hide the System Menu by saving the current menu and setting it to "null. After all the forms are hidden, the rest of the work is to enlarge the edit View to the full screen. You can use this to obtain the current view pointer and display the showwindow () if the function parameter is set to sw_showmaximized, the whole full screen amplification process is completed.
Restoring from full screen to initial state is the inverse operation of the above process: the ws_caption style is added to the form style through logical operations to restore the display of the title bar; set the flag parameter of the showwindow () function of the status bar and toolbar to wm_show to restore the function respectively; the system menu can also be read from the saved original menu and reset to restore its original appearance. Currently, only the hidden forms are displayed, and the forms are still in full screen status. Therefore, you must use the movewindow () function to restore the position of the form to the status before full screen, this is why we need to save some original parameters of the Form in full screen mode.
Iii. Specific implementation of the program
The previous section roughly analyzed the design and implementation of the Program on the general idea, but many details have not been taken into account in actual programming, the following code is based on the previous program design ideas, and some of its key code is explained in order to better understand the implementation method of this program:
Full Screen Display:
// Hide the current toolbar and taskbar by setting the sw_hide Parameter M_btoolbarwasvisible = (m_wndtoolbar.iswindowvisible ()! = 0 ); M_wndtoolbar.showwindow (sw_hide ); M_bstatusbarwasvisible = (m_wndstatusbar.iswindowvisible ()! = 0 ); M_wndstatusbar.showwindow (sw_hide ); ...... // Because there is no system menu or toolbar in the full screen status, you need to display a floating toolbar button for // return to the normal status from the full screen status. // Create a toolbar object, load a toolbar resource, and set the style of the toolbar: M_pwndfullscreenbar = new ctoolbar; M_pwndfullscreenbar-> Create (this ); M_pwndfullscreenbar-> loadtoolbar (idr_fullscreen ); M_pwndfullscreenbar-> setbarstyle (m_pwndfullscreenbar-> getbarstyle () | Cbrs_tooltips | cbrs_flyby | cbrs_size_dynamic ); // Floating button Effect M_pwndfullscreenbar-> modifystyle (0, tbstyle_flat ); M_pwndfullscreenbar-> enabledocking (0 ); // Set the position of the button returned to the normal state Cpoint Pt (300,200 ); Floatcontrolbar (m_pwndfullscreenbar, pt ); // Pre-Save the current window position before enlarging to the full screen Getwindowrect (& m_mainrect ); // Hide the title bar by changing the window style Long style =: getwindowlong (m_hwnd, gwl_style ); Style & = ~ Ws_caption; : Setwindowlong (m_hwnd, gwl_style, style ); Int screenx = getsystemmetrics (sm_cxscreen ); Int screeny = getsystemmetrics (sm_cyscreen ); // Change the size again: Setwindowpos (null, 0, 0, screenx, screeny, swp_nozorder ); Style =: getwindowlong (m_hwnd, gwl_style ); M_bchildmax = (Style & ws_maximize )? True: false; // Save the original system menu and set the current menu to null Cmenu * poldmenu = getmenu (); M_orgmenu.attach (poldmenu-> detach ()); Setmenu (cmenu *) null ); // After hiding other forms, enlarge the editing view to full screen This-> showwindow (sw_showmaximized ); ...... |
It is relatively simple to restore the code from the full screen to the initial state. You only need to restore the hidden forms and menus in sequence and move the view to the original size, the code in this section is similar to that in full screen mode, but the parameters are different. The following is the main code for recovering data:
...... // Restore the saved System Menu Setmenu (& m_orgmenu ); M_orgmenu.detach (); // Release the toolbar pointer object created when it falls into full screen. Because it is created with new, the pointer is allocated in the System Heap. // address space cannot be released automatically when the program exits, therefore, delete must be used for explicit release. Delete m_pwndfullscreenbar; // Add the preceding ws_caption style to the form style. Long style =: getwindowlong (m_hwnd, gwl_style ); Style | = ws_caption; : Setwindowlong (m_hwnd, gwl_style, style ); // Display toolbar and taskbar If (m_btoolbarwasvisible) M_wndtoolbar.showwindow (sw_show ); If (m_bstatusbarwasvisible) M_wndstatusbar.showwindow (sw_show ); Movewindow (& m_mainrect ); Recalclayout (); ...... |
Summary:
This article mainly designs a single-document framework program. It is relatively simple because it does not involve subforms. For full screen amplification of multiple documents, the overall approach is consistent with this. Only when processing full-screen display and restoration, the sub-framework of the program must also respond to zoom in and out. The title bar should also be hidden and restored by changing the window style. This program is also applicable to other programs based on non-editing views. The program described in this article is compiled by Microsoft Visual C ++ 2000 under Windows 6.0 professional.