1 在索引中 键入 CDocTemplate 回车 2 在弹出的3个选项中选 1 3 出现 CDocTemplate 的简介 走道最下面 找到 For more information on CDocTemplate, see Document Templates and the Document/View Creation Process in Visual C++ Programmer's Guide.4 点击 连接就可以了…… Document Templates and the Document/View Creation Process5 慢慢看了,还有其他的一些连接……
2 在弹出的3个选项中选 1
3 出现 CDocTemplate 的简介
走道最下面 找到
For more information on CDocTemplate, see Document Templates and the Document/View Creation Process in Visual C++ Programmer's Guide.4 点击 连接就可以了…… Document Templates and the Document/View Creation Process5 慢慢看了,还有其他的一些连接……
但如何在CWinApp类得到和使用所新建文档的视图类或者文档类呢?
CXXApp::OnFileNew()
{
CWinApp::OnFileNew();
}
直接Trace进去就可以看到全部过程
不知道它是如何实现的,所以我认为应该理解一些其实现过程!
{
POSITION posDoc=pDocTemplate->GetFirstDocPosition();
CDocument* pDocument =NULL;
if(posDoc!=NULL){
pDocument =pDocTemplate->GetNextDoc(posDoc);
//To get the first view in the list of views: POSITION posView = pDocument ->GetFirstViewPosition();
while(posView){//modified for viewbar
CView* pFirstView = pDocument ->GetNextView(posView);
ASSERT(pFirstView !=NULL);
pFirstView ->GetParentFrame()->GetLastActivePopup()->BringWindowToTop();
}
return pDocument;
}
else{
pDocument =pDocTemplate->CreateNewDocument();
if (pDocument == NULL)
{
TRACE0("CDocTemplate::CreateNewDocument returned NULL.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return NULL;
}
ASSERT_VALID(pDocument);
CString strTitle;
pDocTemplate->GetDocString(strTitle,CDocTemplate::windowTitle);
pDocument->SetTitle(strTitle);
BOOL bAutoDelete = pDocument->m_bAutoDelete;
pDocument->m_bAutoDelete = FALSE; // don't destroy if something goes wrong
CFrameWnd* pFrame = pDocTemplate->CreateNewFrame(pDocument, NULL);
pDocument->m_bAutoDelete = bAutoDelete;
if (pFrame == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
delete pDocument; // explicit delete on error
return NULL;
}
ASSERT_VALID(pFrame);
if (!pDocument->OnNewDocument())
{
// user has be alerted to what failed in OnNewDocument
TRACE0("CDocument::OnNewDocument returned FALSE.\n");
pFrame->DestroyWindow();
return NULL;
}
// it worked, now bump untitled count
pDocTemplate->InitialUpdateFrame(pFrame ,pDocument,TRUE);
pFrame->ShowWindow(SW_SHOWMAXIMIZED);
}
return pDocument ;
}
首先谢谢您的代码!
但我还是有点不太明白。
我使用下面的代码调用您写的函数:
POSITION pos=GetFirstDocTemplatePosition();
CDocTemplate *pDocTemplate=GetNextDocTemplate(pos);
CTestDoc *pDocument=(CTestDoc *)CreateNewFrameViewDoc( (CMultiDocTemplate *)pDocTemplate );
然后使用下面的代码用所得到的文档指针将其变量赋值,
pDocument->m_fNewPrice=2.0f;
最后更新视图显示,
pDocument->UpdateAllViews(NULL);
最终发现没有任何变化,这是为什么?
是我的使用方法不对吗?
串行化?不行的!
我意思好像没有说明白。
我是象PowerPoint中向导那样,当然也允许创建空文档的,如何直接几下串行化的话,将不能再创建空文档了!
比如我的视图类CTestView的基类为CFormView类,其中有一个编辑控件,其对应变量为CString m_oPriceEdit;
文档类为CTestDoc,对应视图类的变量m_fNewPrice;
现在我想用两种方法建立空文档,一种是直接使用默认的方法建立,另外一种是自定义内容的方法,即新建一个空文档时直接将m_fNewPrice赋值为2.0,同时编辑框中也显示2.0;
应该如何编写代码?
in CMyFormmView::DoDataExchange(CDataExchange* pDX){
CMyDoc* pDoc=GetDocument();
......
//不要在MFC注释里面写
DDX_Text(pDX,IDC_PRICE,pDoc->m_fNewPrice);
}
由于这两天我的Win2000系统崩溃了,一些数据也丢失了,因此一直忙于修复系统,所以没有来得及给您加分,耽误了几天,非常抱歉!今天系统终于正常了,在下不敢再耽搁了,现在开始加分!
请查收!
其内容为:
[请教简单问题——关于视图更新] --30
比如我的视图类CTestView的基类为CFormView类,其中有一个编辑控件,其对应变量为CString m_oPriceEdit;
对应文档类为CTestDoc,其对应视图类的变量double m_fNewPrice;
现在我想用设置文档类变量m_fNewPrice=2.0f,如何让它的编辑框中也显示2.0呢?应该如何编写更新视图类的代码呢?
谢谢!
请访问帖子:
http://www.csdn.net/expert/topic/229/229096.shtm