Windows Random Rectangle Drawing
The code is as follows
#include <windows.h>void DrawRect (HWND hwnd); int cxclient, cyclient; LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM); int WINAPI WinMain (hinstance hinstance, HI Nstance hprevinstance, LPSTR lpcmdline, int ncmdshow) {static TCHAR szappname[] = TEXT ("Wndclass by Lxy"); Hwndhwnd; msgmsg; wndclasswndclass;//window class initialization wndclass.style= Cs_vredraw | cs_hredraw;wndclass.lpfnwndproc= wndproc;wndclass.cbclsextra= 0;wndclass.cbwndextra= 0;wndclass.hbrBackground= ( Hbrush) Getstockobject (White_brush); wndclass.hcursor= loadcursor (Null,idc_arrow); wndclass.hicon= LoadIcon (NULL, idi_application); wndclass.hinstance= hinstance;wndclass.lpszclassname= szappname;wndclass.lpszmenuname= NULL;// Register window class if (! RegisterClass (&wndclass)) {MessageBox (Null,text ("Allocation window class failed!"), szappname,mb_iconerror); return 0;} Create window hwnd = CreateWindow (Szappname,text ("Information display"), Ws_overlappedwindow,cw_usedefault, Cw_usedefault,cw_usedefault, Cw_usedefault,null, NULL, HINSTANCE, NULL); ShowWindow (hwnd,ncmdshow); UpdateWindow (HWND), while (TRUE) {if (PeekMessage (&msg, NULL, 0, 0, pm_remove)) {if (msg.message = = wm_quit) break; TranslateMessage (&msg);D ispatchmessage (&msg);} Else{drawrect (HWND);}} return Msg.wparam;} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {switch (message) {Case wm_size:cxclient = LO WORD (lParam); cyclient = HiWord (LParam); return 0;case wm_destroy:postquitmessage (message); return 0;} return DefWindowProc (Hwnd,message,wparam,lparam);} void DrawRect (HWND hwnd) {rect rect; HDC hdc; Hbrush hbrush;char szbuffer[20];static Long num = 0;int t;if (cxclient = = 0 | | cyclient = 0) return;t = rand ()%cyclient; SetRect (&rect, N, T, Cxclient, t+100),//sleep (hdc = GetDC (hwnd), Hbrush = CreateSolidBrush (RGB (rand ()%256, RA nd ()%256, rand ()%256)); FillRect (hdc, &rect, hbrush); num++; TextOut (hdc, 0, 0, szbuffer, wsprintf (Szbuffer, "painted rectangle")); TextOut (hdc, 0, Szbuffer, wsprintf (szbuffer, "%ld", num)); ReleaseDC (hwnd, HDC);D eleteobject (hbrush);}
Windows Random Rectangle Drawing