您的位置:首页 > 其它

the relationship of view, doc and frame

2011-11-09 13:55 387 查看
对话框上建立一个文档视图模型代码,两个思路都遇到问题进行不下去。

1.first attempt

使用已有的框架机制:

CSingleDocTemplate* pDocTemplate;

pDocTemplate = new CSingleDocTemplate(

IDR_MENU_DIALOG,

RUNTIME_CLASS(CDialogBasedDoc),

RUNTIME_CLASS(CDialogBasedView), // 主 SDI 框架窗口

RUNTIME_CLASS(CDialogBasedFrameView));

if (!pDocTemplate)

return FALSE;

AddDocTemplate(pDocTemplate); ///CDialog 不具备这样的成员函数。 它来自CWinApp.

2.手工建立它们的关系:

CCreateContext context;

context.m_pCurrentDoc=m_pDialogBasedDoc;

context.m_pCurrentFrame=(CFrameWnd*)this;//the frame pointer point to itself

context.m_pLastView=NULL;//the previous view is NULL

context.m_pNewDocTemplate=NULL;///the templateDoc is NULL;

context.m_pNewViewClass=RUNTIME_CLASS(CDialogBasedFrameView);

m_pView=(CDialogBasedFrameView*)context.m_pNewViewClass->CreateObject();///create the view object

if(m_pView==NULL)

{

TRACE1("Warning: Dynamic creating of view type %hs failed.\n",

context.m_pNewViewClass->m_lpszClassName);

}

ASSERT_KINDOF(CWnd,m_pView);

if(!m_pView->Create(NULL, ///lpszClassNamem

NULL, ///window Namen

AFX_WS_DEFAULT_VIEW, ///window style

RectTargetCtrl,

this, ///parent pointer

AFX_IDW_PANE_FIRST, ///ID of the child window

&context)) ///CCreateContext struct

{

TRACE0("Warning: Couldn't create view for frame.\n");

return FALSE;

}

//TRY load menu bar

CMenu *ptrDlgMenu=new CMenu();

ptrDlgMenu->LoadMenuW(IDR_MENU_DIALOG);

SetMenu(ptrDlgMenu);

DrawMenuBar();

//menu belongs to an CWnd Object.

//视图建立正常,但对话框上的菜单条命令无法路由进doc类对象。

(November 9,2011)

November 10,2011

目标前思路,

在CWinApp类的InitInstance()添加一个新的文档模板类。

在派生出的对话框类中使用该docTemplate对象,建立另外一个view/doc框架程序。

问题是,在新的对话框类中,怎样使用传进来位于CWinApp中的docTemplate来关联需要的view/doc类,并形成正确的消息命令路由机制。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐