Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
HDC hdc;
HPEN hpen;
HBRUSH hbrush;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof (wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "Window Class 1";
wndclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO);
RegisterClassEx (&wndclass);
hwnd = CreateWindow ("Window Class 1",
"My First Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
switch (iMsg)
{
case WM_CREATE:
break;
case WM_SIZE:
break;
case WM_PAINT:
BeginPaint ( hwnd, &ps );
hpen = CreatePen(PS_SOLID,2,RGB(200,20,2));
hbrush = CreateSolidBrush(RGB(15,15,200));
Rectangle ( hdc, 10, 10, 30, 30 );
EndPaint ( hwnd, &ps );
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
Why doesnt it draw a rectangle?