Use the drawing function to create the filling Area and the drawing function Filling Area

Source: Internet
Author: User

Use the drawing function to create the filling Area and the drawing function Filling Area

1 # include <Windows. h> 2 # include <tchar. h> 3 BOOLEAN InitWindowClass (HINSTANCE hInstance, int nCmdShow); 4 lresult callback WndProc (HWND, UINT, WPARAM, LPARAM); 5 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 6 {7 MSG; 8 if (! InitWindowClass (hInstance, nCmdShow) 9 {10 MessageBox (NULL, L "window creation failed! ", _ T (" create window "), NULL); 11 return 1; 12} 13 while (GetMessage (& msg, NULL, 0, 0 )) 14 {15 TranslateMessage (& msg); 16 DispatchMessage (& msg); 17} 18 19 return (int) msg. wParam; 20} 21 lresult callback WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 23 {24 HDC hDC; 25 PAINTSTRUCT PtStr; 26 HBRUSH hBrush; 27 HPEN hPen; 28 static int dispMode =-1; 29 LPCTSTR str; 30 switch (message) 31 {32 case WM_LBUTTONDOWN: 33 InvalidateRect (hWnd, NULL, TRUE); 34 break; 35 case WM_PAINT: 36 hDC = BeginPaint (hWnd, & PtStr ); 37 dispMode = (dispMode + 1) % 6; 38 switch (dispMode) 39 {40 case 0: 41 str = _ T ("mming mode MM_TEXT: Default ing mode "); 42 SetMapMode (hDC, MM_TEXT); // set the ing mode to the default mode 43 TextOut (hDC, 0, 0, str, _ tcsclen (str )); // output ing mode and ing ratio 44 break; 45 case 1: 46 str = _ T ("mming mode MM_ISOTROPIC: The Window coordinate is 20 × 20, and the ing is based on The port size is 10 × 10, and the image size is doubled "); 47 SetMapMode (hDC, MM_ISOTROPIC); // you can set the ing mode to 48 SetWindowExtEx (hDC, 20, 20, NULL ); // The Window rectangle is x 20 49 SetViewportExtEx (hDC, 10, 10, NULL); // The rectangle mapped to the window is x 10 50 TextOut (hDC, 0, 0, str, _ tcsclen (str); 51 break; 52 case 2: 53 str = _ T ("mming method MM_ISOTROPIC: The Window coordinate is 10 × 10, the ing is 20x20 for the view, and the image size is doubled "); 54 SetMapMode (hDC, MM_ISOTROPIC); 55 set1_wextex (hDC, 10, 10, NULL ); // The Window rectangle is 10x10 56 SetViewportExtEx. (HDC, 20, 20, NULL); // The rectangle mapped to the viewport is 20x20 57 TextOut (hDC, 0, 0, str, _ tcsclen (str )); 58 break; 59 case 3: 60 str = _ T ("mming mode MM_ANISOTROPIC: The Window coordinate is 10 × 10, the ing is 20 × 10, and the image is doubled horizontally, portrait unchanged "); 61 SetMapMode (hDC, MM_ANISOTROPIC); 62 set1_wextex (hDC, 10, 10, NULL); // The Window rectangle is 10 × 10 63 SetViewportExtEx (hDC, 20, 10, NULL); // The rectangle mapped to the viewport is 20 × 10 64 TextOut (hDC, 0, 0, str, _ tcsclen (str); 65 break; 66 case 4: 67 str = _ T (" er Form MM_ANISOTROPIC: The Window coordinates are 10 × 10, the ing is 20 × 5, the image is scaled up one time horizontally, and the portrait is reduced by one time "); 68 SetMapMode (hDC, MM_ANISOTROPIC ); 69 setmediawextex (hDC, 10, 10, NULL); // The Window rectangle is 10 × 10 70 SetViewportExtEx (hDC, 20, 5, NULL ); // The rectangle mapped to the viewport is 20x5 71 TextOut (hDC, 0, 0, str, _ tcsclen (str); 72 break; 73 case 5: 74 str = _ T ("mming mode MM_ISOTROPIC: The Window coordinate is 10 × 10, and the ing is 20 × 5. In order to maintain the original aspect ratio, the system will adjust the ing ratio "); 75 SetMapMode (hDC, MM_ISOTROPIC); 76 SetWindowExtEx (hDC, 10, 10, NULL); // The Window rectangle is 10 × 10 77 SetViewportExtEx (hDC, 20, 5, NULL ); // The rectangle mapped to the viewport is 20x5 78 TextOut (hDC, 0, 0, str, _ tcsclen (str); 79 break; 80} 81 hPen = (HPEN) getStockObject (BLACK_PEN); // set the paint brush to the predefined black paint brush 82 hBrush = (HBRUSH) GetStockObject (DKGRAY_BRUSH); // deep gray paint brush 83 SelectObject (hDC, hBrush ); // select image brush 84 SelectObject (hDC, hPen); // select paint brush 85 RoundRect (hDC, 50,120,100,200, 15, 15); // rounded rectangle 86 hBrush = (HB RUSH) GetStockObject (LTGRAY_BRUSH); // pale gray image brush 87 SelectObject (hDC, hBrush); // select image brush 88 Ellipse (hDC, 150, 50,200,150 ); // elliptical 89 hBrush = (HBRUSH) GetStockObject (HOLLOW_BRUSH); // use the predefined virtual image brush 90 SelectObject (hDC, hBrush); // select 91 Pie (hDC, 250, 50,300,100,250, 50,300, 50); // pie-shaped 92 EndPaint (hWnd, & PtStr); // end painting 93 break; 94 case WM_DESTROY: 95 PostQuitMessage (0 ); // call PostQuitMessage to send the WM_QUIT message 96 br Eak; 97 default: 98 return DefWindowProc (hWnd, message, wParam, lParam); // the default system message processing function 99 break; 100} 101 return 0; 102} 103 104 BOOLEAN InitWindowClass (HINSTANCE hInstance, int nCmdShow) 105 {106 WNDCLASSEX wcex; 107 HWND hWnd; 108 TCHAR szWindowClass [] = L "window example "; 109 TCHAR szTitle [] = L "ing mode and filling example"; 110 wcex. cbSize = sizeof (WNDCLASSEX); 111 wcex. style = 0; 112 wcex. lpfnWndProc = WndProc; 113 wcex. cbCls Extra = 0; 114 wcex. cbWndExtra = 0; 115 wcex. hInstance = hInstance; 116 wcex. hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_APPLICATION); 117 wcex. hCursor = LoadCursor (NULL, IDC_ARROW); 118 wcex. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); 119 wcex. lpszMenuName = NULL; 120 wcex. lpszClassName = szWindowClass; 121 wcex. hIconSm = LoadIcon (wcex. hInstance, MAKEINTRESOURCE (IDI_APPLICATION), 122 if (! RegisterClassEx (& wcex) 123 return FALSE; 124 hWnd = CreateWindow (125 szWindowClass, 126 szTitle, 127 WS_OVERLAPPEDWINDOW, 128 CW_USEDEFAULT, CW_USEDEFAULT, 129 CW_USEDEFAULT, CW_USEDEFAULT, 130 NULL, 131 NULL, 132 hInstance, 133 NULL134); 135 if (! HWnd) 136 return FALSE; 137 ShowWindow (hWnd, nCmdShow); 138 UpdateWindow (hWnd); 139 return TRUE; 140}

 

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.