在看雪论坛上看到的一个帖子,很喜欢,转载一下。原文地址:http://bbs.pediy.com/showthread.php?t=138630
哆啦A梦是画出来的,不知道作者算这些坐标位置算了多久,真的很犀利。记得原来看《Windows程序设计》的时候,每次看到GDI都不是很理解,也没有仔细去研究。现在编程也很少与GDI打交道,还是等以后有空了在深入了解一下吧。把这个代码转载一份到博客,以后再回头研究一下。顺便贴一下程序运行后的截图:(很酷吧~~~)
字数补丁~代码疯子~程序人生~字数补丁~代码疯子~程序人生~字数补丁~代码疯子~程序人生

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// 请以C语言后缀(*.c)保存文件
#include <windows.h>
#include <math.h>
 
#define NUM 1000
#define TWOPI (2 * 3.1415926)
 
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
int cx, cy ;
cx = GetSystemMetrics(SM_CXSCREEN) / 2 - 200;
cy = GetSystemMetrics(SM_CYSCREEN) / 2 - 200;
 
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (/*GRAY*/WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
 
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
 
RegisterClass (&wndclass);
 
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
cx, // initial x position
cy, // initial y position
400, // initial x size
400, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
 
ShowWindow (hwnd, iCmdShow) ;
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 ;
static int cxClient, cyClient ;
HBRUSH hBrush ;
int i ;
POINT apt[NUM],
leftHand[] = {
cxClient / 2 - 60, cyClient / 2 - 20,
cxClient / 2 - 100, cyClient / 2 + 10,
cxClient / 2 - 100, cyClient / 2 + 30,
cxClient / 2 - 60, cyClient / 2 + 10
},
rightHand[] = {
cxClient / 2 + 60, cyClient / 2 - 20,
cxClient / 2 + 100, cyClient / 2 + 10,
cxClient / 2 + 100, cyClient / 2 + 30,
cxClient / 2 + 60, cyClient / 2 + 10
} ;
 
switch (message)
{
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) + 120;
return 0 ;
 
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
 
Ellipse (hdc, cxClient / 2 - 70, cyClient / 2 + 55, cxClient / 2, cyClient / 2 + 85) ; //脚
Ellipse (hdc, cxClient / 2, cyClient / 2 + 55, cxClient / 2 + 70, cyClient / 2 + 85) ;
 
hBrush = CreateSolidBrush (RGB (100, 150, 255)) ;
SelectObject (hdc, hBrush) ;
 
// Rectangle (hdc, cxClient / 2 - 60, cyClient / 2 - 60, cxClient / 2 +60, cyClient / 2 + 70); //身体
RoundRect (hdc, cxClient / 2 - 60, cyClient / 2 - 60, cxClient / 2 + 60, cyClient / 2 + 70, 50, 20);
 
DeleteObject (hBrush) ;
 
hBrush = GetStockObject (WHITE_BRUSH) ;
SelectObject (hdc, hBrush) ;
 
Ellipse (hdc, cxClient / 2 - 50, cyClient / 2 - 50, cxClient / 2 + 50, cyClient / 2 + 50) ; //肚子部分
 
hBrush = CreateSolidBrush (RGB (100, 150, 255)) ;
SelectObject (hdc, hBrush) ;
 
Ellipse (hdc, cxClient / 2 - 100, cyClient / 2 - 220, cxClient / 2 +100, cyClient / 2 - 20) ; //头部
 
DeleteObject (hBrush) ;
 
hBrush = GetStockObject (WHITE_BRUSH) ;
SelectObject (hdc, hBrush) ;
 
Ellipse (hdc, cxClient / 2 - 85, cyClient / 2 - 170, cxClient / 2 + 85, cyClient / 2 - 20) ; //脸部
Ellipse (hdc, cxClient / 2 - 40, cyClient / 2 - 190, cxClient / 2, cyClient / 2 - 140 ) ; //眼眶左
Ellipse (hdc, cxClient / 2, cyClient / 2 - 190, cxClient / 2 + 40, cyClient /2 - 140) ; //眼眶右
 
hBrush = GetStockObject (BLACK_BRUSH) ;
SelectObject (hdc, hBrush) ;
 
Ellipse (hdc, cxClient / 2 - 15, cyClient / 2 - 155, cxClient / 2 -10, cyClient / 2 - 150) ; //眼睛左
Ellipse (hdc, cxClient / 2 + 10, cyClient / 2 - 155, cxClient / 2 + 15, cyClient / 2 -150) ; //眼睛右
 
DeleteObject (hBrush) ;
 
hBrush = CreateSolidBrush (RGB (255, 0, 0)) ;
SelectObject (hdc, hBrush) ;
 
Ellipse (hdc, cxClient / 2 - 10, cyClient / 2 - 150, cxClient / 2 +10, cyClient / 2 -130) ; //鼻子
 
MoveToEx (hdc, cxClient / 2, cyClient / 2 -130, NULL) ;
LineTo (hdc, cxClient / 2, cyClient / 2 - 60) ;
 
MoveToEx (hdc, cxClient / 2 - 40, cyClient / 2 - 75, NULL); //嘴
for (i = 0; i < NUM / 2; i++)
{
apt[i].x = cxClient / 2 - 40 + i * 160 / NUM ;
apt[i].y = cyClient / 2 - 75 +(int) (30 * sin (TWOPI * i / NUM)) / 2 ;
LineTo(hdc, apt[i].x, apt[i].y) ;
}
 
MoveToEx (hdc, cxClient / 2 - 60, cyClient / 2 - 140, NULL) ; //胡须
LineTo (hdc, cxClient / 2 - 20, cyClient / 2 - 120) ;
 
MoveToEx (hdc, cxClient / 2 - 60, cyClient / 2 - 110, NULL) ;
LineTo (hdc, cxClient / 2 - 20, cyClient / 2 - 110) ;
 
MoveToEx (hdc, cxClient / 2 - 60, cyClient / 2 - 80, NULL);
LineTo (hdc, cxClient / 2 - 20, cyClient / 2 - 100) ;
 
MoveToEx (hdc, cxClient / 2 + 60, cyClient / 2 -140, NULL) ;
LineTo (hdc, cxClient / 2 + 20, cyClient / 2 - 120) ;
 
MoveToEx (hdc, cxClient / 2 + 60, cyClient / 2 - 110, NULL) ;
LineTo (hdc, cxClient / 2 +20, cyClient / 2 - 110) ;
 
MoveToEx (hdc, cxClient / 2 +60, cyClient / 2 - 80, NULL) ;
LineTo (hdc, cxClient / 2 + 20, cyClient / 2 - 100) ;
 
hBrush = GetStockObject (WHITE_BRUSH) ; //口袋
SelectObject (hdc, hBrush) ;
 
Chord (hdc, cxClient / 2 - 40, cyClient / 2 - 40, cxClient / 2 + 40, cyClient / 2 +40,
cxClient / 2 - 40, cyClient / 2 + 10, cxClient / 2 +40, cyClient / 2 + 10) ;
 
 
 
hBrush = CreateSolidBrush (RGB (255, 0, 0)); //脖子上的套圈
SelectObject (hdc, hBrush) ;
 
RoundRect (hdc, cxClient / 2 - 70, cyClient / 2 - 40, cxClient / 2 + 70, cyClient / 2 - 20, 20, 20);
 
DeleteObject (hBrush) ;
 
hBrush = CreateSolidBrush (RGB (100, 150, 255)) ; //手臂
SelectObject (hdc, hBrush) ;
 
SetPolyFillMode (hdc, WINDING) ;
Polygon (hdc, leftHand, 4) ;
 
SetPolyFillMode (hdc, WINDING) ;
Polygon (hdc, rightHand, 4) ;
 
DeleteObject (hBrush) ;
 
hBrush = GetStockObject (WHITE_BRUSH) ; //手
SelectObject (hdc, hBrush) ;
 
Ellipse (hdc, cxClient / 2 - 115, cyClient / 2 + 5, cxClient / 2 - 85, cyClient / 2 + 35) ;
Ellipse (hdc, cxClient / 2 + 115, cyClient / 2 + 5, cxClient / 2 + 85, cyClient / 2 + 35) ;
 
hBrush = CreateSolidBrush (RGB (250, 255, 150)) ; //铃铛
SelectObject (hdc, hBrush) ;
 
Ellipse (hdc, cxClient / 2 - 10, cyClient / 2 - 35, cxClient / 2 + 10, cyClient / 2 - 15) ;
 
DeleteObject (hBrush) ;
 
hBrush = GetStockObject (BLACK_BRUSH) ;
SelectObject (hdc, hBrush) ;
 
Ellipse (hdc, cxClient / 2 - 4, cyClient / 2 - 29, cxClient / 2 + 4, cyClient / 2 - 21) ;
 
MoveToEx (hdc, cxClient / 2, cyClient / 2 - 25, NULL) ;
LineTo (hdc, cxClient / 2, cyClient / 2 - 15) ;
 
EndPaint (hwnd, &ps) ;
return 0 ;
 
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
 
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

http://www.programlife.net/using-windows-programming-paint-doraemon.html

Windows程序设计画图实现哆啦A梦的更多相关文章

  1. Android用canvas画哆啦A梦

    先上图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...

  2. Scratch 3 矢量编辑器——“临摹”一只哆啦A梦

    利用Scratch来制作一些小作品,常常需要到网上去找图片,而网上下载的图片一般都是位图,往往存在两个问题: 图片不够清晰,当图片放大后会出现"马赛克"现象: 图片中存在不必要的背 ...

  3. [css]我要用css画幅画(七) - 哆啦A梦

    接着之前的[css]我要用css画幅画(六),今天画的有所不同,画的是哆啦A梦,我们小时候对他的称呼其实是小叮当机器猫. (PS:这次我要做的事情,很多人已经做过,这并不是什么创新,我只是在学习并记录 ...

  4. 创建【哆啦A梦】风格字体

    学习canvas,为作画.对于一个毫无逻辑思维的人简直遭罪啊~想象坐标坐标坐标啊- - 好啦言归正传,基于本月16号,在春熙路IFS展出120只哆啦a梦,以及canvas的作用,在此介绍一种PS的美化 ...

  5. 哆啦A梦 canvas

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Windows 程序设计

    一.Win32 API /******************************************************************** created: 2014/04/1 ...

  7. 关于《Windows程序设计(第五版)》中一个实例程序的疑问

    最近一直在看Charlse Petzold的<Windows程序设计>,作为一个新得不能再新的新手,只能先照着书的抄抄源码了,之前的例子一直都很正常,但昨天遇到一个很诡异的BUG. 先看实 ...

  8. windows 程序设计自学:添加图标资源

    #include <windows.h> #include "resource.h" LRESULT CALLBACK MyWndProc( HWND hwnd, // ...

  9. windows程序设计笔记

    2014.05.06 新建一个visual C++ -- 常规 -- 空白 的项目,用.c后缀名指定这是一个用C语言来写的windows项目.和C语言的hellworld程序做了一个比较,按照wind ...

随机推荐

  1. Android菜鸟的成长笔记(27)——SurfaceView的使用

    前面有关自定义View中进行了绘图,但View的绘图机制存在如下缺陷: 1.View缺乏双缓冲机制. 2.当程序需要更新View上的图像时,程序必须重绘View上显示的整张图片. 3.新线程无法直接更 ...

  2. 忙里偷闲( ˇˍˇ )闲里偷学【C语言篇】——(8)枚举、补码

    一.枚举 # include <stdio.h> enum WeekDay //定义了一个数据类型(值只能写以下值) { MonDay, TuesDay, WednesDay, Thurs ...

  3. nodejs版本号更新问题:express不是内部或外部命令

    版本号更新后,我们使用熟悉的npm install -g express命令安装,可是,成功安装之后竟然提示express不是内部或外部命令. nodejs小问题:[1]express不是内部或外部命 ...

  4. [Angular] Difference between Providers and ViewProviders

    For example we have a component: class TodoList { private todos: Todo[] = []; add(todo: Todo) {} rem ...

  5. Android中实现iPhone开关

    前一段时间在做项目的时候遇到了一个问题,美工在设计的时候设计的是一个iPhone中的开关,但是都知道Android中的Switch开关和IOS中的不同,这样就需要通过动画来实现一个iPhone开关了. ...

  6. 【codeforces 791A】Bear and Big Brother

    [题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼 ...

  7. spark 基于key排序的wordcount

    java /** * 根据单词次数排序的wordcount * @author Tele * */ public class SortWordCount { private static SparkC ...

  8. zookeeper 分布式安装/配置/启动

    版本3.4.10,已提前配置好jdk 三台主机:hadoop002,hadoop003.hadoop004 1.配置 将zookeeper-3.4.10.tar.gz解压后进入zookeeper-3. ...

  9. CentOS7 下的mysql安装与配置

    之前虽然也安装过多次mysql,但每次都会遇到各种小问题,这次记录下来,以备后查. 首先是下载与安装 # wget http://dev.mysql.com/get/mysql-community-r ...

  10. numpy 代码优化(一)—— 常见手段

    选择使用 numpy 库的应有之义就在于:应当以矢量化的方式(vectorized operations)来避免迭代操作(iterations),numpy 下的迭代操作执行起来十分耗时. impor ...