Having adapted my program to using malloc instead of direct allocation, I have this strange, unexpected problem. Without even touching these Windows elements, suddenly, BitBlt stopped working (causing something to appear in the top left of my screen drawn on top of everything, making it impossible to see what I'm doing. I found the cause to be the WindowHandle being 0. Using common diagnostics, the "GetLastError" function, I see that the class is not being found. Why is this? How come, without even changing this content, it suddenly stopped working? The only change I made was that of using malloc (which works as far as I can tell) for my image data, which is irrelevent....
Code:
// Window definitions
HWND WindowHandle; // window handle
WNDCLASSEX WindowClass; // window class
// in the WinMain function, first thing
WindowClass.cbSize = sizeof(WNDCLASSEX);
WindowClass.style = CS_HREDRAW | CS_VREDRAW;
WindowClass.lpfnWndProc = WndProc;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = hInstance;
WindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WindowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WindowClass.lpszMenuName = NULL;
WindowClass.lpszClassName = "MyClass";
WindowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
// Register the window class
if (!RegisterClassEx(&WindowClass);)
{
DebugTest[19] = (double)GetLastError();
return 1;
}
WindowHandle = CreateWindowW("MyClass",
"Platform Masters 1.0 (development version)",
WS_OVERLAPPEDWINDOW |
WS_VISIBLE |
WS_SYSMENU,
WindowPos.x, WindowPos.y,
WindowSize.x, WindowSize.y,
NULL,
NULL,
hInstance,
NULL);
DebugTest[19] = (double)GetLastError(); // returns 1407 - cannot find class
if (WindowHandle == 0)
{
return 0;
}