Introduction
In many applications, occur the need of examining our view in mode, which makes full screen available. It relates especially to classes derived from CView
. This project presents simple application (SDI), that uses class CScrollView
showing data on the screen. Initially, view is in normal mode (placed in main frame, with toolbars, statusbar and menu). Converting our view to full mode, it's necessary to hide all other controls. Is it really necessary? It involves hiding main frame with toolbars, menu, and obliges to change code if new controls are placed. This project frees programmers from mentioned necessities and betrays a trick, that serves to preview progress run in your views.
First step
The first step is to add in CView
(CSrollView
,....) variables:
boolean isFull;
CWnd *saveParent;
COLORREF background, text;
CMenu *ContextMenu;
Next step is to add a new button (new submenu) in Resources and attach new ID: ID_FULL_SCREEN_MODE
- to enable/disable full screen mode. Associate this ID (in ClassWizard) and functions CFullScreenView::OnFullScreenMode()
, CFullScreenView::OnUpdateFullScreenMode(CCmdUI* pCmdUI)
.
The most important lines (trick)
( Description in comments )
void CFullScreenView::OnFullScreenMode()
{
if(!isFull){
isFull=true;
saveParent=this->GetParent();
this->SetParent(GetDesktopWindow());
CRect rect;
GetDesktopWindow()->GetWindowRect(&rect);
this->SetWindowPos(&wndTopMost,rect.left,rect.top,
rect.right,rect.bottom,SWP_SHOWWINDOW);
}
else{
isFull=false;
this->SetParent( saveParent);
((CMainFrame *)AfxGetMainWnd())->RecalcLayout();
}
}
Essentially, above-mentioned functions (its body) is way to receive our goal - after initializing variables mentioned in former chapter.
Turn off full screen mode
It's very important, to render possible disabling of full screen mode. Thus, context menu has been added (run by right mouse click). Only context menu, because of assumption to hide all controls, toolbars, menus in this mode.
How to disable full screen ? The best way is to send message ID_FULL_SCREEN_MODE
. In resources, insert a new menu IDR_MENU_VIEW
and in submenu define new items (first one is ID_FULL_SCREEN_MODE
, the others in my project are used to start CColorDialog
).
In CView::OnInitialUpdate()
,
ContextMenu= new CMenu();
if(!ContextMenu->LoadMenu(IDR_MENU_VIEW)){
AfxMessageBox("Fail to create context menu");
}
Context menu should appear, after clicking mouse (right button).
void CFullScreenView::OnRButtonDown(UINT nFlags, CPoint point)
{
ClientToScreen(&point);
if(ContextMenu->GetSubMenu(0)){
CMenu *pSubMenu= ContextMenu->GetSubMenu(0);
if(isFull){
pSubMenu->CheckMenuItem(ID_FULL_SCREEN_MODE,MF_CHECKED );
pSubMenu->EnableMenuItem(ID_CHANGE_TEXT_COLOR,MF_GRAYED);
pSubMenu->EnableMenuItem(ID_CHANGE_BACKGROUND_COLOR,MF_GRAYED);
}
else{
pSubMenu->CheckMenuItem(ID_FULL_SCREEN_MODE,MF_UNCHECKED );
pSubMenu->EnableMenuItem(ID_CHANGE_TEXT_COLOR,MF_ENABLED);
pSubMenu->EnableMenuItem(ID_CHANGE_BACKGROUND_COLOR,MF_ENABLED);
}
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
point.x,point.y,this);
}
CScrollView::OnRButtonDown(nFlags, point);
}
Warning !!
It's impossible to show other windows (dialog boxes, etc.) in full screen mode. This mode serves to review content of view.