the relationship of view, doc and frame

对话框上建立一个文档视图模型代码,两个思路都遇到问题进行不下去。

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类,并形成正确的消息命令路由机制。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值