首页 > Windows开发 > 详细

工作总结:MFC使用Windows自带打开对话框

时间:2014-04-02 08:36:04      阅读:660      评论:0      收藏:0      [点我收藏+]

代码:

int nStructSize = 76;  //Win98 as default  

LPARAM lModuleParam = 0;  

TV_INSERTSTRUCT tvItem;  

CString sPathNameSel;  

char   lpszCurrentDir[1024];//1K

 ::GetModuleFileName(NULL, lpszCurrentDir, 1024);  //Get current directory   

int n = CString(lpszCurrentDir).ReverseFind(‘\\‘);

 CString sTemp = CString(lpszCurrentDir).Left(n);  

STRCPY(lpszCurrentDir, sTemp);

 CString str("", 1024);

 /*if (TRUE == bAMT700PrjModify)  

{   

 bAMT700PrjModify = FALSE;   

int nAnswer = MxMessageBox(m_hWnd, IDS_SAVEPROJECTORNOT, IDS_CAPTION_NEWPROJECT, MB_YESNO);  

 if (IDYES == nAnswer)   

{    

OnBnClickedBtnAmt700PrjSave();   

}

 }

*/  

 CFileDialog mFileDlg( TRUE,   NULL,   NULL,   OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,   "IRIS Files (*.ini)|*.ini||",   this);  //NT does not support  

mFileDlg.m_ofn.lpstrFile = (LPSTR)(LPCTSTR)str;//.GetBuffer(MERGE_MAX_COUNT_OF_FILE_CAN_SELECT); mFileDlg.m_ofn.lpstrTitle = RESID2LPSTR(IDS_BROWSEFORPROJECT);

mFileDlg.m_ofn.lpstrInitialDir = lpszCurrentDir;

DWORD dwVersion = GetVersion();

 if (dwVersion < 0x80000000)    //Windows NT/win2000  

{   

nStructSize = 88;

 }  

else       //Windows95/98

 {   

nStructSize = 76;  

}

 mFileDlg.m_ofn.lStructSize = nStructSize;

 str.ReleaseBuffer();

 if (mFileDlg.DoModal() == IDOK)

 {        

POSITION pos = mFileDlg.GetStartPosition();   

while (NULL != pos)  

 {   

 m_sPrjPathName = mFileDlg.GetNextPathName(pos);   

 sPathNameSel = mFileDlg.GetFileName();  

 }   

CFileFind finder;   

DWORD dwFindRet;   

dwFindRet = m_sPrjPathName.Find(".ini");   

if (0xffffffff == dwFindRet)  

 {   

 m_sPrjPathName += ".ini";

  }  

 dwFindRet = sPathNameSel.Find(".ini");  

 if (0xffffffff == dwFindRet)   

{   

 sPathNameSel += ".ini";

 }

  if (!finder.FindFile(m_sPrjPathName))  

 {   

 MxMessageBox(m_hWnd, IDS_PROJECTNOTEXITS, IDS_CAPTION_OPENPROJECT, MB_ICONERROR);    

m_sPrjPathName.Empty();    

return;   

}  

 sPathNameSel = sPathNameSel.Left(sPathNameSel.GetLength() - strlen(".ini"));

  g_prjAMT700.Release();

  /*m_treePrj.DeleteAllItems();   

m_dlgModule.m_nModuleCount = 0;  

 m_dlgModule.m_bMethod = 1; //add   m_dlgAddr.ShowWindow(SW_HIDE);

  m_dlgModule.ShowWindow(SW_SHOW);*/

  //CButton * pBtn = (CButton *)GetDlgItem(IDC_RAD_AMT700_MODULE);  

 //pBtn->ShowWindow(SW_SHOW);   //pBtn->SetCheck(1);   

//pBtn = (CButton *)GetDlgItem(IDC_RAD_AMT700_ADDR);  

 //pBtn->ShowWindow(SW_SHOW);

  tvItem.hParent = TVI_ROOT;  

 tvItem.hInsertAfter = TVI_ROOT;

  // tvItem.item.iImage = nImage;   

// tvItem.item.iSelectedImage = nImage;  

 tvItem.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM;  

 tvItem.item.pszText = CSTRING_TO_LPSTR sPathNameSel;  

 tvItem.item.lParam = MAKELPARAM(g_prjAMT700.GetModuleCount(), MAKEWORD(1/*PRJ*/, 0));//Prj  

 //m_hPrj = m_treePrj.InsertItem(&tvItem);   

//m_treePrj.SelectItem(m_hPrj);   

//if (AMT700_VERSION == iAMTVer)  

 //{  

 // g_prjAMT700.LoadProject(m_sPrjPathName);

  // for (int i = 0; i < g_prjAMT700.GetModuleCount(); i++)   

// {   

//  CModule700 * pTmpModule = g_prjAMT700.GetModuleAt(i);  

 //  lModuleParam = MAKELPARAM(i, MAKEWORD(2/*Module*/, 0));

  //  HTREEITEM hItem = AddModuleItem(m_hPrj, *pTmpModule, lModuleParam);  

 //  m_dlgModule.m_nModuleCount++;

  //  for (int j = 0; j < pTmpModule->GetAddrCount(); j++)  

 //  {   //   CAddr700 pTmpAddr;

  //   pTmpModule->GetAddrAtEx(j, &pTmpAddr);   

//   AddAddrItem(hItem, pTmpAddr, MAKELPARAM(j, MAKEWORD(3, 0)));

  //  }

  // }

  //}

 }

工作总结:MFC使用Windows自带打开对话框,布布扣,bubuko.com

工作总结:MFC使用Windows自带打开对话框

原文:http://www.cnblogs.com/CocoWang/p/3639287.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!