学习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网络编程经络> ...
随机推荐
- 2017[BUAA软工]第0次个人作业
第一部分:结缘计算机 1.你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢? ●其实填写志愿之前并不知道要学什么专业,当初选择计算机是因为计算机就业前景好.方向多.计算机应用的领域无处不在, ...
- Comparison of Static Code Analysis Tools for Java
http://www.sw-engineering-candies.com/blog-1/comparison-of-findbugs-pmd-and-checkstyle https://stack ...
- eclipse没有(添加)”Dynamic Web Project”选项的方法
https://www.cnblogs.com/longronglang/p/7156383.html(copy) help->install new software web - http:/ ...
- Angular $cookieStore简单应用
angular.module('cookieStoreExample', ['ngCookies']) .controller('ExampleController', ['$cookieStore' ...
- Nginx PRECONTENT try_files指令
L:61 try_fiels指令 syntax : try_files file ... uri;=code //可以是多个文件 context : server,location; locatio ...
- BZOJ2819Nim——树链剖分+线段树+Nim游戏
题目描述 著名游戏设计师vfleaking,最近迷上了Nim.普通的Nim游戏为:两个人进行游戏,N堆石子,每回合可以取其中某一堆的任意多个,可以取完,但不可以不取.谁不能取谁输.这个游戏是有必胜策略 ...
- day10 局部变量 全局变量 作用域前奏
规则命名以及基本介绍 name="LHF" # 顶头写的全局都可以调用的就是全局变量,命名规则要求大写全局变量 def chang_name(): # global name # ...
- Inside JVM 内存模型
Inside JVM 内存模型 来源 原文:https://blog.csdn.net/silentbalanceyh/article/details/4661230 参考:IBM开发中心文档,&l ...
- Linux开机自动挂载存储的两种方式
登录服务器,给查看了下,发现确实是没有自动加载,df -h只能显示本地硬盘的分区,fdisk -l 还是能看到存储空间,这说明这个服务器连接存储是木有问题的. 输入history | grep mou ...
- 自学Linux Shell3.1-帮助命令man
点击返回 自学Linux命令行与Shell脚本之路 3.1-帮助命令man 1.man命令概述 默认bash shell提示符是美元符号($),这个符号表明shell在等待用户输入. Linux ma ...