📄 chap8_4.htm
字号:
<html>
<head>
<title>8.4访问当前活动视图和活动文档 </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
</head>
<body link="#3973DE" alink="#3973DE">
<font SIZE="5"><b><div align="center"><center>
<table border="0" width="615" cellspacing="0" cellpadding="0">
<tr>
</b><td><div align="center"><center><table border="0" width="615" cellpadding="0" cellspacing="0" height="20">
<tr>
<td width="377" bgcolor="#15397D" height="20"></td>
<td width="238" bgcolor="#000000" height="20"><p align="right"></font><span style="text-decoration: none"><a href="../../index.htm"><font color="#FFFFFF">电脑报Visual
C++网络教程</font></a></span></td>
</tr>
</table>
</center></div><font FACE="Times New Roman" SIZE="4"><b><p ALIGN="CENTER"></b></font><font color="#3973DE" FACE="Times New Roman" SIZE="4">8.4</font><font color="#3973DE" SIZE="4">访问当前活动视图和活动文档
</font><font FACE="Times New Roman" SIZE="3"></p>
<p></font><font SIZE="3">对于</font><font FACE="Times New Roman" SIZE="3">SDI</font><font SIZE="3">程序,主框架窗口就是文档框窗,可以采用以下方法取得当前文档和视图:</font><font FACE="Times New Roman" SIZE="3"></p>
<p></font><font SIZE="3">取得活动文档:</font><font FACE="Times New Roman" SIZE="3"></p>
<p>CMyDocument* pDoc;</p>
<p>pDoc=(CMyDocument*)((CFrameWnd*)AfxGetApp()->m_pMainWnd)</p>
<p>->GetActiveDocument();</p>
<p></font><font SIZE="3">或</font><font FACE="Times New Roman" SIZE="3"></p>
<p>pDoc=(CMyDocument*)((CFrameWnd*)AfxGetMainWnd())</font><font SIZE="3">;</font><font FACE="Times New Roman" SIZE="3"></p>
<p></font><font SIZE="3">这两者是等效的。</font><font FACE="Times New Roman" SIZE="3"></p>
<p></font><font SIZE="3">取得活动视图:</font><font FACE="Times New Roman" SIZE="3"></p>
<p>CMyView* pView;</p>
<p>pView=(CMyView*)((CFrameWnd*)AfxGetApp()->m_pMainWnd)->GetActiveView();</p>
<p></font><font SIZE="3">对于</font><font FACE="Times New Roman" SIZE="3">MDI</font><font SIZE="3">程序,由于子窗口才是文档框窗,因此首先要用</font><font FACE="Times New Roman" SIZE="3">GetActiveFrame()</font><font SIZE="3">取得活动子框架窗口,然后通过该子窗口获取活动文档和视图:</font><font FACE="Times New Roman" SIZE="3"></p>
<p>CMDIChildWnd*
pChild=(CMDIChildWnd*)((CFrameWnd*)AfxGetApp()->m_pMainWnd)->GetActiveFrame();</p>
<p></font><font SIZE="3">取得活动文档:</font><font FACE="Times New Roman" SIZE="3"></p>
<p>CMyDocument* pDoc=pChild->GetActiveDocument();</p>
<p>CMyView* pView=(CMyView*)pChild->GetActiveView();</p>
<p></font><font SIZE="3">可以把上述函数片段做成静态成员函数,比如:</font><font FACE="Times New Roman" SIZE="3"></p>
<p>static CMyDocument::GetCurrentDoc()</p>
<p>{</p>
<p>CMDIChildWnd* pChild=(CMDIChildWnd*)((CFrameWnd*)AfxGetApp()-
>m_pMainWnd)->GetActiveFrame();</p>
<p>CMyDocument* pDoc=pChild->GetActiveDocument();</p>
<p>}</p>
<p></font><font SIZE="3">这样就可以通过以下方式取得活动文档(或视图):</font><font FACE="Times New Roman" SIZE="3"></p>
<p>CMyDocument::GetCurrentDoc();</font><font SIZE="3"><b></p>
<p></b><font color="#3973DE">注:静态成员函数调用时不需要一个具体的对象与之相关联。</font></font><font FACE="Times New Roman" SIZE="4"></p>
</font><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="615">
<tr>
<td><a href="chap8_3.htm">上一页</a></td>
<td><p align="right"><a href="chap8_5.htm">下一页</a></td>
</tr>
</table>
</center></div><font SIZE="5"><hr noshade color="#3973DE" size="1">
<p align="center"></font><font size="2" color="#000000">本教程由<a href="http://vcdynasty.yeah.net">Visual C++王朝(Where programmers come together)</a>协助制作<br>
未经许可,请勿以任何形式复制</font></td>
<b>
</tr>
</table>
</center></div>
<p ALIGN="CENTER"></b><font SIZE="5"> </font><font FACE="Times New Roman" SIZE="5"></p>
</font><font FACE="Times New Roman" SIZE="3">
<p></font><b><font SIZE="3"> </font><font FACE="Times New Roman" SIZE="3"></p>
</font></b>
<p><font SIZE="3"> </font><font FACE="Times New Roman" SIZE="3"></p>
<p></font> </p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -