#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. JS对象复制(深拷贝、浅拷贝)

    如何在 JS 中复制对象 在本文中,我们将从浅拷贝(shallow copy)和深拷贝(deep copy)两个方面,介绍多种 JS 中复制对象的方法. 在开始之前,有一些基础知识值得一提:Javas ...

  2. Online Resource Mapping for SDN Network Hypervisors using Machine Learning

    发表时间:2016 一些定义: self-configuring networks: FlowVisor: FlowVisor是建立在OpenFlow之上的网络虚拟化工具,它可以将物理网络划分成多个逻 ...

  3. mybatis 框架网站

    http://www.mybatis.org/mybatis-3/zh/index.html

  4. java mail smtp port

    https://www.tutorialspoint.com/javamail_api/javamail_api_smtp_servers.htm https://www.mkyong.com/jav ...

  5. CSS响应式网站开发

    <html> <head> //当设备屏幕最大宽度小于1024px时加载如下CSS内容 @media screen and (max-width: 1024px){       ...

  6. Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs)

    Docker提供了三种不同的方式用于将宿主的数据挂载到容器中:volumes,bind mounts,tmpfs volumes.当你不知道该选择哪种方式时,记住,volumes总是正确的选择. vo ...

  7. Linux运维工程师必须掌握的基础技能有哪些?

    这个问题挺好的,回答这个问题也是对自身的审查,看看自己还欠缺哪些.(所以我估计得好好思考下,也许下一刻我就会突然惊醒,发现我还是战⑤渣) 首先限定在Linux运维工程师上 回答仅代表我想到,不代表我都 ...

  8. python数据相关性分析 (计算相关系数)

    #-*- coding: utf-8 -*- #餐饮销量数据相关性分析 计算相关系数 from __future__ import print_function import pandas as pd ...

  9. (转)vmware下给linux虚拟机扩容

    “Well, here’s another fine mess you’ve gotten me into” Let us pretend that you have an Ubuntu Server ...

  10. 英国电信反悔华为是唯一真正的5G供应商

    导读 英国电信反悔华为是唯一真正的5G供应商 英国电信的一位发言人表示,该公司目前正「从我们自 2006 年以来实施的网络架构原则中,从我们的 3G 和 4G 网络核心提取华为设备」. 英国电信已经不 ...