Learn about the multilateral rectangle padding for Windows programming Day4

Source: Internet
Author: User
Tags cos getmessage polyline

#include <windows.h>#include<math.h>LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM);#defineR 200#definePI 3.1415926intWINAPI WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR lpCmdLine,intnShowCmd) {    //declaring global Data: class name    StaticTCHAR szclassname[] = TEXT ("mywindows");    HWND hwnd;    MSG msg; //Register window classWndclass wndclass; Wndclass.hinstance=hinstance; Wndclass.lpszclassname=Szclassname; Wndclass.cbclsextra=0; Wndclass.cbwndextra=0; Wndclass.lpfnwndproc=WndProc; Wndclass.lpszmenuname=NULL; Wndclass.hicon=LoadIcon (NULL, idi_application); Wndclass.hcursor=loadcursor (NULL, Idc_arrow); Wndclass.hbrbackground=(Hbrush) getstockobject (White_brush); Wndclass.style=Cs_hredraw; if(! RegisterClass (&wndclass)) {MessageBox (NULL, TEXT ("This program must run in Windows nt!"), Szclassname, Mb_iconerror); return 0; } hwnd=CreateWindow (Szclassname, TEXT ("Myfirstpractice"), Ws_overlappedwindow, Cw_usedefault, Cw_usedefault, Cw_usedefault, Cw_usedefault    , NULL, NULL, HINSTANCE, NULL);    ShowWindow (hwnd, NSHOWCMD);    UpdateWindow (HWND);  while(GetMessage (&msg, NULL,0,0) {translatemessage (&msg); DispatchMessage (&msg); }    returnMsg.wparam;}    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {HDC hdc;    Paintstruct PS;    Rect rect; StaticHbrush Hbrush, hOldBrush;//draw a polygon that fills the number of vertices that need to be polygonPoint apt1[4] = { -, $, $, -, -, $, $, - };//draw a closed polygon polyline the number of vertices required +1 Note: Closed images drawn with lines do not have fill capacity//Point apt2[5] = {n , A, a, a, a, a, a, a, a.Point apt2[5]; intCxclient, Cyclient;//the central position of the stars    Switch(message) { CaseWM_PAINT:HDC= BeginPaint (hwnd, &PS); GetClientRect (hwnd,&rect); Cxclient= Rect.right/2; Cyclient= Rect.bottom/2; //get five vertices//Top left Vertexapt2[0].x = Cxclient-(int) (R*cos (PI/5)); apt2[0].Y = Cyclient-(int) (R*sin (PI/5)); //Top right vertexapt2[1].x = Cxclient + (int) (R*cos (PI/5)); apt2[1].Y = Cyclient-(int) (R*sin (PI/5)); //Lower left Vertexapt2[2].x = Cxclient-(int) (R*cos (PI/5)); apt2[2].Y = Cyclient + (int) (R*sin (PI/5)); //Top Vertexapt2[3].x =cxclient; apt2[3].Y = cyclient-R; //Lower right vertexapt2[4].x = Cxclient + (int) (R*cos (PI/5)); apt2[4].Y = Cyclient + (int) (R*sin (PI/5)); Hbrush= CreateSolidBrush (RGB (255,255,0)); hOldBrush=SelectObject (hdc, hbrush);//Setpolyfillmode (hdc, ALTERNATE); //Alternating fillSetpolyfillmode (hdc, winding);//Spiral Fill, fills all the shapes that can be completed in one stroke//Polygon (hdc, APT2,5);//Polyline (HDC, APT2, 5);// SelectObject (hdc, hOldBrush);        DeleteObject (hOldBrush); EndPaint (hwnd,&PS);  Break;  CaseWm_destroy:postquitmessage (0); return 0; }    returnDefWindowProc (hwnd, message, WParam, LParam);}

#include <windows.h> #include <math.h>
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM);
#define R 200#define PI 3.1415926
int WINAPI WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR lpcmdline, int nshowcmd) {//DECLARE global Data: Class name static TCHAR s Zclassname[] = TEXT ("MyWindows"); HWND hwnd; MSG msg;
Register window class WNDCLASS wndclass;
Wndclass.hinstance = Hinstance;wndclass.lpszclassname = Szclassname;wndclass.cbclsextra = 0;wndclass.cbWndExtra = 0; Wndclass.lpfnwndproc = Wndproc;wndclass.lpszmenuname = Null;wndclass.hicon = LoadIcon (NULL, IDI_APPLICATION); Wndclass.hcursor = LoadCursor (NULL, idc_arrow); wndclass.hbrbackground = (Hbrush) getstockobject (WHITE_BRUSH); Wndclass.style = Cs_hredraw;
if (! RegisterClass (&wndclass)) {MessageBox (NULL, TEXT ("This program must run in Windows nt!"), Szclassname, Mb_iconerror) ; return 0;}
hwnd = CreateWindow (Szclassname,text ("Myfirstpractice"), Ws_overlappedwindow,cw_usedefault,cw_usedefault,cw_ Usedefault,cw_usedefault,null,null,hinstance,null);
ShowWindow (hwnd, NSHOWCMD); UpdateWindow (HWND);
while (GetMessage (&msg, NULL, 0, 0)) {translatemessage (&msg);D ispatchmessage (&msg);}
return Msg.wparam;}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {HDC hdc; Paintstruct PS; Rect rect;
Static Hbrush Hbrush, holdbrush;//draws a polygon that can be populated with the number of vertices required polygonpoint apt1[4] = {100, 200, 200, 100, 300, 200,200, 300};//drawn The number of vertices required for a closed polygon polyline +1 Note: Closed images drawn with lines do not have fill capacity//point apt2[5] = {400, 200, 500, 100, 600, 200, 500, 300, 400, 200}; Point Apt2[5];int cxclient, cyclient;//the center of the stars
Switch (message) {Case WM_PAINT:HDC = BeginPaint (hwnd, &AMP;PS); GetClientRect (hwnd, &rect);
Cxclient = Rect.right/2;cyclient = RECT.BOTTOM/2;
Get five vertices//top left vertices apt2[0].x = cxclient-(int) (R*cos (PI/5)), apt2[0].y = cyclient-(int) (R*sin (PI/5));
Top right Vertex apt2[1].x = cxclient + (int) (R*cos (PI/5)); apt2[1].y = cyclient-(int) (R*sin (PI/5));
Lower left vertex apt2[2].x = cxclient-(int) (R*cos (PI/5)); apt2[2].y = cyclient + (int) (R*sin (PI/5));
Upper Vertex apt2[3].x = Cxclient;apt2[3].y = Cyclient-r;
Lower right Vertex apt2[4].x = cxclient + (int) (R*cos (PI/5)); apt2[4].y = cyclient + (int) (R*sin (PI/5));
Hbrush = CreateSolidBrush (RGB (255,255,0)); hOldBrush = SelectObject (hdc, hbrush);
Setpolyfillmode (hdc, ALTERNATE);//Alternating fill setpolyfillmode (hdc, winding);//spiral fill, fill all the graphics that can be completed//Polygon (HDC, APT2, 5) ;//Polyline (HDC, APT2, 5);//SelectObject (hdc, hOldBrush); DeleteObject (hOldBrush); EndPaint (hwnd, &AMP;PS); Break;case wm_destroy:postquitmessage (0); return 0;}

Return DefWindowProc (HWND, message, WParam, LParam);}

Learn about the multilateral rectangle padding for Windows programming Day4

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.