Windows Random Rectangle Drawing

Source: Internet
Author: User
Tags textout

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.