[游戏模版1] MFC最小框架(base function including)

>_<:Here are the template of mini-MFC include:

  • CPen,CBrush,Front,Paint Line and some other graph.

  • OnPaint message,OnLeftButtonDown message,you can through it know more

Hello.h


 1 #include<afxwin.h>
2 class CMyApp:public CWinApp
3 {
4 public:
5 virtual BOOL InitInstance();
6 };
7 class CMainWindow:public CFrameWnd
8 {
9 public:
10 CMainWindow();
11 protected:
12 afx_msg void OnPaint();
13 afx_msg void OnLButtonDown(UINT m_nFlags,CPoint point);
14 DECLARE_MESSAGE_MAP();
15 };

Hello.cpp


  1 #include<afxwin.h>
2 #include<math.h>
3 #include"Hello.h"
4 #define SEGMENTS 500
5 #define PI 3.1415926
6
7 int PenStyle[7]={PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL,PS_INSIDEFRAME};//实线\宽\窄\宽+窄\宽+2窄\没有\实线不外伸
8 int PenNum=0;
9 int BrushStye[6]={HS_BDIAGONAL,HS_FDIAGONAL,HS_CROSS,HS_HORIZONTAL,HS_DIAGCROSS,HS_VERTICAL};//45\135\90交叉\0\45交叉\90
10 int BrushNum=0;
11
12 CMyApp myApp;
13 //////////////////////////////////////////////
14 //CMyApp member function
15 BOOL CMyApp::InitInstance() //初始化函数
16 {
17 m_pMainWnd=new CMainWindow;
18 m_pMainWnd->ShowWindow(m_nCmdShow);
19 m_pMainWnd->UpdateWindow();
20 return TRUE;
21 }
22 /////////////////////////////////////////////
23 //CMainWindow message map and member function
24 BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd) //消息映射
25 ON_WM_PAINT()
26 ON_WM_LBUTTONDOWN()
27 END_MESSAGE_MAP()
28
29 CMainWindow::CMainWindow() //创建窗口
30 {
31 Create(NULL,_T("The Hello"),WS_OVERLAPPED,CRect(20,40,640,440));//CFrameWnd下的成员函数8个参数,6个默认
32 } //这个参数产生垂直滚动条
33
34 void CMainWindow::OnPaint()
35 {
36
37 CRect rect;
38 GetClientRect(&rect);
39
40 /*72点,Arial,并带有下拉阴影生成的“Hello MFC"
41 CFont font;
42 font.CreatePointFont(720,_T("Arial"));//创建72点,Arial字体
43
44 CPaintDC dc(this);
45 dc.SelectObject(&font);
46 dc.SetBkMode(TRANSPARENT);//背景模式 设为透明
47
48 CString string=_T("Hello MFC");
49
50 rect.OffsetRect(16,16);//从窗口中心向右向下偏移几个像素点的位置
51 dc.SetTextColor(RGB(192,192,192));
52 dc.DrawText(string,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
53
54 rect.OffsetRect(-16,-16);
55 dc.SetTextColor(RGB(0,0,0));
56 dc.DrawText(string,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);//单行、水平、竖直居中的文本
57 */
58
59 /*LOFGFONT 自定义字体 呈现出旋转效果
60 CPaintDC dc(this);
61 dc.SetViewportOrg(rect.Width()/2,rect.Height()/2);
62 dc.SetBkMode(TRANSPARENT);
63
64 for(int i=0;i<3600;i+=360){
65 LOGFONT lf;//自己创建一种字体
66 ::ZeroMemory (&lf,sizeof(lf));
67 lf.lfHeight=180; //26个像素点
68 lf.lfWeight=FW_BOLD; //粗黑
69 //lf.lfItalic=TRUE; //倾斜
70 lf.lfEscapement=i; //配合使用每次旋转36度
71 lf.lfOrientation=i;
72 ::lstrcpy(lf.lfFaceName,_T("Arial"));
73 CFont font;
74 font.CreatePointFontIndirect(&lf);
75
76 CFont* pOldFont=dc.SelectObject(&font);
77 dc.TextOutA(0,0,CString(_T("Hello,MFC")));
78 dc.SelectObject(pOldFont);
79 }
80 */
81 }
82
83 void CMainWindow::OnLButtonDown(UINT m_nFlags,CPoint point)//点击鼠标左键画图
84 {
85 //CClientDC dc(this);
86 CPaintDC dc(this);
87 CRect rect;
88 GetClientRect(&rect);
89 dc.Rectangle(rect);
90
91
92 //dc.SetViewportOrg(rect.Width()/2,rect.Height()/2);
93
94
95 //dc.SetROP2(R2_BLACK);//绘图模式:颜色操作;2.1.3
96 //dc.MoveTo(rect.left,rect.top);
97 //dc.LineTo(rect.right,rect.bottom);
98
99 //POINT aPoint[5]={0,0,0,100,100,100,100,0,0,0};
100 //dc.Polyline(aPoint,5); //将一系列点用线段连起来
101
102 //POINT bPoint[4]={0,100,100,100,100,0};
103 //dc.MoveTo(0,0);
104 //dc.PolylineTo(bPoint,4); //从当前位置开始将一系列的点用线段连起来,并将当前位置移折致折线的终点
105
106 //int nWidth=rect.Width(); //画正弦曲线
107 //int nHeight=rect.Height();
108
109 //CPoint aPoint[SEGMENTS];
110 //for(int i=0;i<SEGMENTS;i++){
111 // aPoint[i].x=(i*nWidth)/SEGMENTS;
112 // aPoint[i].y=(int)((nHeight/2)*(1-(sin((2*PI*i)/SEGMENTS))));
113 //}
114 //dc.Polyline(aPoint,SEGMENTS);
115
116 /*画笔的创建和加载
117 CPen cPen(PenStyle[(PenNum++)%7],1,RGB(192,0,0));//==cPen.CreatePen(...);
118 dc.SelectObject(&cPen);
119 CBrush cBrush(BrushStye[(BrushNum++)%6],RGB(255,0,0));
120 dc.SelectObject(&cBrush);
121 */
122
123 /*扩展笔____必须是通路
124 LOGBRUSH lb;
125 lb.lbStyle=BS_SOLID;
126 lb.lbColor=RGB(0,255,0);
127 CPen pen(PS_GEOMETRIC|PenStyle[(PenNum++)%7]|PS_ENDCAP_FLAT|
128 PS_JOIN_ROUND,3,&lb);
129 CPen* pOldPen=dc.SelectObject(&pen);
130 */
131
132
133 /*画刷原点
134 CPoint point(x1,y1); //矩形左上角的逻辑坐标
135 dc.LPtoDP(&point); //逻辑坐标转换成设备坐标
136 point.x %= 8;
137 point.y %= 8;
138 cBrush.UnrealizeObject();//允许画刷原点移动
139 dc.SetBrushOrg(point); //0~7之间
140 dc.SelectObject(&cBrush);
141 dc.Rectangle(x1,y1,x2,y2);
142 */
143
144
145 /*建立通路
146 dc.BeginPath();
147 dc.MoveTo(0,0);
148 dc.LineTo(100,200);
149 dc.LineTo(200,100);
150 dc.CloseFigure();
151 dc.EndPath();
152 dc.StrokePath();
153 */
154
155
156 /*ARC
157 CRect rect0(0,0,200,100);
158 CPoint cPoint1(0,0);
159 CPoint cPoint2(200,100);
160 dc.Rectangle(rect0);
161 dc.Arc(rect0,cPoint1,cPoint2);//外接矩形+从中心引出的两个边界线所夹的范围
162 dc.MoveTo(0,0);
163 dc.LineTo(200,100);
164
165 CRect rect1(0,102,200,202);
166 CPoint cPoint3(0,102);
167 CPoint cPoint4(200,202);
168 dc.Rectangle(rect1);
169 dc.ArcTo(rect1,cPoint3,cPoint4);
170 CPoint cPointNow=dc.GetCurrentPosition();//终点坐标
171 */
172
173 /*纳克
174 POINT aPoint1[4]={120,100,120,200,250,150,500,40};
175 POINT aPoint2[4]={120,100,50,350,250,200,500,40};
176 dc.PolyBezier(aPoint1,4);
177 dc.PolyBezier(aPoint2,4);
178 */
179
180
181
182 //dc.SetMapMode(MM_TEXT);//映射模式2.1.4 按比例缩放输出
183 //dc.Ellipse(0,0,100,100);//矩形内切圆(弧)
184 //dc.Ellipse(rect.right-100,rect.bottom-100,rect.right,rect.bottom);
185 //dc.Ellipse(point.x,point.y,point.x+100,point.y+100);//鼠标位置
186
187 //dc.SetMapMode(MM_ISOTROPIC);//可编程映射模式,自定义比例缩放(MM_ANISOTROPIC单位长度可以不同;MM_ISOTROPIC单位长度相同)
188 //dc.SetWindowExt(500,500); //设置窗口逻辑值为(0,0)到(500,500)
189 //dc.SetViewportExt(rect.Width(),rect.Height());
190 //dc.Ellipse(0,0,500,500);
191
192 }

[游戏模版1] MFC最小框架(base function including),布布扣,bubuko.com

时间: 2024-11-04 16:28:54

[游戏模版1] MFC最小框架(base function including)的相关文章

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

>_<:Just the minimum Win32  frame don't have any other special function. 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

[游戏学习28] MFC 时钟

>_<:这是一个时钟小程序 >_<:通过调用获得系统时间然后经过计算得出当前时间,然后再以3个圆环表示时分秒. >_<:TAO_CLOCK.h 1 class CMyApp : public CWinApp 2 { 3 public: 4 virtual BOOL InitInstance (); 5 }; 6 7 class CMainWindow : public CFrameWnd 8 { 9 protected: 10 11 12 int m_nPrevSeco

[游戏学习22] MFC 井字棋 双人对战

>_<:太多啦,感觉用英语说的太慢啦,没想到一年做的东西竟然这么多.....接下来要加速啦! >_<:注意这里必须用MFC和前面的Win32不一样啦! >_<:这也是第一次出现MFC游戏,其框架和逻辑的写法和Win32有很大的区别,建议先看一下MFC的基础再理解代码: >_<:TicTac.h 1 #define EX 1 //该点左鼠标 2 #define OH 2 //该点右鼠标 3 4 class CMyApp : public CWinApp 5 {

[游戏学习24] MFC 各种绘图 字体学习

>_<:这里包含字体设置及各种绘图,只要稍微看一下代码就能理解,这里不多介绍 >_<:Hello.h 1 #include<afxwin.h> 2 class CMyApp:public CWinApp 3 { 4 public: 5 virtual BOOL InitInstance(); 6 }; 7 class CMainWindow:public CFrameWnd 8 { 9 public: 10 CMainWindow(); 11 protected: 12

[游戏学习23] MFC 画尺子

>_<:这是个简单的MFC程序,有利于了解MFC的框架结构 >_<:Ruler.h 1 #include<afxwin.h> 2 class CMyApp:public CWinApp 3 { 4 public: 5 virtual BOOL InitInstance(); 6 }; 7 class CMainWindow:public CFrameWnd 8 { 9 public: 10 CMainWindow(); 11 protected: 12 afx_msg

[游戏模版6] Win32 graph

>_<:there in the MyPaint(...) function respectively use Ellipse(...) draw ellipse, use RoundRect(...) draw rectangle whose angle is round, use Pie(...) draw sector also named fan shap, use Chord(...) draw  arch also named bow shaped. >_<:the s

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

>_<:first build some points put in poly1[],poly2[] and poly3[] in the function of InitInstance(...) >_<:then in the function MyDraw() use  PolylineTo(...)\Polyline(...)\Polygon(...) draw diferent line and use PolyBezierTo(...)\PolyBezier(...)

[游戏模版20] Win32 物理引擎 加速运动

>_<:Compared with previous talk,there will be taking about how to create an accelerated speed.Only a little change in the MyPaint(...) function. >_<:resource >_<:code 1 #include <windows.h> 2 // C 运行时头文件 3 #include <stdlib.h>

[游戏模版21] Win32 物理引擎 能量守恒

>_<:Only a little change in the function of MyPaint(...),besides the initial value have some changes. >_<:resource >_<:code:    1 #include <windows.h> 2 // C 运行时头文件 3 #include <stdlib.h> 4 #include <cstdio> 5 #include &