Advertisement

ChoosePixelFormat

Started by June 26, 2000 10:55 PM
2 comments, last by RWarden 24 years, 4 months ago
When I typed in the tutorials word-by-word, everything works great. But, when I do anything from scratch, ChoosePixelFormat fails. I''m basically going through exactly the same steps as in the tutorials, and creating the windows with exactly the same specifications. It can''t be a problem with my hardware not supporting it, because I''m using the same pixel format I used in the tutorial. It can''t be a problem with the PIXELFORAMTDESCRIPTOR struct, because after it failed the first time I c&p''d it from the tutorials. I''ve tried everything I can possibly think of, and a whole bunch of things that would seem to have nothing to do with the problem, but it still never works. Finally, when I used FormatMessage with GetLastError, I get the message "The Operation Completed Successfully". (Also, I know that ChoosePixelFormat is setting the last error because before I called it I used SetLastError (1) and ChoosePixelFormat set it back to zero). Please help, I''m kind of paralyzed trying to fix this problem. -RWarden (roberte@maui.net)
could you possibly show some of the code. i have been using ChoosePixelFormat for years, and may be able to help.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Advertisement
Here''s all the code minus error checking, in the order it''s called in my init function. This is the first code that executes when the program starts up:

// Window class:
wc.style = CS_HREDRAW / CS_VREDRAW / CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = 0;
wc.hIcon = LoadIcon ( NULL, IDI_WINLOGO );
wc.hCursor = LoadCursor ( NULL, IDC_ARROW );
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = NAME;
RegisterClass ( &wc );

// Fullscreen switch:
memset ( &dm, 0, sizeof ( dm ) );
dm.dmSize = sizeof ( dm );
dm.dmPelsWidth = 800;
dm.dmPelsHeight = 600;
dm.dmBitsPerPel = 16;
dm.dmFields = DM_BITSPERPEL / DM_PELSWIDTH / DM_PELSHEIGHT;
ChangeDisplaySettings ( &dm, CDS_FULLSCREEN );

// Window creation:
g_hwndMain = CreateWindowEx ( WS_EX_APPWINDOW, NAME, TITLE, WS_POPUP / WS_CLIPSIBLINGS / WS_CLIPCHILDREN, 0, 0, 800, 600, NULL, NULL, hInstance, NULL );

// Pixelformatdescriptor:
static PIXELFORMATDESCRIPTOR pfd =
{ sizeof ( PIXELFORMATDESCRIPTOR ), 1, PFD_DRAW_TO_WINDOW /
PFD_SUPPORT_OPENGL / PFD_DOUBLEBUFFER, PFD_TYPE_RGBA,
16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0,
PFD_MAIN_PLANE, 0, 0, 0, 0 };

// GetDC/ChoosePixelFormat:
g_hDC = GetDC ( g_hwndMain );
pf = ChoosePixelFormat ( g_hDC, &pfd );

ChoosePixelFormat always returns zero.

-RWarden (roberte@maui.net)
Yes... ChoosePixelFormat returns zero every time you execute it! But it's not an error!!!

I don't know why, but it works with pixelformat=0. I thought that a zero indicates that your PF is the PF you've requested, but if you do nothing about choosing,setting,etc. it won't work!

try this:

pixelformat = ChoosePixelformat( hDC, &pfd );
SetPixelFormat( hDC, pixelformat, &pfd );
DescribePixelFormat( -what ever it expects- );

Edited by - WickedImp on June 28, 2000 11:07:16 AM

This topic is closed to new replies.

Advertisement