学习windows编程 day4 之 盯裆猫
写着写着就困了....
看这些测量数据就算了,是对各种函数的练习
#include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); 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,
,
,
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 int cxClient, cyClient;
static HPEN hPen,hOldPen;
static HBRUSH hBrush, hOldBrush; POINT apt[];
switch (message)
{
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
//1.先绘制两条虚线
//设置画笔
hPen = CreatePen(PS_DOT, 0.1, RGB(,,));
hOldPen=SelectObject(hdc, hPen);
//开始绘制
MoveToEx(hdc, cxClient / , , NULL);
LineTo(hdc, cxClient / , cyClient); MoveToEx(hdc, , cyClient/, NULL);
LineTo(hdc, cxClient, cyClient/);
//还原画笔
SelectObject(hdc, hOldPen); //2.绘制头部(直径240)蓝色
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc,hBrush);
Ellipse(hdc, cxClient / - , cyClient / - , cxClient/ + , cyClient/ + );
SelectObject(hdc, hOldBrush); //3.画脸(和头内切直径200)白色
//hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
//默认是白色,已经替换回来了
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / + ); //4.画眼睛(长60,宽50)
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / , cyClient / - );
Ellipse(hdc, cxClient / + , cyClient / - , cxClient / , cyClient / - ); //5.画眼珠
hBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
hOldBrush = SelectObject(hdc, hBrush); Ellipse(hdc, cxClient / - , cyClient / - , cxClient / - , cyClient / - );
Ellipse(hdc, cxClient / + , cyClient / - , cxClient / + , cyClient / - ); SelectObject(hdc, hOldBrush);
//6.加上眼白
hOldBrush = SelectObject(hdc, GetStockObject(WHITE_BRUSH));
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / - , cyClient / - );
Ellipse(hdc, cxClient / + , cyClient / - , cxClient / + , cyClient / - ); SelectObject(hdc, hOldBrush);
//7.加上鼻子
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush=SelectObject(hdc, hBrush);
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / - );
SelectObject(hdc, hOldBrush); //8.加上鼻子到嘴上的线
MoveToEx(hdc, cxClient / , cyClient / - ,NULL);
LineTo(hdc, cxClient / , cyClient/ - ); //9.画上嘴巴
Arc(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient/ - ,
cxClient / - , cyClient / - , cxClient / + , cyClient / - ); //10.画上胡须
//左
MoveToEx(hdc, cxClient / - , cyClient / - , NULL);
LineTo(hdc, cxClient / - , cyClient / - );
MoveToEx(hdc, cxClient / - , cyClient / - , NULL);
LineTo(hdc, cxClient / -, cyClient / -);
MoveToEx(hdc, cxClient / - , cyClient / - , NULL);
LineTo(hdc, cxClient / - , cyClient / - );
//右
MoveToEx(hdc, cxClient / + , cyClient / - , NULL);
LineTo(hdc, cxClient / + , cyClient / - );
MoveToEx(hdc, cxClient / + , cyClient / - , NULL);
LineTo(hdc, cxClient / + , cyClient / - );
MoveToEx(hdc, cxClient / + , cyClient / - , NULL);
LineTo(hdc, cxClient / + , cyClient / - ); //11.画身体,矩形蓝色
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
Rectangle(hdc, cxClient / - , cyClient / , cxClient / + , cyClient / + );
SelectObject(hdc, hOldBrush); //12.画肚子
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / + );
//覆盖多余长度
hPen = CreatePen(PS_SOLID, , RGB(, , ));
hOldPen = SelectObject(hdc, hPen);
Arc(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / + , cxClient / + , cyClient / , cxClient / - , cyClient / );
SelectObject(hdc, hOldPen);
//13.项圈
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
RoundRect(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / + , , );
SelectObject(hdc, hOldBrush);
//14.铃铛
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
Ellipse(hdc, cxClient / - , cyClient / , cxClient / + , cyClient / +); //15.铃铛上的线
RoundRect(hdc, cxClient / - , cyClient / + , cxClient / + , cyClient / + , , );
SelectObject(hdc, hOldBrush);
//16.铃铛孔和线
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
Ellipse(hdc, cxClient / - , cyClient / + , cxClient / + , cyClient / + );
MoveToEx(hdc, cxClient / , cyClient / + , NULL);
LineTo(hdc, cxClient / , cyClient / + );
SelectObject(hdc, hOldBrush);
//17.口袋
Pie(hdc, cxClient / - , cyClient / , cxClient / + , cyClient / + , cxClient / - , cyClient / + , cxClient / + , cyClient / + ); //18.画腿(用扇形挡住)
Pie(hdc, cxClient / - , cyClient / + , cxClient / + , cyClient / + , cxClient / + , cyClient / + , cxClient / - , cyClient / + );
hPen = CreatePen(PS_SOLID, , RGB(, , ));
hOldPen = SelectObject(hdc, hPen);
MoveToEx(hdc, cxClient / - , cyClient / + , NULL);
LineTo(hdc, cxClient / + , cyClient / + );
SelectObject(hdc, hOldPen); //19.画脚
Ellipse(hdc, cxClient / - , cyClient / + , cxClient / - , cyClient / + );
Ellipse(hdc, cxClient / + , cyClient / + , cxClient / + , cyClient / + ); //20两个手
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
apt[].x = cxClient / - ;
apt[].y = cyClient / + ;
apt[].x = cxClient / - ;
apt[].y = cyClient / + ;
apt[].x = cxClient / - ;
apt[].y = cyClient / + ;
apt[].x = cxClient / - ;
apt[].y = cyClient / + ;
Polygon(hdc, apt, );
SelectObject(hdc, hOldBrush);
Ellipse(hdc, cxClient / - , cyClient / + , cxClient / - , cyClient / + ); hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
apt[].x = cxClient / + ;
apt[].y = cyClient / + ;
apt[].x = cxClient / + ;
apt[].y = cyClient / + ;
apt[].x = cxClient / + ;
apt[].y = cyClient / + ;
apt[].x = cxClient / + ;
apt[].y = cyClient / + ;
Polygon(hdc, apt, );
SelectObject(hdc, hOldBrush);
Ellipse(hdc, cxClient / + , cyClient / + , cxClient / + , cyClient / + ); //画线覆盖多余线条
hPen = CreatePen(PS_SOLID, , RGB(,,));
hOldPen = SelectObject(hdc, hPen); MoveToEx(hdc, cxClient / -, cyClient / +, NULL);
LineTo(hdc, cxClient / - , cyClient / + ); MoveToEx(hdc, cxClient / + , cyClient / + , NULL);
LineTo(hdc, cxClient / + , cyClient / + ); SelectObject(hdc, hOldPen); EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
//销毁创建的画笔对象
DeleteObject(hPen);
PostQuitMessage();
return ;
} 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> #include <math.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT message, ...
- 学习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网络编程经络> ...
随机推荐
- ACL访问控制
/etc/squid/squid.conf 定义语法: acl aclname acltype string acl aclname acltype "file" s ...
- squid反向代理
反向代理的作用是就爱那个网站中的静态自原本地化.也就是将一部分本应该有原是服务器处理的请求交给 Squid 缓存服务处理 编辑 Squid 服务程序的配置文件*(正向代理与反向代理不能同时使用,) ...
- opencv学习笔记(四)
ROI---设定感兴趣的区域(region of interest) 定义: Mat imageROI; //方法一:通过Rect指定矩形区域 imageROI=image(Rect(500,250, ...
- Oracle Gateways 方式创建dblink 连接 SQLSERVER数据库
1. 安装多次 发现在同一个机器上面总出问题,所以建议找一个没有安装oracle的机器上面进行安装gateways 2. 下载oracle gateways 并且解压缩, 下载地址详情见官网. 下载的 ...
- python 协程库gevent学习--gevent数据结构及实战(三)
gevent学习系列第三章,前面两章分析了大量常用几个函数的源码以及实现原理.这一章重点偏向实战了,按照官方给出的gevent学习指南,我将依次分析官方给出的7个数据结构.以及给出几个相应使用他们的例 ...
- Java之修改文件内容:字符串逐行替换
依赖包: <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</a ...
- BZOJ3505 CQOI2014数三角形(组合数学)
显然可以用总方案数减掉三点共线的情况.对于三点共线,一个暴力的做法是枚举起点终点,其间整点数量即为横纵坐标差的gcd-1.这样显然会T,注意到起点终点所形成的线段在哪个位置是没有区别的,于是枚举线段算 ...
- BZOJ2001 HNOI2010城市建设(线段树分治+LCT)
一个很显然的思路是把边按时间段拆开线段树分治一下,用lct维护MST.理论上复杂度是O((M+Q)logNlogQ),实际常数爆炸T成狗.正解写不动了. #include<iostream> ...
- Laravel表单传值
仔细阅读过Laravel官方文档的就不用看啦~ 整理下之前遇到的关于Laravel表单的一些小问题 表单传值无法传过去,因为laravel做了表单的防护 只需要将{{ csrf_field() }}放 ...
- P3312 [SDOI2014]数表
啊啊啊我昨天怎么没写题解wwww 补昨日题解... 题目链接 : https://www.luogu.org/problemnew/show/P3312 也是莫反 我要把fft留到今天写 [和zyn小 ...