Hi,
I don’t know how to switch in fullscreen mode in a MFC DocView app (Single
Document Interface)
This is a code snippet from my app (that, obviously, doesn’t seem to work,
because the app switch to fullscreen but display in a standard window frame
and became instable, with a permanent wait cursor).
What’s wrong?
Thanks in advance.
Nicola Mosca
somewhere in time
BOOL COgldummyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CS_OWNDC);
// cs.style | = (WS_POPUP | WS_MAXIMIZE);
/* I include these styles in OnCreate because if I enable WS_POPUP and
disable WS_CHILD now, MFC reply with an ASSERT on WS_CHILD in std
CVIew::PreCreateWindow*/
return CView::PreCreateWindow(cs);
}
/* I apply a common pixelformat (RGBA, double buffer) */
bool COgldummyView::SetupPixelFormat()
{
GLuint PixelFormat;
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format
Descriptor
1,
// Version Number (?)
PFD_DRAW_TO_WINDOW | // Format Must Support
Window
PFD_SUPPORT_OPENGL | // Format Must Support
OpenGL
PFD_DOUBLEBUFFER, // Must Support
Double Buffering
PFD_TYPE_RGBA, // Request An
RGBA Format
24,
// Select A 24Bit Color Depth
0, 0, 0, 0, 0, 0, //
Color Bits Ignored (?)
8,
// No Alpha Buffer
0,
// Shift Bit Ignored (?)
0,
// No Accumulation Buffer
0, 0, 0, 0,
// Accumulation Bits Ignored (?)
16,
// 16Bit Z-Buffer (Depth Buffer)
0,
// No Stencil Buffer
0,
// No Auxiliary Buffer (?)
PFD_MAIN_PLANE, // Main Drawing
Layer
0,
// Reserved (?)
0, 0, 0
// Layer Masks Ignored (?)
};
m_myhDC = ::GetDC(m_hWnd); // Gets A Device Context For
The Window
PixelFormat = ChoosePixelFormat(m_myhDC, &pfd); // Finds The
Closest Match To The Pixel Format We Set Above
if (!PixelFormat)
{
::MessageBox(0,"Can't Find A Suitable
PixelFormat.",“Error”,MB_OK|MB_ICONERROR);
PostQuitMessage(0); // This Sends A ‘Message’ Telling
The Program To Quit
return false ; // Prevents The Rest Of The Code From
Running
}
if(!SetPixelFormat(m_myhDC,PixelFormat,&pfd))
{
::MessageBox(0,"Can't Set The
PixelFormat.",“Error”,MB_OK|MB_ICONERROR);
PostQuitMessage(0);
return false;
}
m_hRC = wglCreateContext(m_myhDC);
if(!m_hRC)
{
::MessageBox(0,"Can't Create A GL Rendering
Context.",“Error”,MB_OK|MB_ICONERROR);
PostQuitMessage(0);
return false;
}
if(!wglMakeCurrent(m_myhDC, m_hRC))
{
::MessageBox(0,"Can't activate GLRC.","Error",MB_OK|MB_ICONERROR);
PostQuitMessage(0);
return false;
}
// Now that the screen is setup we can
// initialize OpenGL();
InitGL();
return true;
}
/* OnCreate where I apply WS_POPUP */
int COgldummyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
lpCreateStruct->style = (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CS_OWNDC);
lpCreateStruct->style |= (WS_POPUP | WS_MAXIMIZE);
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
SetupPixelFormat();
return 0;
}
void COgldummyView::OnDestroy()
{
ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
// TODO: Add your message handler code here
if(wglGetCurrentContext()!=NULL)
{
// make the rendering context not current
wglMakeCurrent(NULL, NULL) ;
}
if (m_hRC!=NULL)
{
wglDeleteContext(m_hRC);
m_hRC = NULL;
}
// Now the associated DC can be released.
CView::OnDestroy();
}
/* OnShowWindow, where I switch to fullscreen mode */
void COgldummyView::OnShowWindow(BOOL bShow, UINT nStatus)
{
int i;
int numVideoModes;
int currentVideoMode = -1;
DEVMODE vmode;
DEVMODE *VideoMode;
m_width=640;
m_height=480;
nStatus = SW_SHOWMAXIMIZED;
CView::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
/* from [www.stefcam.com/articles/scottlegrand/col1](http://www.stefcam.com/articles/scottlegrand/col1) */
// Get the total number of modes so we can allocate memory for all of 'em.
numVideoModes = 0;
while (EnumDisplaySettings(NULL, numVideoModes, &vmode))
numVideoModes++;
// Fill an array with all the devmodes so we don’t have to keep
// grabbing 'em
VideoMode = (DEVMODE*)malloc(sizeof(DEVMODE) * numVideoModes);
for (i = 0; i < numVideoModes; i++)
EnumDisplaySettings(NULL, i, &VideoMode[i]);
// Set fullscreen video mode, note the use of the undocumented parameter
CDS_FULLSCREEN!
// The use of CDS_FULLSCREEN deactivates the task bar
for (i = 0; i < numVideoModes; i++) {
if ((VideoMode[i].dmPelsWidth == m_width) &&
(VideoMode[i].dmPelsHeight == m_height)) {
if (ChangeDisplaySettings(&VideoMode[i], CDS_TEST) ==
DISP_CHANGE_SUCCESSFUL) {
// Set desired video mode
ChangeDisplaySettings(&VideoMode[i], CDS_FULLSCREEN);
currentVideoMode = i;
}
}
}
// Free video mode list
free(VideoMode);
}