写着写着就困了....

看这些测量数据就算了,是对各种函数的练习

#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 之 盯裆猫的更多相关文章

  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> #include <math.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT message, ...

  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. atcoder A - Frog 1(DP)

    A - Frog 1 Time Limit: 2 sec / Memory Limit: 1024 MB Score : 100100 points Problem Statement There a ...

  2. 安装虚拟环境和Flask

    一.Flask 使用前准备 一. 安装及创建虚拟环境 1. 安装虚拟环境 win + R -> cmd -> pip install virtualenv -> 出现 Success ...

  3. Laravel - 1

    Laravel - 1 Laravel是一个很强大又非常优雅的php框架,但是Laravel的很多组件都是由社区协作的结果,Composer是php开发的一个依赖管理工具,但是墙把绝大多数的开发者堵在 ...

  4. js排序方法

    function swap(ary, x, y) { if (x === y) return let temp = ary[x] ary[x] = ary[y] ary[y] = temp } //生 ...

  5. 解决vmware与主机无法连通的问题

    我们选择NAT方式,来实现Ubuntu的静态IP地址配置. 打开VMware,在顶部依次选择:编辑 > 虚拟网路编辑器,打开虚拟网路编辑器:去掉VMnet0和VMnet1,只保留VMnet8.然 ...

  6. ADODataSet与ADOQuery的区别

    ADODataSet组件  此组件功能是非常强大的,通过ADODataset,可以直接与一个表进行联接,也可以执行SQL语句,还可以执行存储过程,可以说集ADOTable. ADOQuery.   A ...

  7. delphi简单单向字符串加密函数

    delphi用久了有的时候得给密码加密一下,简单点就行了,这个函数还是不错的. const XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$8 ...

  8. python之tkinter使用-文件系统遍历

    # tkinter:文件系统遍历 import tkinter as tk, os from time import sleep class DirList(object): def __init__ ...

  9. lvs逻辑卷详解

    管理磁盘空间对系统管理员来说是一件重要的日常工作.一旦磁盘空间耗尽就需要进行一系列耗时而又复杂的任务,以提升磁盘分区中可用的磁盘空间.它也需要系统离线才能处理.通常这种任务会涉及到安装一个新的硬盘.引 ...

  10. Educational Codeforces Round 8 B. New Skateboard

    题目链接:http://codeforces.com/problemset/problem/628/B 解题思路: 一个数最后两位数能被4整除那么这个数就能被4整除,而且题目还是连续的子序列,这就很简 ...