Code:
#include <windows.h>
#include <WINUSER.h>
#include <stdio.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd ;
MSG msg ;
WNDCLASS wc ;
wc.style = CS_HREDRAW | CS_VREDRAW ;
wc.lpfnWndProc = WndProc ;
wc.cbClsExtra = 0 ;
wc.cbWndExtra = 0 ;
wc.hInstance = hInstance ;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wc.lpszMenuName = NULL ;
wc.lpszClassName = "Moja klasa";
if (!RegisterClass (&wc))
{
MessageBox (NULL, "Greska u registraciji klase",
"Greska", MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow ("Moja klasa", // ime windows klase
"Zadaca 1", // tekst u Window title bar-u
WS_OVERLAPPEDWINDOW, // stil prozora
100, // inicijalna x koordinata
100, // inicijalna y koordinata
320, // inicijalna sirina prozora
250, // inicijalna visina prozora
NULL, // handle na vlasnika (parent) prozora
NULL, // window menu handle
hInstance, // handle na instancu aplikacije
NULL) ; // dodatni kreacioni parametri
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient;
HDC hdc;
static PAINTSTRUCT ps;
static RECT invalid;
char poruka[] = "Homework";
static SIZE sz;
static char pismo[100];
switch (message)
{
case WM_CREATE:
hdc = GetDC(hwnd);
GetTextExtentPoint32(hdc,poruka,strlen(poruka),&sz);
ReleaseDC(hwnd,hdc);
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&invalid);
TextOut(hdc,(cxClient - sz.cx),(cyClient - sz.cy),poruka,strlen(poruka));
sprintf(pismo,"The size of the invalid area is:\n x=%ld \n y=%ld " ,invalid.right,invalid.bottom);
MessageBox (NULL, pismo,"Greska", MB_ICONEXCLAMATION) ;
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Now if you run it you will see that as soon as you try to re-size the window (unless you maximize), the message box appears so you can move only for one pixel at time.