自己写感觉比较好且使用的的函数 包括浏览目录以及 Slplit函数

int CALLBACK CQuer3080ImgDlg::BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
 if(uMsg==BFFM_SELCHANGED||uMsg==BFFM_INITIALIZED)
 {
  if(uMsg==BFFM_INITIALIZED)
  {
   ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,
    LPARAM(lpData));
  }
 }
 return 0;
}


void CQuer3080ImgDlg::OnBnClickedBtnOpen()
{

 Invalidate();
 BROWSEINFO bi={0};
 bi.hwndOwner = this->GetSafeHwnd();
 bi.pidlRoot  = NULL;
 bi.lpszTitle = _T("请选择打开路径");
 bi.ulFlags   = BIF_RETURNONLYFSDIRS|BIF_EDITBOX;
 bi.lpfn      = BrowseCallbackProc;
 bi.lParam    = (LPARAM)m_strPath.GetBuffer(m_strPath.GetLength());
 
 LPITEMIDLIST pIdl;
 if((pIdl = SHBrowseForFolder(&bi)) != NULL)
 {
  TCHAR path[MAX_PATH];
  SHGetPathFromIDList(pIdl,path);
  m_strTemplateInfoPath = path; 
  m_strPath=path;
  BOOL blValidate=ValidateFolderName(m_strTemplateInfoPath);
  
  if (!blValidate)
  {
   AfxMessageBox(_T("文件夹不正确"));
  }
  else
  {
   m_bGetFileData=TRUE;
   this->SetWindowText(_T("Query3080Img_")+m_strTemplateInfoPath);
   ReadImgTDRData(m_strTemplateInfoPath);
   ReadSliceData(m_strTemplateInfoPath);
   m_ImgStatic.SetImgData(g_dr_data_t.get());
   int nPos=GetDlgItemInt(IDC_EDT_SLICE);
   nPos=nPos*0.429+1;
   SetCTImg(nPos); 
   SetAactiveXStatus(TRUE);
   ((CComboBox*)GetDlgItem(IDC_CBO_DRIMG_DEAL))->SetCurSel(0);
   ((CComboBox*)GetDlgItem(IDC_CBO_CTIMG_DEAL))->SetCurSel(0);
  }
 } 
}

BOOL CQuer3080ImgDlg::ValidateFolderName(CString strPath)
{
 try
 {  
  CStringArray sa;
  int nCount=String2Array(strPath,sa,_T("//"));

  if (nCount<2)
  {
   return FALSE;
  }

  CString strLastName=sa.ElementAt(nCount-1);
  CString strPrevName=sa.ElementAt(nCount-2);

  if (strLastName.GetLength()!=6)
  {
   return FALSE;
  }

  if (strPrevName.GetLength()!=8)
  {
   return FALSE;
  }

  int nYear,nMonth,nDay,nHour,nMinute,nSecond;

  swscanf(strLastName,_T("%02d%02d%02d"),&nHour,&nMinute,&nSecond);
  
  swscanf(strPrevName,_T("%04d%02d%02d"),&nYear,&nMonth,&nDay);

  CTime   ct(nYear,   nMonth,   nDay,   nHour,   nMinute,   nSecond);  

  CString  str1  = ct.Format("%Y%m%d"); 
  CString  str2  = ct.Format("%H%M%S");

  if (str2==strLastName && str1==strPrevName)
  {
   return TRUE;
  }
  else
  {
   return FALSE;
  }

 } 
 catch (...)
 {
  return FALSE;
 }
 return TRUE;
}


int  CQuer3080ImgDlg::String2Array(const   CString&   s,   CStringArray   &sa,   CString   sSplitter)  
{  
 int   nLen=s.GetLength(),   nLastPos,   nPos;  
 bool   bContinue;  

 sa.RemoveAll();  
 nLastPos=0;  
 do  
 {  
  bContinue=false;  
  
  nPos   =   s.Find(sSplitter,   nLastPos);  
  if   (-1!=nPos)  
  {  
   sa.Add(s.Mid(nLastPos,   nPos-nLastPos));  
   nLastPos=nPos+1;  
   if   (nLastPos   !=   nLen)   bContinue=true;  
  }  
 }   while   (bContinue);  

 if   (nLastPos   !=   nLen)  
  sa.Add(s.Mid(nLastPos,   nLen-nLastPos));  

 return   sa.GetSize();  
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

醉心编码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值