学习windows编程 day4 之 多边矩形填充
#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 之 多边矩形填充的更多相关文章
- 学习windows编程 day4 之 绘制随机矩形和peekMessage
#include <windows.h> #include <strsafe.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT messa ...
- 学习windows编程 day4 之 矩形的操作
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...
- 学习windows编程 day4 之视口和窗口
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...
- 学习windows编程 day4 之 盯裆猫
写着写着就困了.... 看这些测量数据就算了,是对各种函数的练习 #include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT ...
- 学习windows编程 day4 之 设置画刷
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...
- 学习windows编程 day4 之 自定义映射
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...
- 学习windows编程 day4 之 映射模式
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...
- 有一定基础的 C++ 学习者该怎样学习 Windows 编程?
人的心理有个奇异的特性:一项知识一旦学会之后,学习过程中面临的困惑和不解非常快就会忘得干干净净,似乎一切都是自然而然,本来就该这种.因此,关于「怎样入门」这类问题,找顶尖高手来回答,未必能比一个刚入门 ...
- 我为什么学习Windows编程
前一段时间在看TCP/IP,在图书馆里面找了不少的书,其中有几本书还是不错的.比如: <Windows网络与通信程序设计(第二版)> 王艳平著 <WinSock网络编程经络> ...
随机推荐
- ASP.NET Forms验证
/// <summary> /// 执行用户登录操作 /// </summary> /// <param name="config">授权配置信 ...
- spring-web-4.3.3与spring-webmvc-4.3.3的区别
spring-web-4.3.3 http(http协议的实现类)和web包(应用,上下文,会话,cookies,过滤器等等) spring-webmvc-4.3.3 主要是一些view层的核心封装, ...
- 推荐一个php7+ mongodb三方类
373 次阅读 · 读完需要 8 分钟 5 由于项目需要,把项目升级到了php7.但是升级了之后发现mongo扩展不能用了.php7.0以上只支持mongodb扩展了.而mongodb扩展的驱 ...
- 属性动画总结(Property Animation)
一.概述 属性动画可以作用在View的属性上,对属性进行修改,而且不要求对应的属性一定是有显示效果的. 二.属性动画的实现方式 1.基础的类Animator Animator是一个抽象类,是属性动画的 ...
- python之列表操作(list)
# 列表操作功能汇总 print("列表操作功能汇总") list_demo = ['first', 'second', 'thrid', 'fourth'] # 复制list_d ...
- Highcharts之折线图
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- unorder_map 自定义KEY
1. boost::unorder_map 实现自定义KEY // boostLibTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" ...
- 使用TortoiseSVN创建版本库
1. 使用TortoiseSVN创建版本库 在SVN中,为了便于创建分支和标签,我们习惯于将Repository版本库的结构布置为:/branches,/tags,/trunk.分别代表分支,标签以及 ...
- BZOJ2214[Poi2011]Shift——模拟
题目描述 Byteasar bought his son Bytie a set of blocks numbered from to and arranged them in a row in a ...
- MT【230】一道代数不等式
设$a,b,c>0,$满足$a+b+c\le abc$证明:$\dfrac{1}{\sqrt{1+a^2}}+\dfrac{1}{\sqrt{1+b^2}}+\dfrac{1}{\sqrt{1+ ...