说明: CMyFormView:public CFormView {}; 在FormView放了一个Edit(IDC_TEST_EDIT)控件,在程序中设置Edit中显示的字符串为:“This is the testing string!” 具体的步骤为: 添加菜单: Test Aceess FormView From CMainFrame //like the following: IDR_MAINFRAME MENU POPUP "Test" BEGIN MENUITEM "Aceess FormView From CMainFrame", ID_ACCESS_FORMVIEW END ---------------------------------------------------------- //file:MainFrm.cpp .... #include "MainFrm.h" #include "FormDoc.h" #include "FormView.h" .... void CMainFrame::OnAccessFormview() { //在MainFrame中访问FormView中的变量 // TODO: Add your command handler code here CMyFormView *pFormView=(CMyFormView*)this->GetActiveView(); CEdit *pEdit=(CEdit*)pFormView->GetDlgItem(IDC_TEST_EDIT); pEdit->SetWindowText("This is the testing string!"); }
(CYourView*)GetActiveView()->成员变量。
最安全的方法是:
CFrameWnd * pFrameWnd=(CFrameWnd*)AfxGetMainWnd();
CView* pView=pFrameWnd->GetActiveFrame()->GetActiveView();
...pView->成员变量...;
可惜反过来调用我也不知道:(
CView* pView=pFrameWnd->GetActiveFrame()->GetActiveView();
CMyFormView:public CFormView
{};
在FormView放了一个Edit(IDC_TEST_EDIT)控件,在程序中设置Edit中显示的字符串为:“This is the testing string!”
具体的步骤为:
添加菜单:
Test
Aceess FormView From CMainFrame
//like the following:
IDR_MAINFRAME MENU
POPUP "Test"
BEGIN
MENUITEM "Aceess FormView From CMainFrame", ID_ACCESS_FORMVIEW
END
----------------------------------------------------------
//file:MainFrm.cpp
....
#include "MainFrm.h"
#include "FormDoc.h"
#include "FormView.h"
....
void CMainFrame::OnAccessFormview()
{
//在MainFrame中访问FormView中的变量
// TODO: Add your command handler code here
CMyFormView *pFormView=(CMyFormView*)this->GetActiveView();
CEdit *pEdit=(CEdit*)pFormView->GetDlgItem(IDC_TEST_EDIT);
pEdit->SetWindowText("This is the testing string!");
}