Hey all, just joined you.
Anyhow, I'm trying to run a simple windows program, and simply cannot figure out what I'm doing wrong. I remember doing this stuff about 3 years ago, but I don't remember any of it :/
Here's the code (there's more, but even this much doesn't work; I actually stole this from a tutorial online and it STILL doesn't work).
It compiles and links just fine, but when the program executes the message box pops up and the application closes right after I click ok. When i run through it debugging, I look at the value of hwnd and find it to be 0x0.Code:
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
hwnd = CreateWindowEx(NULL, "ProgName", "First Program",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, 0);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", NULL,
MB_ICONEXCLAMATION | MB_OK);
DWORD blah = GetLastError();
return 0;
}
return 0;
}
Any help would be great! Thanks :)