#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)
{
//声明全局数据:类名
static TCHAR szClassName[] = TEXT("MyWindows");
HWND hwnd;
MSG msg; //注册窗口类
WNDCLASS wndclass; wndclass.hInstance = hInstance;
wndclass.lpszClassName = szClassName;
wndclass.cbClsExtra = ;
wndclass.cbWndExtra = ;
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 ;
} 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, , ))
{
TranslateMessage(&msg);
DispatchMessage(&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;
// 绘制一个多边形,可填充是需要顶点的个数polygon
POINT apt1[] = { , , , , , ,, };
// 绘制一个封闭多边形polyline需要顶点数+1 注意:用线绘制的封闭图像不具有填充能力
// POINT apt2[5] = { 400, 200, 500, 100, 600, 200, 500, 300, 400, 200 };
POINT apt2[];
int cxClient, cyClient; //星星的中心位置 switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect); cxClient = rect.right / ;
cyClient = rect.bottom / ; //获取五个顶点
//左上顶点
apt2[].x = cxClient - (int)(R*cos(PI / ));
apt2[].y = cyClient - (int)(R*sin(PI / )); //右上顶点
apt2[].x = cxClient + (int)(R*cos(PI / ));
apt2[].y = cyClient - (int)(R*sin(PI / )); //左下顶点
apt2[].x = cxClient - (int)(R*cos(PI / ));
apt2[].y = cyClient + (int)(R*sin(PI / )); //上顶点
apt2[].x = cxClient;
apt2[].y = cyClient - R; //右下顶点
apt2[].x = cxClient + (int)(R*cos(PI / ));
apt2[].y = cyClient + (int)(R*sin(PI / )); hBrush = CreateSolidBrush(RGB(,,));
hOldBrush = SelectObject(hdc, hBrush); // SetPolyFillMode(hdc, ALTERNATE); //交替填充
SetPolyFillMode(hdc, WINDING); //螺旋填充,填充所有能够一笔完成的图形
//
Polygon(hdc, apt2, );
// Polyline(hdc, apt2, 5);
//
SelectObject(hdc, hOldBrush);
DeleteObject(hOldBrush);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage();
return ;
} return DefWindowProc(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){//声明全局数据:类名static TCHAR szClassName[] = TEXT("MyWindows");HWND hwnd;MSG msg;
//注册窗口类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);DispatchMessage(&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;//绘制一个多边形,可填充是需要顶点的个数polygonPOINT apt1[4] = { 100, 200, 200, 100, 300, 200,200, 300 };//绘制一个封闭多边形polyline需要顶点数+1注意:用线绘制的封闭图像不具有填充能力//POINT apt2[5] = { 400, 200, 500, 100, 600, 200, 500, 300, 400, 200 };POINT apt2[5];int cxClient, cyClient;//星星的中心位置
switch (message){case WM_PAINT:hdc = BeginPaint(hwnd, &ps);GetClientRect(hwnd, &rect);
cxClient = rect.right / 2;cyClient = rect.bottom / 2;
//获取五个顶点//左上顶点apt2[0].x = cxClient - (int)(R*cos(PI / 5));apt2[0].y = cyClient - (int)(R*sin(PI / 5));
//右上顶点apt2[1].x = cxClient + (int)(R*cos(PI / 5));apt2[1].y = cyClient - (int)(R*sin(PI / 5));
//左下顶点apt2[2].x = cxClient - (int)(R*cos(PI / 5));apt2[2].y = cyClient + (int)(R*sin(PI / 5));
//上顶点apt2[3].x = cxClient;apt2[3].y = cyClient - R;
//右下顶点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);//交替填充SetPolyFillMode(hdc, WINDING);//螺旋填充,填充所有能够一笔完成的图形//  Polygon(hdc, apt2, 5);// Polyline(hdc, apt2, 5);//  SelectObject(hdc, hOldBrush); DeleteObject(hOldBrush);EndPaint(hwnd, &ps);break;case WM_DESTROY:PostQuitMessage(0);return 0;}

return DefWindowProc(hwnd, message, wParam, lParam);}

学习windows编程 day4 之 多边矩形填充的更多相关文章

  1. 学习windows编程 day4 之 绘制随机矩形和peekMessage

    #include <windows.h> #include <strsafe.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT messa ...

  2. 学习windows编程 day4 之 矩形的操作

    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...

  3. 学习windows编程 day4 之视口和窗口

    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...

  4. 学习windows编程 day4 之 盯裆猫

    写着写着就困了.... 看这些测量数据就算了,是对各种函数的练习 #include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT ...

  5. 学习windows编程 day4 之 设置画刷

    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...

  6. 学习windows编程 day4 之 自定义映射

    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...

  7. 学习windows编程 day4 之 映射模式

    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...

  8. 有一定基础的 C++ 学习者该怎样学习 Windows 编程?

    人的心理有个奇异的特性:一项知识一旦学会之后,学习过程中面临的困惑和不解非常快就会忘得干干净净,似乎一切都是自然而然,本来就该这种.因此,关于「怎样入门」这类问题,找顶尖高手来回答,未必能比一个刚入门 ...

  9. 我为什么学习Windows编程

    前一段时间在看TCP/IP,在图书馆里面找了不少的书,其中有几本书还是不错的.比如: <Windows网络与通信程序设计(第二版)> 王艳平著 <WinSock网络编程经络> ...

随机推荐

  1. Maven入门指南④:仓库

    1 . 仓库简介 没有 Maven 时,项目用到的 .jar 文件通常需要拷贝到 /lib 目录,项目多了,拷贝的文件副本就多了,占用磁盘空间,且难于管理.Maven 使用一个称之为仓库的目录,根据构 ...

  2. 【论文笔记】Domain Adaptation via Transfer Component Analysis

    论文题目:<Domain Adaptation via Transfer Component Analysis> 论文作者:Sinno Jialin Pan, Ivor W. Tsang, ...

  3. PAT L2-021 点赞狂魔

    https://pintia.cn/problem-sets/994805046380707840/problems/994805058485469184 微博上有个“点赞”功能,你可以为你喜欢的博文 ...

  4. PAT 1014 福尔摩斯的约会

    https://pintia.cn/problem-sets/994805260223102976/problems/994805308755394560 大侦探福尔摩斯接到一张奇怪的字条:“我们约会 ...

  5. Spring Framework: @RestController vs @Controller

    https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annota ...

  6. Appium学习笔记4_元素定位方法

    Appium之元素定位,如果对Android上如何使用工具获取页面元素有问题的,请转战到这:http://www.cnblogs.com/taoSir/p/4816382.html. 下面主要是针对自 ...

  7. [转帖] select、poll、epoll之间的区别总结[整理] + 知乎大神解答 https://blog.csdn.net/qq546770908/article/details/53082870 不过图都裂了.

    select.poll.epoll之间的区别总结[整理] + 知乎大神解答 2016年11月08日 15:37:15 阅读数:2569 http://www.cnblogs.com/Anker/p/3 ...

  8. Android Studio & HTTP Proxy

    Android Studio & HTTP Proxy https://mirrors.neusoft.edu.cn/android https://mirrors.neusoft.edu.c ...

  9. ajax 提交字符串到后台 反序列化

    MVC后台 或者 Webapi 都可以使用此方式 前台 @using (Html.BeginForm("Test","Test")) { <input t ...

  10. Nginx, HTTPS的配置

    server {listen 443;      ####HTTPS指定端口server_name www.web.com;      #####域名或者IP root /data/wwwroot/l ...