Har*_*vey 0 mfc docview visual-c++
由OP编辑.
我的计划需要进行大量的清理和重组.
在另一篇文章中,我询问了如何离开MFC DocView框架并转向WinProc和Message Loop方式(简称为什么?).那么目前我在想我应该清理Doc View中的内容,也许以后转换为非MFC甚至是有意义的.我的Document类目前几乎没有任何用处.
我认为一个开始的地方是InitInstance()函数(发布在下面).
在这部分:
POSITION pos=pDocTemplate->GetFirstDocPosition();
CLCWDoc *pDoc=(CLCWDoc *)pDocTemplate->GetNextDoc(pos);
ASSERT_VALID(pDoc);
POSITION vpos=pDoc->GetFirstViewPosition();
CChildView *pCV=(CChildView *)pDoc->GetNextView(vpos);
Run Code Online (Sandbox Code Playgroud)
这对我来说很奇怪.我只有一个文档和一个视图.我觉得我正在使用GetNextDoc()和GetNextView()向后推进它.尝试使用愚蠢的比喻; 这就像我手里拿着一本书,但我必须查看它的索引,找出书的标题所在的页面.我厌倦了对我的代码感到尴尬.我需要纠正或保证,或两者兼而有之.:)
此外,所有杂项都没有特别的顺序.我想将它们重新排列成可能更标准,更有条理或更直接的订单.
欢迎所有建议!
BOOL CLCWApp::InitInstance()
{
InitCommonControls();
if(!AfxOleInit())
return FALSE;
// Initialize the Toolbar dll. (Toolbar code by Nikolay Denisov.)
InitGuiLibDLL(); // NOTE: insert GuiLib.dll into the resource chain
SetRegistryKey(_T("Real Name Removed"));
// Register document templates
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CLCWDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CChildView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCmdLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
// The window frame appears on the screen in here.
if (!ProcessShellCommand(cmdInfo))
{
AfxMessageBox("Failure processing Command Line");
return FALSE;
}
POSITION pos=pDocTemplate->GetFirstDocPosition();
CLCWDoc *pDoc=(CLCWDoc *)pDocTemplate->GetNextDoc(pos);
ASSERT_VALID(pDoc);
POSITION vpos=pDoc->GetFirstViewPosition();
CChildView *pCV=(CChildView *)pDoc->GetNextView(vpos);
if(!cmdInfo.m_Fn1.IsEmpty() && !cmdInfo.m_Fn2.IsEmpty())
{
pCV->OpenF1(cmdInfo.m_Fn1);
pCV->OpenF2(cmdInfo.m_Fn2);
pCV->DoCompare(); // Sends a paint message when complete
}
// enable file manager drag/drop and DDE Execute open
m_pMainWnd->DragAcceptFiles(TRUE);
m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
m_pMainWnd->UpdateWindow(); // paints the window background
pCV->bDoSize=true; //Prevent a dozen useless size calculations
return TRUE;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
如果不知道你的程序应该做什么,很难给你很好的建议.我只有一些一般性的评论:
InitInstance看起来并不是很混乱.它的标准配置包括一些自定义代码.CChildView* CLCWApp::GetFirstView()但只有在一个地方才需要它时,这只是化妆品.如果您只有一个视图,那么您正在做什么以及您在Document类和View类中放置哪些数据更像是一个语义问题.(无论如何,你只有一个文档,因为它是一个SDI应用程序.).从技术角度来看,两者都是可能的.但是为了(可能)以后扩展到多个视图并遵循文档/视图体系结构的标准模式,有一些经验法则:
pCV->OpenF1(cmdInfo.m_Fn1) ... and so on做了什么,但如果它像文件或文件名或用于以任何方式访问数据的参数OpenF1可能是更好的文档类的方法.GetDocument()在View类中拥有简单的访问器来检索成员或调用Doc的方法.要将视图中的数据提取到文档中,需要遍历视图列表.(请记住:即使在SDI应用程序中,Doc-View也是1-n关系.)只需几美分.
| 归档时间: |
|
| 查看次数: |
492 次 |
| 最近记录: |