SetPixelFormat() fails

Hello, I met with strange situation because it worked fain before.
When it tries to set pixel format by using the SetPixelFormat() my MFC dialog stops responding and I neet to restart my PC for properly working of other applications.
Please a look at the code:

int OpenGLWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CWnd::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
m_hDC = ::GetDC(m_hWnd);

if (SetPixelFormat(m_hDC)==FALSE)
return -1;

if (CreateGLContext(m_hDC)==FALSE)
return -1;

}

BOOL OpenGLWnd::SetPixelFormat(HDC hdc)
{

PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER |
PFD_TYPE_RGBA,
24,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,//2,
0,
0,
0
};

int pixelFormat;

if((pixelFormat = ::ChoosePixelFormat(hdc, &pfd)) == 0)
{
pixelFormat = 1;
if(DescribePixelFormat(m_hDC, pixelFormat, // Obtains information about the pixel format identified by iPixelFormat of the device associated with hdc
sizeof(PIXELFORMATDESCRIPTOR), &pfd)==0)
return FALSE;

}

if (::SetPixelFormat(hdc, pixelFormat, &pfd) == FALSE)
{
return FALSE;
}

return TRUE;
}

BOOL OpenGLWnd::CreateGLContext(HDC hdc)
{

if((m_hrc = ::wglCreateContext(hdc)) == NULL)
return FALSE;

if(::wglMakeCurrent(hdc, m_hrc) == FALSE)
return FALSE;

return TRUE;
}

the OpenGLWnd class has been derived from CWnd.
I use Windows NT 4.0 SP6. However this problem appears on other OS as well.
Thank you in advance,
Romanas Puisa

Hi !

It would be much more helpful if you could say where it stops, use the debugger to singlestep through the code and look where it stops working.

Mikael

It seems that your PIXELFORMATDESCRIPTOR is
not set right.
After PFD_DOUBLEBUFFER should be coma,
PFD_TYPE_RGBA is value for iPixelType member of structure.
Aslo make sure that your card supports 32 bit
Z-buffer.
Hope this helps,
mproso

I think you are not right regarding to the comma placing. If you closely take a look at it once more you’ll see it set right. It seems you had been confused by OR operators.
If I mistake please point out where.
Thank you for spearing time at this problem.

Sorry you was right. I made mistake regarding the coma placing. I had used the PFD_TYPE_RGBA in incorrect position.
I think it will help to solve the problem.