Code:
// #ifndef UNICODE
// #define UNICODE
// #endif
#include <windows.h>
WNDCLASS wc = {};
HWND hwnd;
const char szNAME[] = "Sample Window Class";
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int initialize(WNDCLASS* wc, HINSTANCE hInstance);
int makeApp(HINSTANCE hInstance, 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(hInstance, 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 char szNAME[] = "Sample Window Class";
//wc.sytle = 0;
(*wc).lpfnWndProc = WindowProc;
//wc.cbClsExtra = NULL;
//wc.cbWndEXtra = NULL;
(*wc).hInstance = hInstance;
(*wc).lpszClassName = szNAME;
RegisterClass(wc);
return (TRUE);
}
int makeApp(HINSTANCE hInstance, WNDCLASS wc)
{
hwnd = CreateWindowEx(
0, // Optional window styles
wc.lpszClassName, // Window Class
// szNAME,
"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
// hInstance,
NULL // Additional application data
);
if(hwnd == NULL)
{
return 0;
}
else
{
return 1;
}
}
LRESULT CALLBACK 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);
}