In the development of image display programs and video applications, often need full screen features, such as ACD See and Hero Jie Ba and other applications have full screen display. This article describes how to implement the full screen of a view in an MFC framework program, which means that the title, menu, toolbars, status bar, and all the borders of the window are all hidden, and the view fills the entire screen. and provides a quick switch between full screen display and frame window.
As you know, the MFC framework does not provide ready-made classes or functions to achieve full screen features, at least I have not found so far. But it is not difficult to achieve this feature. The basic idea is to adjust the size and position of the main window so that the display of the view fills the screen. It needs to handle the negative coordinates in the x,y direction with the upper left corner of the screen as the origin. This article uses the example code in the article "using GDI + for image processing" as the basis to realize the full screen display of the view. I added a reusable C + + class Cfullscreenhandler in the original code, as the name implies, the role of this class is designed to achieve full screen features, it encapsulates all the implementation details, as long as you add it to your own engineering code, There is no need to modify the program can be a full-screen display function. There are two important method calls in this class: First, maximize into full-screen display mode, note that the full screen mode here is not the usual window to maximize the button oh. Second, the Restore method is used to restore the original window frame. Cfullscreenhandler also provides a Infullscreenmode method to check whether a program is in full screen state, and these methods are invoked through a Cfullscreenhandler full object instance. The following is the main window processing command for the program, and the full screen feature is triggered by Full-screen display (&u) In the View menu, with key code as follows:
void CMainFrame::OnViewFullScreen()
{
if (FullScreenHandler.InFullScreenMode())
FullScreenHandler.Restore(this);
else
FullScreenHandler.Maximize(this);
}
Once you get to the full screen, the title bar, the menu bar, and the toolbar will disappear. Never forget to tell the user how to restore the original, add a few words to the OnDraw function:
void CPictureView::OnDraw(CDC* pDC)
{
......
if (*ppic) {
......
pDC->DrawText(FullScreenHandler.InFullScreenMode() ?
_T("恢复窗口按 Ctrl-U 或者在客户区双击鼠标") : _T(""), &rc, 0);
}
}
As shown in Figure one:
Figure A recovery hint for the user
The reason why you must give the user this hint is that an important GUI feature of the Windows program is the self interpretation of the interface operation. Otherwise, when the user enters Full-screen mode (intentionally or unintentionally), the user will be overwhelmed if the recovery method is not found.
Let's take a look at how cfullscreenhandler::maximize and restore work: In fact, there is nothing advanced in this code, just some pixel calculations. Maximize first saves the position of the current frame in the M_rcrestore data member, and then calculates the desired screen size. As shown in Figure II:
Figure II calculates the desired screen size