|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionIn many applications, occur the need of examining our view in mode, which makes full screen available. It relates especially to classes derived from First stepThe first step is to add in boolean isFull; /* in constructor of CView: isFull=false; */ CWnd *saveParent; /* Besides other 3 var.: */ COLORREF background, text; CMenu *ContextMenu; Next step is to add a new button (new submenu) in Resources and attach new ID: The most important lines (trick)( Description in comments ) void CFullScreenView::OnFullScreenMode() { /* if normal mode - start (enable) full screen mode */ if(!isFull){ isFull=true; /* Variable saveParent is used to save address of parent window (address is necessary in disabling this mode -to place view in former position) */ saveParent=this->GetParent(); /* this (our view) is placed on desktop window - CWnd::GetDesktopWindow() - Returns the Windows desktop window */ this->SetParent(GetDesktopWindow()); CRect rect; /* temporary variable */ /* Next function copies the dimensions of the bounding rectangle of the desktop */ GetDesktopWindow()->GetWindowRect(&rect); /* view is placed on desktop */ this->SetWindowPos(&wndTopMost,rect.left,rect.top, rect.right,rect.bottom,SWP_SHOWWINDOW); } else{ /* disable full screen mode */ isFull=false; /* our view is placed in old window - using address saveParent (pointer that has been used in former if-section) */ this->SetParent( saveParent); /* pointer to the main frame and function RecalcLayout() (run on behalf of CmainFrame object) - that repositions all control bars in the frame (#include <MainFrame.h>) */ ((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 modeIt'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
In 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){ /* check menu item if full screen mode */ pSubMenu->CheckMenuItem(ID_FULL_SCREEN_MODE,MF_CHECKED ); /* disable next positions - to avoid sending message, that start dialogs, etc. */ pSubMenu->EnableMenuItem(ID_CHANGE_TEXT_COLOR,MF_GRAYED); pSubMenu->EnableMenuItem(ID_CHANGE_BACKGROUND_COLOR,MF_GRAYED); } else{ /* uncheck menu item */ pSubMenu->CheckMenuItem(ID_FULL_SCREEN_MODE,MF_UNCHECKED ); /* enable menu item - in normal mode. */ 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.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||