{"id":418,"date":"2010-05-19T07:06:00","date_gmt":"2010-05-18T23:06:00","guid":{"rendered":"http:\/\/www.prayerlaputa.com\/?p=418"},"modified":"2019-10-24T19:23:31","modified_gmt":"2019-10-24T11:23:31","slug":"mfc%e6%8c%87%e9%92%88%e7%9a%84%e8%8e%b7%e5%8f%96%ef%bc%88%e8%bd%ac%e8%bd%bd%ef%bc%89","status":"publish","type":"post","link":"http:\/\/prayerlaputa.com\/?p=418","title":{"rendered":"MFC\u6307\u9488\u7684\u83b7\u53d6\uff08\u8f6c\u8f7d\uff09"},"content":{"rendered":"<p>\u6e90\u5730\u5740\uff1ahttp:\/\/blog.csdn.net\/yincheng01\/archive\/2009\/01\/06\/3718954.aspx<\/p>\n<p>1\u3001\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u6307\u9488<br \/>\nCMyApp* pApp=(CMyApp*)AfxGetApp();<br \/>\n2\u3001\u83b7\u53d6\u4e3b\u6846\u67b6\u6307\u9488<br \/>\nCWinApp \u4e2d\u7684\u516c\u6709\u6210\u5458\u53d8\u91cf m_pMainWnd \u5c31\u662f\u4e3b\u6846\u67b6\u7684\u6307\u9488<br \/>\nCMainFrame* pMainFrame = (CMainFrame*)(AfxGetApp()-&gt;m_pMainWnd);<br \/>\n\u6216\u8005<br \/>\nCMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();<!--more--><br \/>\n\uff13\u3001\u83b7\u53d6\u83dc\u5355\u6307\u9488<br \/>\nCMenu* pMenu = AfxGetMainWnd()-&gt;GetMenu();<br \/>\n\uff14\u3001\u83b7\u53d6\u5de5\u5177\u680f\u3001\u72b6\u6001\u680f\u6307\u9488<br \/>\n\u4e3b\u6846\u67b6\u4e2d\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528m_wndToolBar\u3001m_wndStatusBar<br \/>\n\u5176\u4ed6\uff1a<br \/>\nCToolBar* pToolBar = (CToolBar*)AfxGetMainWnd()-&gt;GetDescendantWindow(AFX_IDW_TOOLBAR);<br \/>\nCStatusBar* pStatusBar = (CStatusBar*)AfxGetMainWnd()-&gt;GetDescendantWindow(AFX_IDW_STATUS_BAR);<br \/>\n5\u3001\u83b7\u53d6\u63a7\u4ef6\u6307\u9488<br \/>\n\u5148\u7528 GetDlgItem() \u518d\u8f6c\u6362\uff0c\u5982\uff1a<br \/>\nCButton* pButton = (CButton*)GetDlgItem(IDC_MYBUTTON);<br \/>\n6\u3001\u83b7\u53d6\u6587\u6863\u3001\u89c6\u56fe\u6307\u9488<\/p>\n<blockquote dir=\"ltr\" style=\"margin-right: 0px;\"><p>SDI:<br \/>\nCMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();<br \/>\nCYourDoc* pDoc = (CYourDoc*)pMainFrame-&gt;GetActiveDocument();<br \/>\nCYourView* pView = (CYourView*)pMainFrame-&gt;GetActiveView();<br \/>\nMDI:<br \/>\nCMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();<br \/>\nCChildFrame* pChildFrame = (CChildFrame*)pMainFrame-&gt;GetActiveFrame();<br \/>\nCYourDoc* pDoc = (CYourDoc*)pChildFrame-&gt;GetActiveDocument();<br \/>\nCYourView* pView = (CYourView*)pChildFrame-&gt;GetActiveView();<\/p><\/blockquote>\n<p>7\u3001\u6587\u6863\u3001\u89c6\u56fe<\/p>\n<blockquote dir=\"ltr\" style=\"margin-right: 0px;\"><p>\u4ece\u89c6\u56fe\u83b7\u53d6\u6587\u6863\u6307\u9488\uff1a<br \/>\nCYourDoc* pDoc = GetDocument();<br \/>\n\u4ece\u6587\u6863\u83b7\u53d6\u89c6\u56fe\u6307\u9488\uff1a<br \/>\n\u5229\u7528\u6210\u5458\u51fd\u6570 GetFirstViewPosition() \u548c GetNextView() \u904d\u5386<br \/>\nvirtual POSITION GetFirstViewPosition() const;<br \/>\nvirtual CView* GetNextView(POSITION&amp; rPosition) const;<br \/>\nSDI:<br \/>\nCYourView* pView;<br \/>\nPOSITION pos = GetFirstViewPosition();<br \/>\npView = GetNextView(pos);<br \/>\nMDI:<br \/>\n\u5b9a\u4e49\u51fd\u6570<br \/>\nCView* CYourDoc::GetView(CRuntimeClass* pClass)<br \/>\n{<br \/>\nCView* pView;<br \/>\nPOSITION pos=GetFirstViewPosition();<br \/>\nwhile(pos!=NULL)<br \/>\n{<br \/>\npView=GetNextView(pos);<br \/>\nif(!pView-&gt;IsKindOf(pClass))<br \/>\nbreak;<br \/>\n}<br \/>\nif(!pView-&gt;IsKindOf(pClass))<br \/>\n{<br \/>\nAfxMessageBox(&#8220;Connt Locate the View.&#8221;);<br \/>\nreturn NULL;<br \/>\n}<br \/>\nreturn pView;<br \/>\n}<br \/>\n\u4f7f\u7528\u5982\u4e0b\uff1a<br \/>\nCYourView* pView=(CYourView*)GetView(RUNTIME_CLASS(CYourView));<\/p><\/blockquote>\n<p dir=\"ltr\">8\u3001\u6587\u6863\u6a21\u7248\u3001\u6587\u6863<\/p>\n<blockquote dir=\"ltr\" style=\"margin-right: 0px;\"><p>\u4ece\u6587\u6863\u83b7\u53d6\u6587\u6863\u6a21\u7248\u6307\u9488\uff1a<br \/>\nCDocTemplate* GetDocTemplate() const;<br \/>\n\u4ece\u6587\u6863\u6a21\u7248\u83b7\u53d6\u6587\u6863\u6307\u9488\uff1a<br \/>\nviaual POSITION GetFirstDocPosition( ) const = 0;<br \/>\nvisual CDocument* GetNextDoc(POSITION &amp; rPos) const = 0;<\/p><\/blockquote>\n<p dir=\"ltr\">9\u3001\u83b7\u53d6\u5206\u5272\u89c6\u56fe\u4e2d\u5404\u4e2a\u89c6\u56fe\u7684\u6307\u9488<\/p>\n<blockquote dir=\"ltr\" style=\"margin-right: 0px;\">\n<p dir=\"ltr\">\u4e3b\u6846\u67b6\u4e2d\u5b9a\u4e49\uff1aCSplitterWnd m_wndSplitter;<\/p>\n<p dir=\"ltr\">\u5b9a\u4e49\u4e24\u4e2aView<strong style=\"color: black; background-color: #99ff99;\">\u7c7b<\/strong>\uff1aCView1\u3001CView2<\/p>\n<p dir=\"ltr\">\u6846\u67b6<strong style=\"color: black; background-color: #99ff99;\">\u7c7b<\/strong>\u4e2d\u91cd\u8f7d\uff1a<br \/>\nBOOL CMainFrame::OnCreateClient(LPCREATESTRUCT, CCreateContext* pContext)<br \/>\n{<br \/>\nVERIFY(m_splitter.CreateStatic(this,2,1)); \/\/\u5206\u5272\u6210\u4e24\u884c\u4e00\u5217<br \/>\nVERIFY(m_splitter.CreateView(0,0,RUNTIME_CLASS(CView1),CSize(100,100),pContext));<br \/>\nVERIFY(m_splitter.CreateView(1,0,RUNTIME_CLASS(CView2),CSize(100,100),pContext));<br \/>\nreturn TRUE;<br \/>\n}<\/p>\n<p dir=\"ltr\">\u83b7\u53d6\u5206\u5272\u89c6\u56fe\u6307\u9488<br \/>\nCView1* pView1 = (CView1*)m_wndSplitter.GetPane(0,0);<br \/>\nCView2* pView2 = (CView2*)m_wndSplitter.GetPane(1,0);<\/p>\n<\/blockquote>\n<p dir=\"ltr\">10\u3001\u901a\u8fc7\u9f20\u6807\u83b7\u5f97\u5b50\u7a97\u53e3\u6307\u9488<\/p>\n<blockquote dir=\"ltr\" style=\"margin-right: 0px;\">\n<p dir=\"ltr\">CWnd* ChildWindowFromPoint(POINT point) const;<br \/>\nCWnd* ChildWindowFromPoint(POINT point,UINT nFlags) const;<br \/>\n\u7528\u4e8e\u786e\u5b9a\u5305\u542b\u6307\u5b9a\u70b9\u7684\u5b50\u7a97\u53e3<br \/>\n\u5982 \u679c\u6307\u5b9a\u70b9\u5728\u5ba2\u6237\u533a\u4e4b\u5916\uff0c\u51fd\u6570\u8fd4\u56deNULL\uff1b<br \/>\n\u5982\u679c\u6307\u5b9a\u70b9\u5728\u5ba2\u6237\u533a\u5185\uff0c\u4f46\u662f\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u4e00\u4e2a\u5b50\u7a97\u53e3\uff0c\u51fd\u6570\u8fd4\u56de\u8be5CWnd\u7684\u6307\u9488\uff1b<br \/>\n\u5982\u679c\u6709\u591a\u4e2a\u5b50\u7a97 \u53e3\u5305\u542b\u6307\u5b9a\u70b9\uff0c\u5219\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5b50\u7a97\u53e3\u7684\u6307\u9488\u3002<br \/>\n\u8fd8\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8be5\u51fd\u6570\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u4f2a\u7a97\u53e3\u6307\u9488\uff0c\u4e0d\u80fd\u5c06\u5b83\u4fdd\u5b58\u8d77\u6765\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002<br \/>\n\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u53c2\u6570 nFlags\u6709\u51e0\u4e2a\u542b\u4e49\uff1a<br \/>\nCWP_ALL\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 file:\/\/\u4e0d\u5ffd\u7565\u4efb\u4f55\u5b50\u7a97\u53e3<br \/>\nCWP_SKIPNIVSIBLE\u00a0\u00a0\u00a0 file:\/\/\u5ffd\u7565\u4e0d\u53ef\u89c1\u5b50\u7a97\u53e3<br \/>\nCWP_SKIPDISABLED\u00a0\u00a0\u00a0 file:\/\/\u5ffd\u7565\u7981\u6b62\u7684\u5b50\u7a97\u53e3<br \/>\nCWP_SKIPRANSPARENT file:\/\/\u5ffd\u7565\u900f\u660e\u5b50\u7a97\u53e3<\/p>\n<p><span style=\"font-size: 18pt; color: #f70909;\">\u83b7 \u53d6\u5de5\u5177\u6761\u7684\u6307\u9488<\/span><span style=\"font-size: 9pt;\"><br \/>\n<\/span><span style=\"font-size: 9pt;\">\u5728\u7f3a\u7701\u72b6\u6001\u4e0b\uff0c\u6709\u4e00\u4e2a\u9ed8\u8ba4\u7684\u5de5\u5177\u6761AFX_IDW_TOOLBAR\uff0c \u6211\u4eec\u53ef\u4ee5\u6839\u636e\u76f8\u5e94\u7684ID\u53bb\u83b7\u53d6\u5de5\u5177\u6761\u6307\u9488\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a<br \/>\nCToolBar* pToolBar=(CToolBar*)AfxGetMainWnd()-&gt;GetDescendantWindow(AFX_IDW_TOOLBAR);<br \/>\n\u662f\u4e0d\u662f\u5f88\u7b80\u5355\uff1f<br \/>\n<\/span><span style=\"font-size: 18pt; color: #f70909;\">\u83b7\u53d6\u72b6\u6001\u6761\u7684\u6307 \u9488<\/span><span style=\"font-size: 9pt;\"><br \/>\n<\/span><span style=\"font-size: 9pt;\">\u5728\u7f3a\u7701\u72b6\u6001\u4e0b\uff0c\u6709\u4e00\u4e2a\u9ed8\u8ba4\u7684\u72b6\u6001\u6761AFX_IDW_STATUS_BAR\uff0c \u6211\u4eec\u81ea\u7136\u4e5f\u53ef\u4ee5\u6839\u636e\u76f8\u5e94\u7684ID\u53bb\u83b7\u53d6\u72b6\u6001\u6761\u6307\u9488\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a<br \/>\nCStatusBar* pToolBar=(CStatusBar*)AfxGetMainWnd()-&gt;GetDescendantWindow(AFX_IDW_STATUS_BAR);<br \/>\n\u662f\u4e0d\u662f\u540c\u6837\u5f88\u7b80\u5355\uff1f<\/span><br \/>\n<span style=\"font-size: 9pt;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-size: 18pt; color: #ee1111;\">\u83b7\u53d6\u63a7\u4ef6\u7684\u6307\u9488 <\/span><span style=\"font-size: 9pt;\"><br \/>\n<\/span><span style=\"font-size: 9pt;\">\u8fd9\u91cc\u6709\u4e24\u79cd\u65b9\u6cd5\u3002<br \/>\n\u4e00\u3001\u8c03\u7528CWnd: : GetDlgItem\uff0c \u83b7\u53d6\u4e00\u4e2aCWnd*\u6307\u9488\u8c03\u7528\u6210\u5458\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u60f3\u83b7\u53d6CButton\u6307\u9488\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a<br \/>\nCButton* pButton=(CButton*) GetDlgItem (IDC_MYBUTTON);<br \/>\n\u4e8c\u3001\u53ef\u4ee5\u4f7f\u7528ClassWizard\u5c06\u63a7\u4ef6\u548c\u6210\u5458\u53d8\u91cf\u8054\u7cfb\u8d77\u6765\u3002\u5728ClassWizard\u4e2d \u7b80\u5355\u5730\u9009\u62e9Member Variables\u6807\u7b7e\uff0c\u7136\u540e\u9009\u62e9Add Variable \u2026\u6309\u94ae\u3002\u5982 \u679c\u5728\u5bf9\u8bdd\u8d44\u6e90\u7f16\u8f91\u5668\u4e2d\uff0c\u6309\u4e0bCtrl\u952e\u5e76\u53cc\u51fb\u63a7\u4ef6\u5373\u53ef\u8f6c\u5230Add Member Variable\u5bf9 \u8bdd\u3002<\/span><br \/>\n<span style=\"font-size: 9pt;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-size: 18pt; color: #f70909;\">\u5728\u6587\u6863\u7c7b\u4e2d\u8c03\u7528 \u89c6\u56fe\u7c7b\u6307\u9488<br \/>\n<\/span><span style=\"font-size: 9pt;\">\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u6587\u6863\u7c7b\u7684\u6210\u5458\u51fd\u6570GetFirstView()\u548cGetNextView()\u904d \u5386\u89c6\u56fe\u3002<\/span><br \/>\n<span style=\"font-size: 9pt;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-size: 18pt; color: #ee1111;\">\u5728\u89c6\u56fe\u7c7b\u4e2d\u8c03\u7528\u6587\u6863\u7c7b<\/span><span style=\"font-size: 9pt;\"><br \/>\n<\/span><span style=\"font-size: 9pt;\">\u5176\u5b9e\uff0c\u5728\u89c6\u56fe\u7c7b\u4e2d\u6709\u4e00\u4e2a\u73b0\u6210\u7684\u6210\u5458\u51fd\u6570\u4f9b\u6211\u4eec\u4f7f\u7528\uff0c\u90a3\u5c31\u662f\uff1aGetDocument();\u5229 \u7528\u5b83\u6211\u4eec\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u5f97\u5230\u6587\u6863\u7c7b\u6307\u9488\uff0c\u6211\u4eec\u5148\u770b\u4e00\u4e0bGetDocument()\u51fd\u6570\u7684\u5b9e\u73b0\uff1a<br \/>\nCColorButtonDoc* CColorButtonView::GetDocument()<br \/>\n{<br \/>\nASSERT(m_pDocument-&gt;IsKindOf(RUNTIME_CLASS(CColorButtonDoc)));<br \/>\nreturn (CColorButtonDoc*)m_pDocument;<br \/>\n}<br \/>\n\u8fd9\u91cc\u5b9e\u9645\u4e0a\u662f\u5c06m_pDocument\u5f3a\u5236\u8f6c\u6362\u6210CColorButtonDoc*\uff0c \u4e5f\u5c31\u662f\u6211\u4eec\u60f3\u8981\u7684\u3002<\/span><br \/>\n<span style=\"font-size: 9pt;\">\u00a0\u00a0\u00a0<\/span><span style=\"font-size: 18pt; color: #ee1111;\">\u5728\u6846\u67b6\u7c7b\u4e2d\u8c03 \u7528\u6587\u6863\u7c7b\u3001\u89c6\u56fe\u7c7b<br \/>\n<\/span><span style=\"font-size: 9pt;\">\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u5229\u7528GetActiveXXXXX()\u53bb \u6389\u7528\u5f53\u524d\u6fc0\u6d3b\u7684\u6587\u6863\u548c\u89c6\u56fe\uff1a<br \/>\nCMyDoc*\u00a0\u00a0 pDoc=(CMyDoc*)GetActiveDocument();<br \/>\nCMyView* pView=(CMyView*)GetActiveView();<\/span><br \/>\n<span style=\"font-size: 9pt;\">\u00a0\u00a0\u00a0<\/span><span style=\"font-size: 18pt; color: #ee1111;\">\u83b7\u5f97\u5e94\u7528\u7a0b\u5e8f\u6307\u9488<\/span><span style=\"font-size: 9pt;\"><br \/>\n<\/span><span style=\"font-size: 9pt;\">\u8fd9\u4e2a\u5f88\u7b80\u5355\uff0c\u4e00\u53e5\u8bdd\u641e\u5b9a\uff1a<br \/>\nCMyApp* pApp=(CMyApp*)AfxGetApp();<\/span><br \/>\n<span style=\"font-size: 9pt;\">\u00a0\u00a0\u00a0<\/span><span style=\"font-size: 18pt; color: #ee1111;\">\u83b7\u5f97\u4e3b\u6846\u67b6\u6307 \u9488<br \/>\n<\/span><span style=\"font-size: 9pt;\">\u5728\u7c7bCWinThread\u91cc\u9762\u6709\u4e00\u4e2a\u516c\u6709 \u7684\u6210\u5458\u53d8\u91cf\uff1aCWnd* m_pMainWnd; \u5b83\u5b58\u5728\u7684\u4e3b\u8981\u76ee\u7684\u5c31\u662f\u63d0\u4f9b\u6211\u4eec\u83b7\u5f97CWnd\u6307 \u9488\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u5b83\u6765\u8fbe\u5230\u6211\u4eec\u7684\u76ee\u7684\uff1a<br \/>\nCMainFrame* pFrame=(CMainFrame*)(AfxGetApp()-&gt;m_pMainWnd);<br \/>\n<\/span><span style=\"font-size: 18pt; color: #ee1111;\">\u901a\u8fc7\u9f20\u6807\u83b7 \u5f97\u5b50\u7a97\u53e3\u6307\u9488<\/span><span style=\"font-size: 9pt;\"><br \/>\n<\/span><span style=\"font-size: 9pt;\">\u8fd9\u91cc\u6211\u4eec\u8981\u7528\u5230\u4e00\u4e2a\u4e0d\u592a\u5e38\u7528\u7684\u51fd\u6570\uff1aChildWindowFromPoint\u3002 \u4ed6\u7684\u539f\u578b\u5982\u4e0b\uff1a<br \/>\nCWnd* ChildWindowFromPoint(POINT point) const;<br \/>\nCWnd* ChildWindowFromPoint(POINT point,UINT nFlags) const;<br \/>\n\u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u786e\u5b9a\u5305\u542b\u6307\u5b9a\u70b9\u7684\u5b50\u7a97\u53e3\uff0c\u5982\u679c\u6307\u5b9a\u70b9\u5728\u5ba2\u6237\u533a\u4e4b\u5916\uff0c\u51fd\u6570\u8fd4\u56deNULL\uff1b\u5982\u679c\u6307\u5b9a\u70b9\u5728\u5ba2\u6237\u533a \u5185\uff0c\u4f46\u662f\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u4e00\u4e2a\u5b50\u7a97\u53e3\uff0c\u51fd\u6570\u8fd4\u56de\u8be5CWnd\u7684\u6307\u9488\uff1b\u5982\u679c\u6709\u591a\u4e2a\u5b50\u7a97\u53e3\u5305\u542b\u6307\u5b9a\u70b9\uff0c\u5219\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5b50\u7a97\u53e3\u7684\u6307\u9488\u3002\u4e0d\u8fc7\uff0c\u8fd9 \u91cc\u8fd8\u8981\u6ce8\u610f\u7684\u662f\uff1a\u8be5\u51fd\u6570\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u4f2a\u7a97\u53e3\u6307\u9488\uff0c\u4e0d\u80fd\u5c06\u5b83\u4fdd\u5b58\u8d77\u6765\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002<br \/>\n\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u53c2\u6570nFlags\u6709\u51e0\u4e2a\u542b\u4e49\uff1a<br \/>\nCWP_ALL\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<a href=\"file:\/\/\/\" target=\"_blank\" rel=\"noopener noreferrer\"><u>file:\/\/\u4e0d<\/u><\/a><\/span>\u5ffd\u7565\u4efb\u4f55\u5b50\u7a97\u53e3<br \/>\nCWP_SKIPNIVSIBLE\u00a0\u00a0\u00a0\u00a0<a href=\"file:\/\/\/\" target=\"_blank\" rel=\"noopener noreferrer\"><u>file:\/\/\u5ffd<\/u><\/a>\u7565\u4e0d\u53ef\u89c1\u5b50\u7a97\u53e3<br \/>\nCWP_SKIPDISABLED\u00a0\u00a0\u00a0\u00a0<a href=\"file:\/\/\/\" target=\"_blank\" rel=\"noopener noreferrer\"><u>file:\/\/\u5ffd<\/u><\/a>\u7565\u7981\u6b62\u7684\u5b50\u7a97\u53e3<br \/>\nCWP_SKIPRANSPARENT\u00a0\u00a0<a href=\"file:\/\/\/\" target=\"_blank\" rel=\"noopener noreferrer\"><u>file:\/\/\u5ffd<\/u><\/a>\u7565 \u900f\u660e\u5b50\u7a97\u53e3<\/p>\n<p>\u5728\u4f55\u65f6\u4f55\u5730\uff0c\u4f60\u90fd\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u7cbe\u786e\u7684\u5f97\u5230\u4efb\u4f55\u4e00\u4e2a\u5bf9\u8c61 \uff08Application\uff0cDocTemplate,Document\uff0cView,Frame\uff09<br \/>\n1\u3002\u901a\u8fc7AfxGetApp()\u5f97\u5230\u5f53\u524d\u7684App \u5bf9\u8c61\uff1b<br \/>\n2\u3002\u901a\u8fc7AfxGetMainWnd\uff08\uff09\u5f97\u5230\u4e3b\u7a97\u53e3\uff1b<br \/>\n3\u3002\u901a\u8fc7CMDIFrameWnd::GetActiveFrame\u5f97\u5230\u5f53\u524d \u6d3b\u52a8\u7a97\u53e3\uff1b<br \/>\n4\u3002\u901a\u8fc7GetNextWindow()\u904d\u4f8b\u6240\u6709\u7684\u5b50\u7a97\u53e3\uff1b\uff08\u5982\u679c\u8981\u5f97\u5230\u4f60\u60f3\u8981\u7684\u5b50\u7a97\u53e3\uff0c\u53ef\u4ee5\u901a\u8fc7\u7279\u5b9a\u7684\u6210\u5458\u53d8\u91cf\u6765\u6807\u5fd7\uff09\uff1b<br \/>\n5\u3002 \u901a\u8fc7CWinApp::GetFirstDocTemplatePostion()\u4ee5\u53caCWinApp::GetNextDocTemplate()\u7684\u7ec4 \u5408\u5e94\u7528\u6765\u904d\u5386\u6240\u6709\u7684DocTemplate\u5bf9\u8c61\uff0c\u5e76\u4e14\u7528CDocTemplate::GetDocString()\u6765\u5224\u65ad\u5f53\u524d\u5f97\u5230\u7684\u6587\u6863\u83ab\u677f\u5bf9\u8c61\u662f\u54ea\u4e2a\u3002<br \/>\n6\u3002 \u901a\u8fc7CDocTemplate::GetFirstDocPosition()\u4ee5\u53caCDocTemplate\u7684GetNextDoc\uff08\uff09\u7ec4\u5408\u6765\u904d\u5386\u6240\u6709\u7684 \u8be5\u6a21\u677f\u7684\u6587\u6863\u5bf9\u8c61\uff0c\u5e76\u7528CDocument::GetDocTemplate()\u6765\u5f97\u5230\u6587\u6863\u6a21\u677f\uff0c\u7528CDocment::GetTitle() \u6216\u8005GetPathName()\u6765\u5224\u65ad\u5f53\u524d\u7684\u6587\u6863\u662f\u54ea\u4e2a\u3002<br \/>\n7\u3002\u901a\u8fc7CDocuemt\u7684GetFirstViewPositon()\u4ee5\u53ca GetNextView()\u6765\u904d\u5386\u89c6\u56fe\u5bf9\u8c61\uff0c\u4e00\u822c\u901a\u8fc7\u8bbf\u95eeView\u7684\u6210\u5458\u53d8\u91cf\u6765\u533a\u522b\u5404\u4e2a\u89c6\u56fe\uff1b\u901a\u8fc7CView::GetDocument()\u6765\u5f97\u5230\u6587\u6863\u5bf9 \u8c61\uff1b<br \/>\n8\u3002Frame-&gt;View\uff1a \u901a\u8fc7GetActiveView\u65b9\u6cd5\uff1b<br \/>\n9\u3002Frame-&gt;Doc\uff1a\u901a\u8fc7 GetActiveDocument();<br \/>\n10\u3002View-&gt;Frame\uff1aGetParentFrame();<br \/>\n11\u3002 View-&gt;Doc:GetDocuemt()\/\/\u524d\u9762\u5df2\u7ecf\u8bf4\u4e86\u3002<br \/>\n12\u3002Doc-&gt;View:\u524d\u9762\u8bf4\u4e86\uff1b<br \/>\n13\u3002 Doc-&gt;Frame:\u4e0d\u77e5\u9053\u6709\u6ca1\u6709\u5f88\u76f4\u63a5\u7684\u65b9\u6cd5\u3002<br \/>\nMFC\u5e94\u7528\u7a0b\u5e8f\u4e2d\u6307\u9488\u7684\u4f7f\u7528<br \/>\n1) \u5728View\u4e2d\u83b7\u5f97Doc\u6307\u9488<br \/>\n2) \u5728App\u4e2d\u83b7\u5f97MainFrame\u6307\u9488<br \/>\n3) \u5728View\u4e2d\u83b7\u5f97MainFrame\u6307\u9488<br \/>\n4) \u83b7\u5f97View\uff08\u5df2\u5efa\u7acb\uff09\u6307\u9488<br \/>\n5) \u83b7\u5f97\u5f53\u524d\u6587\u6863\u6307\u9488<br \/>\n6) \u83b7\u5f97\u72b6\u6001\u680f\u4e0e\u5de5\u5177\u680f\u6307\u9488<br \/>\n7) \u83b7\u5f97\u72b6\u6001\u680f\u4e0e\u5de5\u5177\u680f\u53d8\u91cf<br \/>\n8) \u5728Mainframe\u83b7\u5f97\u83dc\u5355\u6307\u9488<br \/>\n9) \u5728\u4efb\u4f55\u7c7b\u4e2d\u83b7\u5f97\u5e94\u7528\u7a0b\u5e8f\u7c7b<br \/>\n10) \u4ece\u6587\u6863\u7c7b\u53d6\u5f97\u89c6\u56fe\u7c7b\u7684\u6307\u9488(1)<br \/>\n11) \u5728App\u4e2d\u83b7\u5f97\u6587\u6863\u6a21\u677f\u6307\u9488<br \/>\n12) \u4ece\u6587\u6863\u6a21\u677f\u83b7\u5f97\u6587\u6863\u7c7b\u6307\u9488<br \/>\n13) \u5728\u6587\u6863\u7c7b\u4e2d\u83b7\u5f97\u6587\u6863\u6a21\u677f\u6307\u9488<br \/>\n14) \u4ece\u6587\u6863\u7c7b\u53d6\u5f97\u89c6\u56fe\u7c7b\u7684\u6307\u9488(2)<br \/>\n15) \u4ece\u4e00\u4e2a\u89c6\u56fe\u7c7b\u53d6\u5f97\u53e6\u4e00\u89c6\u56fe\u7c7b\u7684\u6307\u9488<br \/>\nVC\u4e2d\u7f16\u7a0b\u5bf9\u4e8e\u521a\u521a\u5f00\u59cb\u5b66\u4e60\u7684\u540c\u5b66\uff0c\u6700\u5927\u7684\u969c\u788d\u548c\u95ee\u9898\u5c31\u662f\u6d88\u606f\u673a\u5236\u548c\u6307\u9488\u83b7\u53d6\u4e0e<br \/>\n\u64cd\u4f5c\u3002\u5176\u5b9e\u8fd9\u4e9b\u5185\u5bb9\u57fa\u672c \u4e0a\u662f\u6bcf\u672cVC\u5b66\u4e60\u5de5\u5177\u4e66\u4e0a\u5fc5\u8bb2\u7684\u5185\u5bb9\uff0c\u800c\u4e14\u901a\u8fc7MSDN\u5f88\u591a<br \/>\n\u95ee\u9898\u90fd\u80fd\u89e3\u51b3\u3002\u4e0b\u9762\u6587\u5b57\u4e3b\u8981\u662f\u4e2a\u4eba\u5728\u7f16\u7a0b\u4e2d\u6307\u9488\u4f7f\u7528\u7684\u4e00\u4e9b\u4f53\u4f1a\uff0c\u8bf4\u7684\u4e0d\u5f53\u7684\u5730<br \/>\n\u65b9 \u8bf7\u6307\u6b63\u3002\u4e00\u822c\u6211\u4eec\u4f7f\u7528\u7684\u6846\u67b6\u662fVC\u63d0\u4f9b\u7684Wizard\u751f\u6210\u7684MFC App Wizard(exe)\u6846\u67b6\uff0c<br \/>\n\u65e0\u8bba\u662f\u591a\u6587\u6863\u8fd8\u662f\u5355\u6587\u6863\uff0c\u90fd\u5b58\u5728\u6307\u9488\u83b7 \u53d6\u548c\u64cd\u4f5c\u95ee\u9898\u3002\u4e0b\u9762\u8fd9\u8282\u5185\u5bb9\u4e3b\u8981\u662f\u4e00\u822c<br \/>\n\u7684\u6846\u67b6\uff0c\u7136\u540e\u518d\u8bb2\u591a\u7ebf\u7a0b\u4e2d\u7684\u6307\u9488\u4f7f\u7528\u3002\u4f7f\u7528\u5230\u7684\u7c7b\u9700\u8981\u5305\u542b\u54cd\u5e94\u7684\u5934\u6587\u4ef6\u3002\u9996\u5148<br \/>\n\u4e00\u822c\u83b7\u5f97\u672c\u7c7b(\u89c6\uff0c\u6587 \u6863\uff0c\u5bf9\u8bdd\u6846\u90fd\u652f\u6301)\u5b9e\u4f8b\u6307\u9488this\uff0c\u7528this\u7684\u76ee\u7684\uff0c\u4e3b\u8981\u53ef\u4ee5\u901a<br \/>\n\u8fc7\u7c7b\u4e2d\u7684\u51fd\u6570\u5411\u5176\u4ed6\u7c7b\u6216\u8005\u51fd\u6570\u4e2d\u53d1\u6307\u9488\uff0c\u4ee5\u4fbf\u4e8e\u5728\u975e\u672c\u7c7b\u4e2d\u64cd\u4f5c\u548c\u4f7f\u7528\u672c\u7c7b\u4e2d\u7684<br \/>\n\u529f \u80fd\u3002<br \/>\n1\uff09 \u5728View\u4e2d\u83b7\u5f97Doc\u6307\u9488 CYouSDIDoc *pDoc=GetDocument();\u4e00\u4e2a\u89c6\u53ea\u80fd\u6709\u4e00\u4e2a\u6587<br \/>\n\u6863\u3002<br \/>\n2) \u5728App\u4e2d\u83b7\u5f97MainFrame\u6307\u9488<br \/>\nCWinApp \u4e2d\u7684 m_pMainWnd\u53d8\u91cf\u5c31\u662fMainFrame\u7684\u6307\u9488<br \/>\n\u4e5f\u53ef\u4ee5\uff1a CMainFrame *pMain =(CMainFrame *)AfxGetMainWnd();<br \/>\n3) \u5728View\u4e2d\u83b7\u5f97MainFrame\u6307\u9488 CMainFrame *pMain=(CmaimFrame *)AfxGetApp()-&gt;m_pMainWnd;<br \/>\n4) \u83b7\u5f97View\uff08\u5df2\u5efa\u7acb\uff09\u6307\u9488 CMainFrame *pMain=(CmaimFrame *)AfxGetApp()-&gt;m_pMainWnd;<br \/>\nCyouView *pView=(CyouView *)pMain-&gt;GetActiveView();<br \/>\n5) \u83b7\u5f97\u5f53\u524d\u6587\u6863\u6307\u9488 CDocument * pCurrentDoc =(CFrameWnd *)m_pMainWnd-&gt;GetActiveDocument();<br \/>\n6) \u83b7\u5f97\u72b6\u6001\u680f\u4e0e\u5de5\u5177\u680f\u6307\u9488 CStatusBar * pStatusBar\uff1d(CStatusBar *)AfxGetMainWnd()-&gt;GetDescendantWindow(AFX_IDW_STATUS_BAR);<br \/>\nCToolBar * pToolBar=(CtoolBar *)AfxGetMainWnd()-&gt;GetDescendantWindow(AFX_IDW_TOOLBAR);<br \/>\n7) \u5982\u679c\u6846\u67b6\u4e2d\u52a0\u5165\u5de5\u5177\u680f\u548c\u72b6\u6001\u680f\u53d8\u91cf\u8fd8\u53ef\u4ee5\u8fd9\u6837<br \/>\n(CMainFrame *)GetParent()-&gt;m_wndToolBar;<br \/>\n(CMainFrame *)GetParent()-&gt;m_wndStatusBar;<br \/>\n8) \u5728Mainframe\u83b7\u5f97\u83dc\u5355\u6307\u9488 CMenu *pMenu=m_pMainWnd-&gt;GetMenu();<br \/>\n9) \u5728\u4efb\u4f55\u7c7b\u4e2d\u83b7\u5f97\u5e94\u7528\u7a0b\u5e8f\u7c7b<br \/>\n\u7528MFC\u5168\u5c40\u51fd\u6570 AfxGetApp()\u83b7\u5f97\u3002<br \/>\n10) \u4ece\u6587\u6863\u7c7b\u53d6\u5f97\u89c6\u56fe\u7c7b\u7684\u6307\u9488<br \/>\n\u6211\u662f\u4ece<wbr \/><a href=\"http:\/\/download.cqcnc.com\/soft\/program\/article\/vc\/vc405.html\" target=\"_blank\" rel=\"noopener noreferrer\"><u>http:\/\/download.cqcnc.com\/soft\/program\/article\/vc\/vc405.html<\/u><\/a><wbr \/>\u5b66 \u5230\u7684\uff0c<br \/>\n\u4ece\u6587\u6863\u83b7\u5f97\u89c6\u56fe\u7c7b\u6307\u9488\u76ee\u7684\u4e00\u822c\u4e3a\u4e86\u63a7\u5236\u540c\u4e00\u6587\u6863\u7684\u591a\u4e2a\u89c6\u56fe\u7684\u5b9a\u4f4d\u95ee\u9898\uff0c\u6211\u7684\u4f53\u4f1a<br \/>\n\u7279\u522b\u662f\u6587\u5b57\u5904\u7406CEditView\u5f53\u4ea7\u751f\u591a\u4e2a\u89c6\u56fe\u7c7b \u65f6\uff0c\u8fd9\u4e2a\u529f\u80fd\u662f\u975e\u5e38\u9700\u8981\u7684\u3002<br \/>\nCDocument\u7c7b\u63d0\u4f9b\u4e86\u4e24\u4e2a\u51fd\u6570\u7528\u4e8e\u89c6\u56fe\u7c7b\u7684\u5b9a\u4f4d\uff1a<br \/>\nGetFirstViewPosition()\u548c GetNextView()<br \/>\nvirtual POSITION GetFirstViewPosition() const;<br \/>\nvirtual CView* GetNextView(POSITION&amp; rPosition) const;<br \/>\n\u6ce8\u610f\uff1aGetNextView()\u62ec \u53f7\u4e2d\u7684\u53c2\u6570\u7528\u7684\u662f\u5f15\u7528\u65b9\u5f0f\uff0c\u56e0\u6b64\u6267\u884c\u540e\u503c\u53ef\u80fd\u6539\u53d8\u3002<br \/>\nGetFirstViewPosition()\u7528\u4e8e\u8fd4\u56de\u7b2c\u4e00\u4e2a\u89c6\u56fe\u4f4d\u7f6e\uff08\u8fd4\u56de\u7684\u5e76\u975e\u89c6\u56fe\u7c7b\u6307 \u9488\uff0c\u800c\u662f\u4e00<br \/>\n\u4e2aPOSITION\u7c7b\u578b\u503c\uff09\uff0cGetNextView()\u6709\u4e24\u4e2a\u529f\u80fd\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u89c6\u56fe\u7c7b\u7684\u6307\u9488\u4ee5\u53ca\u7528<br \/>\n\u5f15\u7528\u8c03\u7528\u7684\u65b9\u5f0f\u6765\u6539\u53d8\u4f20\u5165 \u7684POSITION\u7c7b\u578b\u53c2\u6570\u7684\u503c\u3002\u5f88\u660e\u663e\uff0c\u5728Test\u7a0b\u5e8f\u4e2d\uff0c\u53ea\u6709<br \/>\n\u4e00\u4e2a\u89c6\u56fe\u7c7b\uff0c\u56e0\u6b64\u53ea\u9700\u5c06\u8fd9\u4e24\u4e2a\u51fd\u6570\u8c03\u7528\u4e00\u6b21\u5373\u53ef\u5f97\u5230CTestView\u7684\u6307\u9488\u5982 \u4e0b\uff08\u9700\u5b9a<br \/>\n\u4e49\u4e00\u4e2aPOSITION\u7ed3\u6784\u53d8\u91cf\u6765\u8f85\u52a9\u64cd\u4f5c\uff09\uff1a<br \/>\nCTestView* pTestView;<br \/>\nPOSITION pos=GetFirstViewPosition();<br \/>\npTestView=GetNextView(pos);<br \/>\n\u8fd9\u6837\uff0c\u4fbf\u53ef\u5230\u4e86 CTestView\u7c7b\u7684\u6307\u9488pTestView.\u6267\u884c\u5b8c\u51e0\u53e5\u540e\uff0c\u53d8\u91cfpos=NULL,\u56e0\u4e3a\u6ca1<br \/>\n\u6709\u4e0b\u4e00\u4e2a\u89c6\u56fe\u7c7b\uff0c\u81ea\u7136\u4e5f\u6ca1\u6709\u4e0b\u4e00\u4e2a\u89c6\u56fe\u7c7b\u7684 POSITION.\u4f46\u662f\u8fd9\u51e0\u6761\u8bed\u53e5\u592a\u7b80\u5355\uff0c\u4e0d<br \/>\n\u5177\u6709\u592a\u5f3a\u7684\u901a\u7528\u6027\u548c\u5b89\u5168\u7279\u5f81\uff1b\u5f53\u8c61\u524d\u9762\u8bf4\u7684\u90a3\u6837\uff0c\u5f53\u8981\u5728\u591a\u4e2a\u89c6\u56fe\u4e3a\u4e2d\u8fd4\u56de\u67d0\u4e2a\u6307<br \/>\n\u5b9a\u7c7b\u7684\u6307\u9488 \u65f6\uff0c\u6211\u4eec\u9700\u8981\u904d\u5386\u6240\u6709\u89c6\u56fe\u7c7b\uff0c\u76f4\u5230\u627e\u5230\u6307\u5b9a\u7c7b\u4e3a\u6b62\u3002\u5224\u65ad\u4e00\u4e2a\u7c7b\u6307\u9488\u6307<br \/>\n\u5411\u7684\u662f\u5426\u67d0\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u65f6\uff0c\u53ef\u7528IsKindOf()\u6210\u5458\u51fd\u6570\u65f6\u884c\u68c0\u67e5\uff0c\u5982\uff1a<br \/>\npView-&gt;IsKindOf(RUNTIME_CLASS(CTestView));<br \/>\n\u5373 \u53ef\u68c0\u67e5pView\u6240\u6307\u662f\u5426\u662fCTestView\u7c7b\u3002<br \/>\n\u6709\u4e86\u4ee5\u4e0a\u57fa\u7840\uff0c\u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u4ece\u6587\u6863\u7c7b\u53d6\u5f97\u4efb\u4f55\u7c7b\u7684\u6307\u9488\u3002\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6211\u4eec\u5c06\u5176\u4f5c<br \/>\n\u4e3a\u4e00\u4e2a\u6587 \u6863\u7c7b\u7684\u6210\u5458\u51fd\u6570\uff0c\u5b83\u6709\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u8981\u83b7\u5f97\u54ea\u4e2a\u7c7b\u7684\u6307\u9488\u3002\u5b9e\u73b0\u5982\u4e0b\uff1a<br \/>\nCView* CTestDoc::GetView(CRuntimeClass* pClass)<br \/>\n{<br \/>\nCView* pView;<br \/>\nPOSITION pos=GetFirstViewPosition();<br \/>\nwhile(pos!=NULL){<br \/>\npView=GetNextView(pos);<br \/>\nif(!pView-&gt;IsKindOf(pClass))<br \/>\nbreak;<br \/>\n}<br \/>\nif(!pView-&gt;IsKindOf(pClass)){<br \/>\nAfxMessageBox(&#8220;Connt Locate the View.rn <wbr \/><a href=\"http:\/\/www.vckbase.com\/\" target=\"_blank\" rel=\"noopener noreferrer\"><u>http:\/\/www.VCKBASE.com<\/u><\/a><wbr \/>&#8220;);<br \/>\nreturn NULL;<br \/>\n}<br \/>\nreturn pView;<br \/>\n}<br \/>\n\u5176\u4e2d\u7528\u4e86\u4e24\u6b21\u89c6\u56fe\u7c7b\u7684\u6210\u5458\u51fd\u6570IsKindOf()\u6765\u5224\u65ad\uff0c\u662f\u56e0\u4e3a\u9000\u51fa while\u5faa\u73af\u6709\u4e09\u79cd<br \/>\n\u53ef\u80fd\uff1a<br \/>\n1.pos\u4e3aNULL\uff0c\u5373\u5df2\u7ecf\u4e0d\u5b58\u5728\u4e0b\u4e00\u4e2a\u89c6\u56fe\u7c7b\u4f9b\u64cd\u4f5c\uff1b<br \/>\n2.pView\u5df2\u7b26\u5408\u8981\u6c42\u3002<br \/>\n1\u548c2 \u540c\u662f\u6ee1\u8db3\u3002\u8fd9\u662f\u56e0\u4e3aGetNextView()\u7684\u529f\u80fd\u662f\u5c06\u5f53\u524d\u89c6\u56fe\u6307\u9488\u6539\u53d8\u6210\u4e00\u4e2a\u89c6\u56fe<br \/>\n\u7684\u4f4d\u7f6e\u540c\u65f6\u8fd4\u56de\u5f53\u524d\u89c6\u56fe\u6307\u9488\uff0c\u56e0\u6b64pos\u662fpView\u7684\u4e0b\u4e00 \u4e2a\u89c6\u56fe\u7c7b\u7684POSITION,\u5b8c\u5168<br \/>\n\u6709\u53ef\u80fd\u65e2\u662fpos==NULL\u53c8\u662fpView\u7b26\u5408\u9700\u8981\u3002\u5f53\u6240\u9700\u7684\u89c6\u56fe\u662f\u6700\u540e\u4e00\u4e2a\u89c6\u56fe\u662f\u6700\u540e\u4e00<br \/>\n\u4e2a\u89c6\u56fe\u7c7b\u65f6 \u5c31\u5982\u5f15\u3002\u56e0\u6b64\u9700\u91c7\u7528\u4e24\u6b21\u5224\u65ad\u3002<br \/>\n\u4f7f\u7528\u8be5\u51fd\u6570\u5e94\u9075\u5faa\u5982\u4e0b\u683c\u5f0f\uff08\u4ee5\u53d6\u5f97CTestView\u6307\u9488\u4e3a\u4f8b\uff09\uff1a<br \/>\nCTestView* pTestView=(CTestView*)GetView(RUNTIME_CLASS(CTestView));<br \/>\nRUNTIME_CLASS \u662f\u4e00\u4e2a\u5b8f\uff0c\u53ef\u4ee5\u7b80\u5355\u5730\u7406\u89e3\u5b83\u7684\u4f5c\u7528\uff1a\u5c06\u7c7b\u7684\u540d\u5b57\u8f6c\u5316\u4e3a<br \/>\nCRuntimeClass\u4e3a\u6307\u9488\u3002\u81f3\u4e8e\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u4e5f\u662f\u4e3a\u4e86\u5b89\u5168\u7279\u6027\u8003\u8651\u7684\uff0c\u56e0\u4e3a\u4ece\u540c\u4e00\u4e2a<br \/>\n\u57fa \u7c7b\u4e4b\u95f4\u7684\u6307\u9488\u7c7b\u578b\u662f\u4e92\u76f8\u517c\u5bb9\u7684\u3002\u8fd9\u79cd\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u4e5f\u8bb8\u5e76\u4e0d\u5fc5\u8981\uff0c\u4f46\u80fd\u907f\u514d\u4e00<br \/>\n\u4e9b\u53ef\u80fd\u51fa\u73b0\u7684\u9ebb\u70e6\u3002<br \/>\n3.\u4ece\u4e00\u4e2a\u89c6\u56fe\u7c7b\u53d6\u5f97\u53e6\u4e00\u89c6\u56fe\u7c7b\u7684\u6307\u9488 \u7efc\u54081\u548c2\uff0c\u5f88\u5bb9\u6613\u5f97\u51fa\u89c6\u56fe\u7c7b\u4e4b\u95f4\u4e92\u76f8\u83b7\u5f97<br \/>\n\u6307\u9488\u7684\u65b9\u6cd5\uff1a\u5c31\u662f\u7528\u6587\u6863\u7c7b\u4f5c\u4e2d\u8f6c\uff0c\u5148\u75281\u7684\u65b9\u6cd5\u5f97\u5230\u6587\u6863\u7c7b\u7684\u6307\u9488\uff0c\u518d\u75282\u7684\u65b9\u6cd5\uff0c<br \/>\n\u4ee5\u6587\u6863\u7c7b\u7684\u89c6 \u56fe\u5b9a\u4f4d\u51fd\u6570\u53d6\u5f97\u53e6\u4e00\u4e2a\u89c6\u56fe\u7c7b\u3002\u540c\u6837\uff0c\u53ef\u4ee5\u5b9e\u73b0\u6210\u4e00\u4e2a\u51fd\u6570\uff1a<br \/>\n\uff08\u5047\u8bbe\u8981\u4eceCTestAView\u4e2d\u53d6\u5f97\u6307\u5411\u5176\u5b83\u89c6\u56fe\u7c7b\u7684\u6307\u9488\uff09<br \/>\nCView* CTestAView::GetView(CRuntimeClass* pClass)<br \/>\n{<br \/>\nCTestDoc* pDoc=(CTestDoc*)GetDocument();<br \/>\nCView* pView;<br \/>\nPOSITION pos=pDoc-&gt;GetFirstViewPosition();<br \/>\nwhile(pos!=NULL){<br \/>\npView=pDoc-&gt;GetNextView(pos);<br \/>\nif(!pView-&gt;IsKindOf(pClass))<br \/>\nbreak;<br \/>\n}<br \/>\nif(!pView-&gt;IsKindOf(pClass)){<br \/>\nAfxMessageBox(&#8220;Connt Locate the View.&#8221;);<br \/>\nreturn NULL;<br \/>\n}<br \/>\nreturn pView;<br \/>\n}<br \/>\n\u8fd9\u4e2a\u51fd \u6570\u548c2\u4e2d\u7684GetView()\u76f8\u6bd4\uff0c\u4e00\u662f\u591a\u4e86\u7b2c\u4e00\u53e5\u4ee5\u53d6\u5f97\u6587\u6863\u7c7b\u6307\u9488\uff0c\u4e8c\u662f\u5728<br \/>\nGetFirstViewPosition()\u548c GetNextView()\u524d\u52a0\u4e0a\u4e86\u6587\u6863\u7c7b\u6307\u9488\uff0c\u4ee5\u8868\u793a\u5b83\u4eec\u662f\u6587\u6863<br \/>\n\u7c7b\u6210\u5458\u51fd\u6570\u3002\u6709\u4e86\u6b64\u51fd\u6570\uff1b\u5f53\u8981\u4eceCTestAView\u4e2d\u53d6\u5f97 CTestBView\u7684\u6307\u9488\u65f6\uff0c\u53ea\u9700\u5982<br \/>\n\u4e0b\uff1aCTestBView* pTestbView=(CTestView*)GetView(RUNTIME_CLASS(CTestBView));<br \/>\n\u5bf9\u4e8e\u5355\u6587\u6863\u4e2d\u4e5f\u53ef\u4ee5\u52a0 \u5165\u591a\u4e2a\u6587\u6863\u6a21\u677f\uff0c\u4f46\u662f\u4e00\u822c\u7684\u5f00\u53d1\u5c31\u4f7f\u7528MDI\u65b9\u5f0f\u5f00\u53d1<br \/>\n\u591a\u6587\u6863\u6a21\u677f\uff0c\u5176\u65b9\u6cd5\u4e0e\u4e0a\u8ff0\u89c6\u56fe\u7684\u83b7\u53d6\u65b9\u6cd5\u5f88\u63a5\u8fd1\uff0c\u8fd9\u91cc\u7a0d\u505a\u89e3\u91ca\uff0c\u5982\u679c\u4e0d\u6e05\u695a\uff0c<br \/>\n\u8bf7\u67e5\u9605 MSDN\uff0c\uff08\u4ee5\u4e0b\u56db\u4e2a\u5185\u5bb9\uff0811\u300112\u300113\u300114\uff09\u6765\u6e90\uff1a<br \/>\nhttp:\/\/sanjianxia.myrice.com\/vc \/vc45.htm\uff09<br \/>\n\u53ef\u4ee5\u7528CWinApp::GetFirstDocTemplatePostion\u83b7\u5f97\u5e94\u7528\u7a0b\u5e8f\u6ce8\u518c\u7684\u7b2c\u4e00\u4e2a\u6587\u6863\u6a21\u677f<br \/>\n\u7684 \u4f4d\u7f6e\uff1b\u5229\u7528\u8be5\u503c\u6765\u8c03\u7528CWinApp::GetNextDocTemplate\u51fd\u6570\uff0c\u83b7\u5f97\u7b2c\u4e00\u4e2a<br \/>\nCDocTemplate\u5bf9\u8c61\u6307\u9488\u3002 POSITION GetFirstDocTemplate( ) const;<br \/>\nCDocTemplate *GetNextDocTemplate( POSITION &amp; pos ) const;<br \/>\n\u7b2c\u4e8c\u4e2a\u51fd\u6570\u8fd4\u56de\u7531pos \u6807\u8bc6\u7684\u6587\u6863\u6a21\u677f\u3002POSITION\u662fMFC\u5b9a\u4e49\u7684\u4e00\u4e2a\u7528\u4e8e\u8fed\u4ee3\u6216\u5bf9\u8c61<br \/>\n\u6307\u9488\u68c0\u7d22\u7684\u503c\u3002\u901a\u8fc7\u8fd9\u4e24\u4e2a\u51fd\u6570\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u904d\u5386\u6574\u4e2a\u6587\u6863\u6a21\u677f\u5217\u8868\u3002\u5982\u679c\u88ab\u68c0 \u7d22<br \/>\n\u7684\u6587\u6863\u6a21\u677f\u662f\u6a21\u677f\u5217\u8868\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\uff0c\u5219pos\u53c2\u6570\u88ab\u7f6e\u4e3aNULL\u3002<br \/>\n12\uff09\u4e00\u4e2a\u6587\u6863\u6a21\u677f\u53ef\u4ee5\u6709\u591a\u4e2a\u6587\u6863\uff0c\u6bcf\u4e2a\u6587\u6863\u6a21\u677f\u90fd\u4fdd\u7559\u5e76\u7ef4 \u62a4\u4e86\u4e00\u4e2a\u6240\u6709\u5bf9\u5e94\u6587<br \/>\n\u6863\u7684\u6307\u9488\u5217\u8868\u3002<br \/>\n\u7528CDocTemplate::GetFirstDocPosition\u51fd\u6570\u83b7\u5f97\u4e0e\u6587\u6863\u6a21\u677f\u76f8\u5173\u7684\u6587 \u6863\u96c6\u5408\u4e2d\u7b2c\u4e00<br \/>\n\u4e2a\u6587\u6863\u7684\u4f4d\u7f6e\uff0c\u5e76\u7528POSITION\u503c\u4f5c\u4e3aCDocTemplate::GetNextDoc\u7684\u53c2\u6570\u6765\u91cd\u590d\u904d\u5386\u4e0e<br \/>\n\u6a21\u677f\u76f8\u5173\u7684 \u6587\u6863\u5217\u8868\u3002\u51fd\u6570\u539f\u5f62\u4e3a\uff1a<br \/>\nviaual POSITION GetFirstDocPosition( ) const = 0;<br \/>\nvisual CDocument *GetNextDoc(POSITION &amp; rPos) const = 0;<br \/>\n\u5982\u679c\u5217\u8868\u4e3a\u7a7a\uff0c\u5219 rPos\u88ab\u7f6e\u4e3aNULL.<br \/>\n13\uff09\u5728\u6587\u6863\u4e2d\u53ef\u4ee5\u8c03\u7528CDocument::GetDocTemplate\u83b7\u5f97\u6307\u5411\u8be5\u6587\u6863\u6a21\u677f\u7684\u6307\u9488\u3002<br \/>\n\u51fd \u6570\u539f\u5f62\u5982\u4e0b\uff1a CDocTemplate * GetDocTemplate ( ) const;<br \/>\n\u5982\u679c\u8be5\u6587\u6863\u4e0d\u5c5e\u4e8e\u6587\u6863\u6a21\u677f\u7ba1\u7406\uff0c\u5219\u8fd4\u56de\u503c\u4e3a NULL\u3002<br \/>\n14)\u4e00\u4e2a\u6587\u6863\u53ef\u4ee5\u6709\u591a\u4e2a\u89c6\u3002\u6bcf\u4e00\u4e2a\u6587\u6863\u90fd\u4fdd\u7559\u5e76\u7ef4\u62a4\u4e00\u4e2a\u6240\u6709\u76f8\u5173\u89c6\u7684\u5217\u8868\u3002<br \/>\nCDocument::AddView \u5c06\u4e00\u4e2a\u89c6\u8fde\u63a5\u5230\u6587\u6863\u4e0a\uff0c\u5c06\u8be5\u89c6\u52a0\u5165\u5230\u6587\u6863\u76f8\u8054\u7cfb\u7684\u89c6\u7684\u5217\u8868<br \/>\n\u4e2d\uff0c\u5e76\u5c06\u89c6\u7684\u6587\u6863\u6307\u9488\u6307\u5411\u8be5\u6587\u6863\u3002\u5f53\u6709File\/New\u3001File\/Open\u3001 Windows\/New\u6216<br \/>\nWindow\/Split\u7684\u547d\u4ee4\u800c\u5c06\u4e00\u4e2a\u65b0\u521b\u5efa\u7684\u89c6\u7684\u5bf9\u8c61\u8fde\u63a5\u5230\u6587\u6863\u4e0a\u65f6\uff0c MFC\u4f1a\u81ea\u52a8\u8c03\u7528<br \/>\n\u8be5\u51fd\u6570\uff0c\u6846\u67b6\u901a\u8fc7 \u6587\u6863\/\u89c6\u7684\u7ed3\u6784\u5c06\u6587\u6863\u548c\u89c6\u8054\u7cfb\u8d77\u6765\u3002\u5f53\u7136\uff0c\u7a0b\u5e8f\u5458\u4e5f\u53ef\u4ee5\u6839\u636e\u81ea<br \/>\n\u5df1\u7684\u9700\u8981\u8c03\u7528\u8be5\u51fd\u6570\u3002<br \/>\nVirtual POSITION GetFirstViewPosition( ) const;<br \/>\nVirtual CView * GetNextView( POSITION &amp;rPosition) cosnt;<br \/>\n\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u8c03\u7528CDocument::GetFirstViewPosition\u8fd4 \u56de\u4e0e\u8c03\u7528\u6587\u6863\u76f8\u8054\u7cfb\u7684\u89c6\u7684<br \/>\n\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u89c6\u7684\u4f4d\u7f6e\uff0c\u5e76\u8c03\u7528CDocument::GetNextView\u8fd4\u56de\u6307\u5b9a\u4f4d\u7f6e\u7684\u89c6\uff0c\u5e76\u5c06<br \/>\nrPositon \u7684\u503c\u7f6e\u4e3a\u5217\u8868\u4e2d\u4e0b\u4e00\u4e2a\u89c6\u7684POSITION\u503c\u3002\u5982\u679c\u627e\u5230\u7684\u89c6\u4e3a\u5217\u8868\u4e2d\u7684\u6700\u540e\u4e00\u4e2a<br \/>\n\u89c6\uff0c\u5219\u5c06rPosition\u7f6e\u4e3aNULL.<br \/>\n15) \u4ece\u4e00\u4e2a\u89c6\u56fe\u7c7b\u53d6\u5f97\u53e6\u4e00\u89c6\u56fe\u7c7b\u7684\u6307\u9488<br \/>\n\u8fd9\u4e2a\u5e94\u7528\u5728\u591a\u89c6\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5f88\u591a\u89c1\uff0c\u4e00\u822c\u5982\u679c\u81ea\u5df1\u5728\u4e3b\u7a0b\u5e8f\u6216\u8005\u4e3b\u6846\u67b6\u4e2d\u505a\u597d\u53d8<br \/>\n\u91cf\u8bb0\u53f7\uff0c\u4e5f\u53ef\u4ee5\u83b7\u5f97\uff0c\u8fd8\u6709 \u6bd4\u8f83\u901a\u7528\u7684\u5c31\u662f\u7528\u6587\u6863\u7c7b\u4f5c\u4e2d\u8f6c\uff0c\u4ee5\u6587\u6863\u7c7b\u7684\u89c6\u56fe\u904d\u5386<br \/>\n\u5b9a\u4f4d\uff0c\u53d6\u5f97\u53e6\u4e00\u4e2a\u89c6\u56fe\u7c7b\u3002\u8fd9\u4e2a\u529f\u80fd\u4ece\u672c\u6587\u7b2c10\u9879\u4e2d\u53ef\u4ee5\u5f97\u5230\u3002<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6e90\u5730\u5740\uff1ahttp:\/\/blog.csdn.net\/yincheng01\/archive\/2009\/01\/06\/ <a href='http:\/\/prayerlaputa.com\/?p=418' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4],"tags":[28],"_links":{"self":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/418"}],"collection":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=418"}],"version-history":[{"count":1,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/418\/revisions"}],"predecessor-version":[{"id":691,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/418\/revisions\/691"}],"wp:attachment":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}