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