Implement full screen window program in VC

Source: Internet
Author: User

Full Screen Display is essential for some applications. For example, when using VC ++ to edit resources such as the Project source file or the editing dialog box, select "viewfull screen" to enter the full screen display status, press the "ESC" key to exit full screen display.

In VC ++ 6.0, Appwizard is used to generate the application framework of the Single-Document Interface by default. Next, we will first discuss how to click the menu item "viewfull screen" to achieve full screen display, and then how to exit the full screen display status after pressing the "ESC" key.

1) Add the following three member variables in the cmainframe class.

Class cmainframe: Public cframewnd

{PRIVATE: // three member variables added by yourself

Windowplacement m_oldwndplacement; // used to save the original window position

Bool m_bfullscreen; // full screen display flag

Crect m_fullscreenrect; // indicates the position of the window when the screen is displayed.

Protected: cmainframe ();

Declare_dyncreate (cmainframe )}

2) edit the menu idr_mainframe in the resource editor. In the View menu bar, add the menu item "full screen ". In its attribute box, Set ID to id_full_screen and caption to "full screen ". You can also add a new tool icon in the toolbar and associate it with the menu item "full screen" to set its id value to id_full_screen.

3) design the full-screen display processing function, and add the response function of the preceding menu item id_full_screen in the cmainframe class. The response function is as follows:

Void cmainframe: onfullscreen ()

{Getwindowplacement (& m_oldwndplacement );

Crect windowrect;

Getwindowrect (& windowrect );

Crect clientrect;

Repositionbars (0, 0 xFFFF, afx_idw_pane_first, reposquery, & clientrect );

Clienttoscreen (& clientrect );

// Obtain the screen resolution

Int nfullwidth = getsystemmetrics (sm_cxscreen );

Int nfullheight = getsystemmetrics (sm_cyscreen );

// Display the customer area except the control bar in full screen to the (0, 0) to (nfullwidth, nfullheight) area, and (0, 0) and (nfullwidth, nfullheight) expand the difference between the original window and the customer location except the control bar outside the two points to get the window location displayed in full screen

M_fullscreenrect.left = windowrect. left-ClientRect.left;

M_fullscreenrect.top = windows. top-ClientRect.top;

M_fullscreenrect.right = windowrect. right-ClientRect.right + nfullwidth;

M_fullscreenrect.bottom = windowrect. bottom-ClientRect.bottom + nfullheight;

M_bfullscreen = true; // set the full-screen display flag to true.

// Enter the full screen display status

Windowplacement wndpl;

Wndpl. Length = sizeof (windowplacement );

Wndpl. Flags = 0;

Wndpl. showcmd = sw_shownormal;

Wndpl. rcnormalposition = m_fullscreenrect;

Setwindowplacement (& wndpl );}

4) The ongetminmaxinfo function of the cmainframe class is reloaded to provide the location information displayed in full screen mode.

Void cmainframe: ongetminmaxinfo (minmaxinfo far * lpmmi)

{If (m_bfullscreen)

{Lpmmi-> ptmaxsize. x = m_fullscreenrect.width ();

Lpmmi-> ptmaxsize. Y = m_fullscreenrect.height ();

Lpmmi-> ptmaxposition. x = m_fullscreenrect.width ();

Lpmmi-> ptmaxposition. Y = m_fullscreenrect.height ();

// The maximum track size must be changed.

Lpmmi-> ptmaxtracksize. x = m_fullscreenrect.width ();

Lpmmi-> ptmaxtracksize. Y = m_fullscreenrect.height ();

} Cframewnd: ongetminmaxinfo (lpmmi );

}

1) Select cmainframe in classview, right-click it, and select "add member function ...", Add the public-type member function endfullscreen, which exits the full screen display.

Void cmainframe: endfullscreen ()

{If (m_bfullscreen)

{// Exit full screen display and restore the original window display

Showwindow (sw_hide );

Setwindowplacement (& m_oldwndplace

Ment );}}

2) The function endfullscreen can exit the full screen display. The problem is how to call this function after the "ESC" Key is pressed. Because the View class can process messages related to keyboard input (for example, wm_keydown indicates that the user presses a key), we will add the onkeydown function to the View class cfullscreenview for processing the wm_keydown message. if the press Key is "ESC", call the endfullscreen function of the cmainframe class to exit the full screen display.

Void cfullscreenview: onkeydown (uint nchar, uint nrepcnt, uint nflags)

{If (nchar = vk_escape) // If you press the ESC key

{// Obtain the pointer of the main frame window

Cmainframe * pframe = (cmainframe *) afxgetapp ()-> m_pmainwnd;

// Call the endfullscreen function of the main window class to exit full screen display.

Pframe-> endfullscreen ();}

Cview: onkeydown (nchar, nrepcnt, nflags );}

In this way, we have implemented a professional full screen display function, and I believe it will certainly increase the color of your software program.

From http://c.chinaitlab.com/vc/917454.html

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.