I'm currently reading "programming windows" by charles petzold and am trying my best to UNDERSTAND the code, rather than just copy it, however, I've come undone with the following bit of code:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int iCmdShow)
{
//Name of the window class
LPWSTR lpszWindowClass = L"HelloWorld";
//window class struct
WNDCLASS wc = { };
wc.lpfnWndProc = WndProc; //Window callback function
wc.lpszClassName = lpszWindowClass; //Name of the window class
wc.hInstance = hInstance; //Instance that calls the window
//Register the class and inform the user wether or not it succeeded
if( !RegisterClass(&wc) )
{
MessageBox(NULL,
L"Class Not Registered!",
L"ERROR!",
MB_OK | MB_ICONERROR);
}
//Create the window
HWND hWnd;
hWnd = CreateWindow(lpszWindowClass,
L"Hello World!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(hWnd==NULL)
{
MessageBox(NULL,
L"Window Not Created!",
L"ERROR!",
MB_OK | MB_ICONERROR);
return 0;
}
//show the window
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
//create the message loop
MSG msg;
while( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
DrawText(hdc,
L"Hello World!",
-1,
&rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return 0;
}
I'm getting no compiler errors and as far as I can tell it SHOULD work, however, it always fails to create the window.
If anyone could help it would be GREATLY appreciated.
Get on my level