>_<:introduce the functions of define\create\use pen and brush to draw all kinds of line and some graphs.

>_<!following 2 files are the same with the previous and file main.cpp has some changes.

  1. //{{NO_DEPENDENCIES}}
  2. // Microsoft Visual C++ generated include file.
  3. // Used by FE.RC
  4. //
  5. #define IDR_MAINFRAME 128
  6. #define IDD_FE_DIALOG 102
  7. #define IDD_ABOUTBOX 103
  8. #define IDS_APP_TITLE 103
  9. #define IDM_ABOUT 104
  10. #define IDM_EXIT 105
  11. #define IDS_HELLO 106
  12. #define IDI_FE 107
  13. #define IDI_SMALL 108
  14. #define IDC_FE 109
  15. #define IDC_MYICON 2
  16. #define IDC_STATIC -1
  17. // Next default values for new objects
  18. //
  19. #ifdef APSTUDIO_INVOKED
  20. #ifndef APSTUDIO_READONLY_SYMBOLS
  21.  
  22. #define _APS_NEXT_RESOURCE_VALUE 129
  23. #define _APS_NEXT_COMMAND_VALUE 32771
  24. #define _APS_NEXT_CONTROL_VALUE 1000
  25. #define _APS_NEXT_SYMED_VALUE 110
  26. #endif
  27. #endif

resourse.h ID定义文件

  1. // stdafx.h : include file for standard system include files,
  2. // or project specific include files that are used frequently, but
  3. // are changed infrequently
  4. //
  5.  
  6. #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
  7. #define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
  8.  
  9. #if _MSC_VER > 1000
  10. #pragma once
  11. #endif // _MSC_VER > 1000
  12.  
  13. #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
  14.  
  15. // Windows Header Files:
  16. #include <windows.h>
  17.  
  18. // C RunTime Header Files
  19. #include <stdlib.h>
  20. #include <malloc.h>
  21. #include <memory.h>
  22. #include <tchar.h>
  23.  
  24. // Local Header Files
  25.  
  26. // TODO: reference additional headers your program requires here
  27.  
  28. //{{AFX_INSERT_LOCATION}}
  29. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  30.  
  31. #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)

StdAfx.h 各种头文件包含

main.cpp

  1. #include "stdafx.h"
  2. #include "resourse.h"
  3.  
  4. #define MAX_LOADSTRING 100
  5.  
  6. // Global Variables:
  7. HINSTANCE hInst; // current instance
  8. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  9. TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
  10. HPEN hPen[]; //以下四行是画笔及画刷对象数组声明
  11. HBRUSH hBru[];
  12. int sPen[]={PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL,PS_INSIDEFRAME};//前3个基本型(实、长间、短间)可以组合;
  13. int sBru[]={HS_VERTICAL,HS_HORIZONTAL,HS_CROSS,HS_DIAGCROSS,HS_FDIAGONAL,HS_BDIAGONAL};//横、竖、格、斜格、↘、↗)
  14. HWND hWnd;
  15. HDC hdc;
  16. // Foward declarations of functions included in this code module:
  17. ATOM MyRegisterClass(HINSTANCE hInstance);
  18. BOOL InitInstance(HINSTANCE, int);
  19. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  20. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  21. void MyPaint(HDC hdc);
  22. //========================================================================================
  23. int APIENTRY WinMain(HINSTANCE hInstance,
  24. HINSTANCE hPrevInstance,
  25. LPSTR lpCmdLine,
  26. int nCmdShow)
  27. {
  28. // TODO: Place code here.
  29. MSG msg;
  30.  
  31. MyRegisterClass(hInstance);//调用函数向系统注册窗口类别,输入参数hInstance是目前运行程序的对象代码;
  32.  
  33. // 调用InitInstance函数,进行初始化操作;
  34. if (!InitInstance (hInstance, nCmdShow))
  35. {
  36. return FALSE;
  37. }
  38.  
  39. // 消息循环(通过消息循环来获取信息,
  40. //进行必要的键盘信息转换而后将控制权交给操作系统,
  41. //有操作系统决定哪个程序的消息处理函数处理消息
  42. while (GetMessage(&msg, NULL, , )) //获取程序消息
  43. {
  44. TranslateMessage(&msg);//转换伪码及字符
  45. DispatchMessage(&msg);//将控制权交给系统,再有系统决定负责处理消息的程序;
  46. }
  47.  
  48. return msg.wParam;
  49. }
  50. //=====================================================================================
  51.  
  52. //=============================================================================================
  53. //在建立程序窗口实体之前,必须先定义一个窗口类别,其中包含所要建立窗口的信息,
  54. //并向系统注册,这里的MyRegisterClass函数就是进行定义及注册窗口类别的函数。
  55. //==============================================================================================
  56. ATOM MyRegisterClass(HINSTANCE hInstance)
  57. {
  58. WNDCLASSEX wcex; //申请一个窗口类别“WNDCLASSEX”和结构”wcex“
  59. //--------------------------------------------------------------
  60. //定义vcex结构的各项信息,其中设定信息处理函数(lpfnWndProc)
  61. //为WNDPROC,类别名称为(lpszClassName)为”fe";
  62. //--------------------------------------------------------------
  63. wcex.cbSize = sizeof(WNDCLASSEX);
  64.  
  65. wcex.style = CS_HREDRAW | CS_VREDRAW;
  66. wcex.lpfnWndProc = (WNDPROC)WndProc;
  67. wcex.cbClsExtra = ;
  68. wcex.cbWndExtra = ;
  69. wcex.hInstance = hInstance;
  70. wcex.hIcon = NULL;
  71. wcex.hCursor = NULL;
  72. wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
  73. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+);
  74. wcex.lpszMenuName = NULL;
  75. wcex.lpszClassName = "fe";
  76. wcex.hIconSm = NULL;
  77.  
  78. return RegisterClassEx(&wcex);//调用RegisterClassEx函数注册类别,返回一个“ATOM"形态的字符串
  79. //此字符串即为类别名称”fe";
  80. }
  81. //============================================================================================
  82.  
  83. //============================================================================================
  84. //按照前面所定义的窗口类别来建立并显示实际的程序窗口
  85. //============================================================================================
  86. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  87. {
  88.  
  89. int i;
  90.  
  91. hInst = hInstance; // 把instance handle 储存在全局变量中;
  92.  
  93. hWnd = CreateWindow("fe","绘图窗口",WS_OVERLAPPEDWINDOW,
  94. CW_USEDEFAULT, , CW_USEDEFAULT, , NULL, NULL, hInstance, NULL);
  95. //-----------------------------------------------
  96. //调用CreateWindow函数来建立一个窗口对象
  97. //第一个参数就是窗口建立依据的类别名称
  98. //-----------------------------------------------
  99. if (!hWnd)
  100. {
  101. return FALSE;
  102. }
  103. //------------------------------------------------
  104. //设定窗口的位置及窗口的大小,然后绘制显示在设备上
  105. //-------------------------------------------------
  106. MoveWindow(hWnd,,,,,true);//位置及大小
  107. ShowWindow(hWnd, nCmdShow);//改定窗口显示时的状态
  108. UpdateWindow(hWnd);//将窗口绘制在显示设备上
  109.  
  110. //--------------------------------------------------
  111. //循环建立各种画笔与画刷
  112. //--------------------------------------------------
  113. for(i=;i<=;i++)
  114. {
  115. hPen[i]=CreatePen(sPen[i],,RGB(,,));//sPen[]笔型;粗细;颜色
  116. if(i==)hBru[i]=CreateSolidBrush(RGB(,,));//i=6时调用CreateSolidBrush()函数建立单色笔
  117. else hBru[i]=CreateHatchBrush(sBru[i],RGB(,,));//i!=6时;根据sBru[]阴影刷
  118. }
  119.  
  120. hdc=GetDC(hWnd);//取得窗口DC;
  121.  
  122. SetTimer(hWnd,,,NULL);
  123. MyPaint(hdc);//在DC窗口出现时画图
  124.  
  125. return TRUE;
  126. }
  127. //============================================================================================
  128.  
  129. //============================================================================================
  130. //自定义绘图函数(以格式画笔及画刷绘制线条与填充矩形)
  131. //============================================================================================
  132. void MyPaint(HDC hdc)
  133. {
  134. int i,x1,x2,y;//x1、x2、y坐标变量
  135.  
  136. for(i=;i<=;i++)//以7种不同画笔绘制线条
  137. {
  138. y=(i+)*;
  139.  
  140. SelectObject(hdc,hPen[i]);//选用画笔
  141. MoveToEx(hdc,,y,NULL);//移到线条起点//-----GDI两个画线函数
  142. LineTo(hdc,,y);//画线 ||-BOOL MoveToEx(HDC hdc,int x坐标,int y坐标,LPPOINT 目前坐标);
  143. } // ||-BOOL LineTo(HDC hdc,int x坐标,int y坐标);
  144.  
  145. x1=;
  146. x2=;
  147.  
  148. for(i=;i<=;i++)//以7种不同画刷填充矩形
  149. {
  150. SelectObject(hdc,hBru[i]);//选画刷
  151. Rectangle(hdc,x1,,x2,y);//画封闭矩形||-------绘制矩形函数
  152. x1+=; //------||-BOOL Rectangle(HDC hdc,int 矩形左上点x坐标,int 矩形左上点y坐标,int x,int y右下);
  153. x2+=;
  154. }
  155. }
  156. //============================================================================================
  157.  
  158. //============================================================================================
  159. //在前面定义类别的时候把WndProc定义为消息处理函数(当某些外部消息发生时,会按消息的类型
  160. //来决定该如何进行处理。此外该函数也是一个回叫函数(CALLBACK)(windows系统函数)每一个
  161. //程序都会接收信息,选择性接受、处理;
  162. //============================================================================================
  163. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  164. {
  165. PAINTSTRUCT ps;
  166.  
  167. int i;
  168.  
  169. switch (message) //判断消息类型
  170. {
  171. case WM_TIMER:
  172. MyPaint(hdc);
  173. break;
  174. case WM_PAINT: //窗口重绘制
  175. hdc = BeginPaint(hWnd, &ps);
  176. MyPaint(hdc);//窗口重绘开始时调用MyPaint()绘图
  177. EndPaint(hWnd, &ps);
  178. break;
  179. case WM_DESTROY: //处理窗口结束消息
  180. for(i=;i<=;i++)//窗口消息结束时删除GDI对象
  181. {
  182. DeleteObject(hPen[i]);
  183. DeleteObject(hBru[i]);
  184. }
  185. PostQuitMessage();
  186. ReleaseDC(hWnd,hdc);//释放所占DC;
  187. break;
  188. default:
  189. return DefWindowProc(hWnd, message, wParam, lParam);
  190. }
  191. return ;
  192. }
  193. //============================================================================================

[游戏模版3] Win32 画笔 画刷 图形的更多相关文章

  1. GDI+编程(画笔/画刷/路径/区域)

    构造Graphics对象 Graphics类是GDI+程序设计的核心,Graphics类能够完成大部分的绘图,文本输出,几何图形的填充及坐标系统的转换等各种操作.在功能上,它与GDI的设备环境(DC) ...

  2. [游戏模版2] Win32最小框架

    >_<:Just the minimum Win32  frame don't have any other special function. //{{NO_DEPENDENCIES}} ...

  3. [游戏模版18] Win32 五子棋

    >_<:Learning its AI logic. >_<:resource >_<:code: #include <windows.h> // C ...

  4. [游戏模版4] Win32 显示鼠标位置

    >_<:use MOUSE_MOVE message refresh the position information. >_<:use LOWORD(lParam) get ...

  5. [游戏模版5] Win32 折线 弧线

    >_<:first build some points put in poly1[],poly2[] and poly3[] in the function of InitInstance ...

  6. [游戏模版6] Win32 graph

    >_<:there in the MyPaint(...) function respectively use Ellipse(...) draw ellipse, use RoundRe ...

  7. [游戏模版7] Win32 最简单贴图

    >_<:this is the first using mapping. >_<:There will be introducing how to do: First load ...

  8. [游戏模版8] Win32 透明贴图

    >_<:The same with previous introduction. In the InitInstance fanction make a little change: &g ...

  9. [游戏模版9] Win32 半透明 图像处理

    >_<:Previous part we talk about how to map a transparent picture, and this time we will solve ...

随机推荐

  1. phpstorm

    9XVKERIY9F-eyJsaWNlbnNlSWQiOiI5WFZLRVJJWTlGIiwibGljZW5zZWVOYW1lIjoiYXNoZXIgY2hlbiIsImFzc2lnbmVlTmFtZ ...

  2. js 字符串转化成数字

    方法主要有三种 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后者把值转换成浮点数.只有 ...

  3. DIOCP之注册编码解码器与ClientContext

    FTcpServer.registerCoderClass(TIOCPStreamDecoder, TIOCPStreamEncoder);//注册编码器与解码器 FTcpServer.registe ...

  4. Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK fla

      转载于 http://blog.csdn.net/wike163/article/details/6678073    从一个Activity中要通过intent调出另一个Activity的话,需 ...

  5. Nginx配置配置文件nginx.conf的设置

    引用自:http://www.ha97.com/5194.html #定义Nginx运行的用户和用户组user www www; #nginx进程数,建议设置为等于CPU总核心数.worker_pro ...

  6. 算法与数据结构实验题6.4 order (二叉树)

    1.题目: 2.代码: #include<iostream> #include<algorithm> using namespace std; struct Node { in ...

  7. javascript 的事件--阻止冒泡

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  8. 小甲鱼python视频弟十一讲(课后习题)

    1.修改列表里的值 list1 = [,,[,,,[,,,,] list1[] = print(list1) list1[][][] = '?' print(list1) 2.列表的排序(sort) ...

  9. zabbix使用sendEmail发送邮件报警

    sendEmail是一个轻量级,命令行的SMTP邮件客户端.如果你需要使用命令行发送邮件,那么sendEmail是非常完美的选择:使用简单并且功能强大.这个被设计用在php.bashperl和web站 ...

  10. 谈谈Linux下动态库查找路径的问题

    学习到了一个阶段之后,就需要不断的总结.沉淀.清零,然后才能继续"上路".回想起自己当年刚接触Linux时,不管是用源码包编译程序,还是程序运行时出现的和动态库的各种恩恩怨怨,心里 ...