#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdio.h>

long WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	case WM_KEYDOWN:
		{
			const int nKeyCode = wParam;
			const int nScanCode = ((lParam & 0x00ff0000) >> 16);
			
			char szMessage[1024];
			sprintf(szMessage, "KeyCode = %d\nScanCode = %d", nKeyCode, nScanCode);
			const int nMessageLength = strlen(szMessage);

			HDC hDC = GetDC(hWnd);
			RECT rc;
			GetClientRect(hWnd, &rc);
			FillRect(hDC, &rc, HBRUSH(COLOR_WINDOW + 1));
			DrawText(hDC, szMessage, nMessageLength, &rc, DT_CENTER);
		}
		return 0;
	}

	return DefWindowProc(hWnd, msg, wParam, lParam);
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	WNDCLASS wc = {0};
	wc.lpszClassName = "Keys";
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.hbrBackground = HBRUSH(COLOR_WINDOW + 1);
	wc.style = CS_VREDRAW | CS_HREDRAW;
	RegisterClass(&wc);

	HWND hWnd = CreateWindow(wc.lpszClassName, "Keys", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 
	                         CW_USEDEFAULT, CW_USEDEFAULT, 150, 75, 
	                         NULL, NULL, hInstance, NULL);

	MSG msg;
 	while( GetMessage(&msg, NULL, 0, 0) )
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return 0;
}
