// sample02.cpp
#include <windows.h>
#include <stdio.h>

#include "wmmsg.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void ShowMyText(HWND);

char szClassNme[] = "Class";

void print_debug(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	printf("Received windows message:  ");
	if ( msg > MAX_WMMSG ) {
		printf("%d", msg);
	} else {
		printf("%s", wmtab[msg]);
	}
    printf(" -- 0x%X, 0x%X\n", (int)wParam, (int)lParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    print_debug(hWnd, msg, wParam, lParam);

    switch (msg) {
    case WM_CLOSE:
        DestroyWindow(hWnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    return 0L;
}

int main()
{
    HWND hWnd;
    MSG msg;
    WNDCLASS myProg;
    HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);

    myProg.style         = CS_HREDRAW | CS_VREDRAW;
    myProg.lpfnWndProc   = WndProc;
    myProg.cbClsExtra    = 0;
    myProg.cbWndExtra    = 0;
    myProg.hInstance     = hInstance;
    myProg.hIcon         = NULL;
    myProg.hCursor       = LoadCursor(NULL, IDC_ARROW);
    myProg.hbrBackground = GetStockObject(WHITE_BRUSH);
    myProg.lpszMenuName  = NULL;
    myProg.lpszClassName = szClassNme;

    if (!RegisterClass(&myProg))
        return 0;

    hWnd = CreateWindow(
        szClassNme,
        "Test",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);

    ShowWindow(hWnd, SW_SHOW);
    UpdateWindow(hWnd);

    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

