save views

来源:互联网 发布:安装办公软件 编辑:程序博客网 时间:2024/05/01 02:48

BOOL CScribbleApp::InitInstance()
{
 // Standard initialization
 // If you are not using these features and wish to reduce the size
 //  of your final executable, you should remove from the following
 //  the specific initialization routines you do not need.

#ifdef _AFXDLL
 Enable3dControls();                     // Call this when using MFC in a shared DLL
#else
 Enable3dControlsStatic();       // Call this when linking to MFC statically
#endif

 LoadStdProfileSettings();  // Load standard INI file options (including MRU)

 
 // Register the application's document templates.  Document templates
 //  serve as the connection between documents, frame windows and views.

 CMultiDocTemplate* pDocTemplate;
 pDocTemplate = new CMultiDocTemplate(
  IDR_SCRIBBTYPE,
  RUNTIME_CLASS(CScribbleDoc),
  RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  RUNTIME_CLASS(CScribbleView));

 AddDocTemplate(pDocTemplate);

 // create main MDI Frame window
 CMainFrame* pMainFrame = new CMainFrame;
 if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  return FALSE;
 m_pMainWnd = pMainFrame;

 // Enable drag/drop open.  We don't call this in Win32, since a
 //  document file extension wasn't chosen while running AppWizard.
 m_pMainWnd->DragAcceptFiles();

 // Enable DDE Execute open
 EnableShellOpen();
 RegisterShellFileTypes(TRUE);

 // Parse command line for standard shell commands, DDE, file open
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);

 // Dispatch commands specified on the command line
 
 // The main window has been initialized, so show and update it.
 BOOL bOpened = FALSE;
 // if (0)
 {
  {
   regex expression("(//b//d{4}[- ]){3}//d{4}//b", boost::regex::perl|boost::regex::icase);
   CString in = "a 3333-4444-5555-6666";
   CString sRet;
   boost::cmatch what;
   
   if(boost::regex_match(LPCSTR(in), what, expression))//CString转string
   {
    int i = 0;
    for(i=0;i<what.size();i++)
    {
     sRet = (what.str()).c_str();//string转CString
    }
   }
   else
   {
   }
  }
  RECT rc;
  if (COption::Load(OPTION_UI_SEC, OPTION_UI_FRAMEWNDRECT, &rc))
   pMainFrame->MoveWindow(&rc);
  CString recentFils, file_info;
  int nStart = 0, nEnd = 0;
  if (COption::Load(OPTION_REC_FILES, OPTION_REC_FILE, &recentFils))
  {
   while (TRUE)
   {
    nStart = recentFils.Find(_T('<'), nStart);
    nEnd = recentFils.Find('>', nStart);
    if (nStart>=0 && nEnd>0)
    {
     file_info = recentFils.Mid(nStart+1, nEnd-nStart-1);
     int len_file_info = file_info.GetLength();
     CString file_path;
     int n1, n2;
     n1 = file_info.Find(_T('/"')); n2 = file_info.Find(_T('/"'), n1+1);
     if (n1>=0 && n2>0 && n2-n1-1>0 && n1<len_file_info && n2<len_file_info)
     {
      file_path = file_info.Mid(n1+1, n2-n1-1);
      n1 = n2 + 1;
      CStringArray view_titles;
      CArray<RECT, RECT> view_rcs;
      while (n1>0 && n1<len_file_info)
      {
       int n1_, n2_;
       n1_ = file_info.Find(_T('/"'), n1);
       n2_ = file_info.Find(_T('/"'), n1_+1);
       if (n1_>=0 && n2_>0 && n1_<len_file_info && n2_<len_file_info)
       {
        view_titles.Add(file_info.Mid(n1_+1, n2_-n1_-1));
        CString strRc = file_info.Mid(n2_+1);
        RECT rc;
        sscanf((LPCTSTR)strRc, "%d %d %d %d", &rc.left, &rc.top, &rc.right, &rc.bottom);
        view_rcs.Add(rc);
       }
       n1 = file_info.Find(_T(';'), n2_)+1;
      }
      CDocument *pDoc = OpenDocumentFile(file_path);
      if (pDoc!=NULL)
      {
       POSITION posvw = pDoc->GetFirstViewPosition();
       while (posvw != NULL)
       {
        CView* pView = pDoc->GetNextView(posvw);
        CFrameWnd* pFrame = pView->GetParentFrame();
        ASSERT_VALID(pFrame);
        RECT rc = view_rcs.GetAt(0);
        CWnd *pParentWnd = pFrame->GetParent();
        RECT rcParent;
        if (pParentWnd!=NULL)
        {
         pParentWnd->GetClientRect(&rcParent);
         pParentWnd->ScreenToClient(&rc);
        }
        if (rc.left<0 || rc.top<0)
        {
         if (pFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)))
          ((CMDIChildWnd*)pFrame)->MDIMaximize();
        }
        else
         pFrame->MoveWindow(&rc);
       }
       if (cmdInfo.m_nShellCommand==CCommandLineInfo::FileNew)
        cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
      }
     }
    }
    else
     break;
    nStart = nEnd + 1;
   }
  }
 }
 if (!ProcessShellCommand(cmdInfo))
  return FALSE;
 
   
 pMainFrame->ShowWindow(m_nCmdShow);
 pMainFrame->UpdateWindow();

 return TRUE;
}

 

void CMainFrame::OnClose()
{
 // TODO: Add your message handler code here and/or call default
 CScribbleApp* app = dynamic_cast<CScribbleApp*>(AfxGetApp());
 if (app!=NULL && app->IsKindOf(RUNTIME_CLASS(CScribbleApp)))
 {
  CString szSave;
  POSITION pos = app->GetFirstDocTemplatePosition();
  while (pos != NULL)
  {
   CMultiDocTemplate* pMDT = dynamic_cast<CMultiDocTemplate*>(app->GetNextDocTemplate(pos));
   if (pMDT!=NULL && pMDT->IsKindOf(RUNTIME_CLASS(CMultiDocTemplate)))
   {
    POSITION posmdt = pMDT->GetFirstDocPosition();
    while (posmdt != NULL)
    {
     CScribbleDoc* pDoc = dynamic_cast<CScribbleDoc*>(pMDT->GetNextDoc(posmdt));
     if (pDoc!=NULL && pDoc->IsKindOf(RUNTIME_CLASS(CScribbleDoc)))
     {
      CString file = pDoc->GetPathName();
      if (!file.IsEmpty())
      {
       CString view_info, view_info_tmp;
       POSITION posvw = pDoc->GetFirstViewPosition();
       while (posvw != NULL)
       {
        CView* pView = pDoc->GetNextView(posvw);
        CFrameWnd* pFrame = pView->GetParentFrame();
        ASSERT_VALID(pFrame);
        
        CString title;
        pFrame->GetWindowText(title);
       
        view_info_tmp += CString(_T("/"")) + title + _T("/"");
        RECT rc;
        pFrame->GetWindowRect(&rc);
        view_info.Format(_T("%s %d %d %d %d;"), (LPCTSTR)view_info_tmp, rc.left, rc.top, rc.right, rc.bottom);
       }
       if (!view_info.IsEmpty())
       {
        CString file_info;
        file_info = CString(_T("</"")) + file + _T("/" ")  + view_info + _T(">");
        szSave += file_info;
       }
      }
     }
    }
   }
  }
  if (!szSave.IsEmpty())
  {
   COption::Save(OPTION_REC_FILES, OPTION_REC_FILE, (LPCTSTR)szSave);
  }
 }
 CMDIFrameWnd::OnClose();
}