-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathday03.txt
266 lines (139 loc) · 4.22 KB
/
day03.txt
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
virtual BOOL CWnd::Create(
LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle,
Const RECT& rect,
CWnd* pParentWnd,
UINT nID,
CCreateContext* pContext = NULL
);
一 工具栏的使用
1. MFC工具栏相关
CToolBar - 父类是CControlBar , 提供了与框架窗口相关的支持
CToolBarCtrl - 父类是 CWnd 对Win32下的ToolBar控件进行封装
在MFC中, 一般使用CToolBar创建工具栏, 如果要进行更多工具栏的操作,
需要使用GetToolBarCtrl函数获取该工具栏的CToolBarCtrl类
2.工具栏的使用
2.1 创建
2.1.1 添加工具栏资源
2.1.2 添加CToolBar 头文件 afxext.h
2.1.3 创建工具栏
Create 和 CreateEx
2.1.4
LoadToolBar 加载工具栏资源
2.2 工具栏的停靠
2.2.1 工具栏支持停靠 EnableDocking
2.2.2 框架窗口停靠支持 CFrameWnd::EnableDocking
2.2.3 停靠工具栏 DockToolBar
3.工具栏显示和关闭
二 视图 View
//WM_COMMAND 逐层向下(子窗口)派发消息
WM_COMMAND消息处理,
WM_COMMAND消息------>顶层窗口(Frame)--->OnWndMsg()--->
OnCommand-->OnCmdMsg-->逐层派发
可以使用 SetActiveView 将view设置成当前的活动视图
============================
CMyView::OnTest() line 44
_AfxDispatchCmdMsg(CCmdTarget * 0x00421950 {CMyView}, unsigned int 40002, int 0, void (void)* 0x0040103c CMyView::OnTest(void), void * 0x00000000, unsigned int 12, AFX_CMDHANDLERINFO * 0x00000000) line 88
CCmdTarget::OnCmdMsg(unsigned int 40002, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 302 + 39 bytes
CView::OnCmdMsg(unsigned int 40002, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 159 + 24 bytes
CViewFrame::OnCmdMsg(unsigned int 40002, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 99 + 41 bytes
CWnd::OnCommand(unsigned int 40002, long 0) line 2088
CFrameWnd::OnCommand(unsigned int 40002, long 0) line 317
CWnd::OnWndMsg(unsigned int 273, unsigned int 40002, long 0, long * 0x0012fcc4) line 1597 + 28 bytes
CWnd::WindowProc(unsigned int 273, unsigned int 40002, long 0) line 1585 + 30 bytes
==========================
==========================================
// MFCToolBar.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
class CViewApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMyView : public CView
{
DECLARE_MESSAGE_MAP()
public:
virtual void OnDraw(CDC *pDC);
afx_msg void OnPaint();
afx_msg void OnTest();
};
BEGIN_MESSAGE_MAP(CMyView, CView)
ON_WM_PAINT()
ON_COMMAND(ID_TEST1, OnTest)
END_MESSAGE_MAP()
void CMyView::OnDraw(CDC *pDC)
{
pDC->TextOut(100, 100, "Hello View");
}
void CMyView::OnTest()
{
AfxMessageBox("测试成功");
}
/*
HDC BeginPaint(
HWND hwnd, // 窗口的句柄
LPPAINTSTRUCT lpPaint // 绘制信息
);
*/
void CMyView::OnPaint()
{
PAINTSTRUCT ps = {0};
HDC hDC = ::BeginPaint(m_hWnd, &ps);
TextOut(hDC, 100, 100, "View Hello" , 10);
::EndPaint(m_hWnd, &ps);
}
class CViewFrame : public CFrameWnd
{
DECLARE_MESSAGE_MAP()
public:
CViewFrame();
BOOL OnCmdMsg(UINT iID, int iCode, void *pExtra, AFX_CMDHANDLERINFO *lpHandlerInfo);
public:
int OnCreate(LPCREATESTRUCT lpCreateStruct);
public:
CMyView *m_pwndView;
};
BEGIN_MESSAGE_MAP(CViewFrame, CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
CViewFrame::CViewFrame()
{
m_pwndView = NULL;
}
BOOL CViewFrame::OnCmdMsg(UINT iID, int iCode, void *pExtra, AFX_CMDHANDLERINFO *lpHandlerInfo)
{
#if 0
if(NULL != m_pwndView)
{
if(TRUE == m_pwndView->OnCmdMsg(iID, iCode, pExtra, lpHandlerInfo))
{
return TRUE;
}
}
#endif
return CFrameWnd::OnCmdMsg(iID, iCode, pExtra, lpHandlerInfo);
}
int CViewFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CFrameWnd::OnCreate(lpCreateStruct);
m_pwndView = new CMyView();
m_pwndView->Create(NULL, "Vieeeew", WS_CHILD|WS_VISIBLE|WS_BORDER, CRect(100, 100, 200, 200), this, AFX_IDW_PANE_FIRST /*填满客户区*/);
SetActiveView(m_pwndView); //就不必自己写消息派发了
ModifyStyle(WS_EX_CLIENTEDGE, 0 );
return 0;
}
CViewApp theApp;
BOOL CViewApp::InitInstance()
{
CViewFrame *pWnd = new CViewFrame();
pWnd->Create(NULL, "View使用", WS_OVERLAPPEDWINDOW, CFrameWnd::rectDefault, NULL, MAKEINTRESOURCE(IDR_MENU1));
m_pMainWnd = pWnd;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
======================================