Пример #1
0
void CProjectView::OnFileadd() 
{
   // Start in the project directory
   ((CProjectDoc*)GetDocument())->SetProject();
   _TCHAR* FileBuffer = new _TCHAR[4096];

   CFileDialog *pfileDlg = NULL;

   if (g_osrel >= 4)
   {
      pfileDlg = new CFileDialog(TRUE, NULL, NULL,
         OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_EXPLORER,
         _T("Prolog Files (*.pro;*.plm)|*.pro;*.plm|All (*.*)|*.*||"));
   }
   else
   {
      pfileDlg = new CFileDialog(TRUE, NULL, NULL,
         OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
         _T("Prolog Files (*.pro;*.plm)|*.pro;*.plm|All (*.*)|*.*||"));
   }

   pfileDlg->m_ofn.lpstrFile = FileBuffer;
   FileBuffer[0] = EOS;  // Note, must do this or W95 flags as error
   pfileDlg->m_ofn.nMaxFile = 4096;

   if (pfileDlg->DoModal() != IDOK)
   {
      //_TCHAR errbuf[512];
      //wsprintf(errbuf, _T("FileDialog error: %d"), CommDlgExtendedError());
      //AfxMessageBox(errbuf);
      delete pfileDlg;
      return;
   }

   CListBox* pLB = (CListBox*)GetDlgItem(IDP_FILELIST);

   // Loop through all the files to be added. If they are in the project
   // directory or below, just put in the relative path.
   POSITION pos = pfileDlg->GetStartPosition();
   CString dir(m_directory), path, upath;
   dir.MakeUpper();
   int i, idx;
   while (pos != NULL)
   {
      path = pfileDlg->GetNextPathName(pos);
      upath = path;
      upath.MakeUpper();
      if (dir.Right(1) != _T("\\"))
         dir = dir + _T("\\");
      i = upath.Find(dir);
      if (i >= 0)
         path = path.Mid(i+dir.GetLength());
      idx = pLB->AddString(path);
      update_scroll(pLB, path); 
   }
   delete FileBuffer;
   delete pfileDlg;

   ((CProjectDoc*)GetDocument())->SetProject();
}
Пример #2
0
void CProjectView::OnLibadd() 
{
   _TCHAR* FileBuffer = new _TCHAR[4096];

   CFileDialog *pfileDlg = NULL;

   if (g_osrel >= 4)
      pfileDlg = new CFileDialog(TRUE, NULL, NULL,
         OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_EXPLORER,
         _T("Prolog Files (*.pro;*.plm)|*.pro;*.plm|All (*.*)|*.*||"));
   else
      pfileDlg = new CFileDialog(TRUE, NULL, NULL,
         OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
         _T("Prolog Files (*.pro;*.plm)|*.pro;*.plm|All (*.*)|*.*||"));

   pfileDlg->m_ofn.lpstrFile = FileBuffer;
   FileBuffer[0] = EOS;  // Note, must do this or W95 flags as error
   pfileDlg->m_ofn.nMaxFile = 4096;

   if (pfileDlg->DoModal() != IDOK)
   {
      delete pfileDlg;
      return;
   }

   CListBox* pLB = (CListBox*)GetDlgItem(IDP_LIBLIST);

   POSITION pos = pfileDlg->GetStartPosition();
   CString text;
   while (pos != NULL)
   {
      text = pfileDlg->GetNextPathName(pos);
      pLB->AddString(text);
      update_scroll(pLB, text);
   }
   delete FileBuffer;
   delete pfileDlg;

   ((CProjectDoc*)GetDocument())->SetProject();
}