Need help Creating Basic Window
I need help with the following. When executed know window is visible. Can someone help me, please? It is based on a tutorial from msdn. I tried to give more structure by placing some of the code into functions. The compiled and executed msdn's example and it works. Mine doesn't.
Code:
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int initialize(WNDCLASS* wc, HINSTANCE hInstance);
int makeApp(HWND &hwnd, WNDCLASS wc);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR pCmdLine, int nCmdShow)
{
// Declare window class for the main window
WNDCLASS wc = {};
HWND hwnd;
// Register , create, and show window
if(!initialize(&wc, hInstance))
return FALSE;
if(!makeApp(hwnd, wc))
return FALSE;
ShowWindow(hwnd, nCmdShow);
// Declare message struct
MSG msg;
// Create the message loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
int initialize(WNDCLASS *wc, HINSTANCE hInstance)
{
const wchar_t CLASS_NAME[] = L"Sample Window Class";
//wc.sytle = 0;
(*wc).lpfnWndProc = WindowProc;
//wc.cbClsExtra = NULL;
//wc.cbWndEXtra = NULL;
(*wc).hInstance = hInstance;
(*wc).lpszClassName = CLASS_NAME;
RegisterClass(wc);
}
int makeApp(HWND &hwnd, WNDCLASS wc)
{
hwnd = CreateWindowEx(
0, // Optional window styles
wc.lpszClassName, // Window Class
L"Learn to Program Windows", // Window Text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
wc.hInstance, // Instance handle
NULL // Additional application data
);
if(hwnd == NULL)
{
return 0;
}
else
{
return 1;
}
}
LRESULT WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// All painting occurs here, between BeginPaint and EndPaint
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
EndPaint(hwnd, &ps);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}