#include <windows.h>
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
/*
hInstance - identifier of the "instance"/application
prevInstance - obsolete, not important
lpCmdLine - string pointer, like argv in C (getting cmdline parameters)
showCmd - not important in games
*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc; //fill up this struct and then Register
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc; //WindowProc() is a function that handles messages (e.g. mouse and keyboard inputs)
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = "Window Class 1";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL,
"Window Class 1 - CreateWindowEx",
"Window Name 1",
WS_OVERLAPPEDWINDOW,
300,
300,
500,
400,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
MSG msg;
while(true)
{
//Check if there is a message in the message queue. If none, continue with the game code, else process
while(PeekMessage(&msg, hWnd, 0,0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
break;
/*
Run Game Code Here
*/
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
//close application
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
//Hnadle any statement the switch-case didn't
return DefWindowProc(hWnd, message, wParam, lParam);
}
I have this program written using MS Visual C++ 2010. When I debug it (F5), there is no error and it runs. BUT it does not show anything. I'm expecting a blank window. Can anyone help me identifying what is wrong with this code? Thanks!
I'm following a DirectX tutorial, BTW.