首页 > 其他分享 >自己写感觉比较好且使用的的函数 包括浏览目录以及 Slplit函数

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

时间:2023-01-24 14:05:14浏览次数:33  
标签:好且 return 函数 CString Slplit bi nLastPos nPos sa

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

标签:好且,return,函数,CString,Slplit,bi,nLastPos,nPos,sa
From: https://blog.51cto.com/u_15942605/6022282

相关文章

  • hdu:Big Event in HDU(母函数,背包)
    ProblemDescriptionNowadays,weallknowthatComputerCollegeisthebiggestdepartmentinHDU.But,maybeyoudon’tknowthatComputerCollegehadeverbe......
  • MySQL 日期函数、时间函数在实际场景中的应用
    整理日常业务中用到日期函数的一些场景,并对日期函数按照使用类型做了分类,实例也尽可能符合日常需求。为了方便查阅,可以先看目录,再根据需要看具体方法和实例。首先明确日期......
  • JavaScript学习笔记—高阶函数
    如果一个函数的参数或返回值是函数,则这个函数就成为高阶函数将函数作为参数,意味着可以对另一个函数动态的传递代码classPerson{constructor(name,age){thi......
  • 生成函数法推导自然数幂求和公式
    本文主要介绍用生成函数推导形如\(\sum_{k=1}^nk^a,a\inN^+\)的【自然数幂求和公式】的方法。之前在知乎、博客园看到各种奇奇怪怪的推导【平方和】、【立方和】等自然......
  • TLS回调函数
    TLS回调函数TLS回调函数是个啥TLS全称ThreadLocalStorage,中文“线程局部存储”。TLS是各线程的独立的数据存储空间,使用TLS技术可在线程内部独立使用或修改进程的全局......
  • 冒泡排序函数(算法)
    比较相邻的元素。如果第一个比第二个大,就交换他们两个。对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。针对所有的元素重......
  • Day06 - 匿名函数和文件操作
    1.匿名函数lambdadef函数名(参数列表): 函数体'''匿名函数'''#万物皆对象#对象就会有内存地址,就会有一个引用#通过这个引用就可以找到该对象并使用它d......
  • Day05 - 内置函数和参数
    0.列表推导式格式:列表变量=[表达式for变量inrange(10)]表达式中需要使用后面的变量'''列表推导式创建一个具有一百个数字的列表'''#c_l=[]#f......
  • python一个函数简单接收命令行参数
    需要使用sys和getopt库defarg(_,__):#接收命令行参数importsysimportgetopt'''参数:_:短参数str,列如:-f-g-p__:长参数list,列如:['file','......
  • Day02函数和条件表达
    0.格式化字符串'''格式化字符串'''print(1)print(1,2,3,4)a=1b=2.1123c='hello's='a=%db=%fc=%s'%(a,b,c)s+='--world'print(s)......