Error creating dummy window for OpenGL 3.x Content

Started by
1 comment, last by mark ds 10 years, 3 months ago

Hi all,

Trying to get my code to use an OpenGL 3.x Core Context.

Previously my code has been working fine on Windows using just a 1.2 Context, but now that I've prototyped out the design I need to get a more recent context to do some of the more exciting things.

The issue I'm having is that my CreateWindow() call is return a null HWND, and GetLastError() is returning 0 - which is less than helpful!

Bit of background info. This code is called in a child thread of the main application thread (I've tried calling it in the main thread, with the same results) and there is already a Window that has been successfully created (but not created a GL Context yet).

Any thoughts what I might be doing wrong?


WNDCLASS wndClass;
HINSTANCE hInstance = 0;

ZeroMemory(&wndClass, sizeof(WNDCLASS));

wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;			
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WndProc;
wndClass.lpszClassName = TEXT("Dummy Window");
wndClass.lpszMenuName = 0;
wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;

DWORD err = GetLastError();
RegisterClass(&wndClass);
err = GetLastError();

HWND hWnd = CreateWindow(TEXT("Dummy Window"), "Dummy Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
err = GetLastError();
if (hWnd == NULL)
{
	return false;
}

return true;
Advertisement

Right, fixed this - I was being stupid.

In the WndProc method I was passing to Register class I was just returning 0 (as the method wouldn't be used). Changing that to

static LRESULT CALLBACK WndProc(HWND hwnd, cxuint message, WPARAM wparam, LPARAM lparam)
{
return DefWindowProc(hwnd, message, wparam, lparam);
}
Worked perfectly...

To save a bit of code,

wndClass.lpfnWndProc = (WNDPROC) DefWindowProc;

also works fine.

This topic is closed to new replies.

Advertisement