Help to restructure my Doc/View more correctly

Posted by Harvey on Stack Overflow See other posts from Stack Overflow or by Harvey
Published on 2010-03-23T00:10:57Z Indexed on 2010/03/23 21:23 UTC
Read the original article Hit count: 319

Filed under:
|
|

Edited by OP.
My program is in need of a lot of cleanup and restructuring.

In another post I asked about leaving the MFC DocView framework and going to the WinProc & Message Loop way (what is that called for short?). Well at present I am thinking that I should clean up what I have in Doc View and perhaps later convert to non-MFC it that even makes sense. My Document class currently has almost nothing useful in it.

I think a place to start is the InitInstance() function (posted below).
In this part:

POSITION pos=pDocTemplate->GetFirstDocPosition();
CLCWDoc *pDoc=(CLCWDoc *)pDocTemplate->GetNextDoc(pos);
ASSERT_VALID(pDoc);
POSITION vpos=pDoc->GetFirstViewPosition();
CChildView *pCV=(CChildView *)pDoc->GetNextView(vpos);

This seem strange to me. I only have one doc and one view. I feel like I am going about it backwards with GetNextDoc() and GetNextView(). To try to use a silly analogy; it's like I have a book in my hand but I have to look up in it's index to find out what page the Title of the book is on. I'm tired of feeling embarrassed about my code. I either need correction or reassurance, or both. :)

Also, all the miscellaneous items are in no particular order. I would like to rearrange them into an order that may be more standard, structured or straightforward.

ALL suggestions welcome!

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;
}

Thanks

© Stack Overflow or respective owner

Related posts about visual-c++

Related posts about mfc