• windows开发杂记


    一、判断文件或者文件夹是否存在。

    if (!PathFileExists(csFilePath))
    {::CreateDirectory(csFilePath, NULL);} 

    二、打开windows类型对话框

    static TCHAR strDirName[MAX_PATH];
    BROWSEINFO bi;
    CString szString = TEXT("选择一个文件夹");
    bi.hwndOwner = ::GetFocus();
    bi.pidlRoot = NULL;
    bi.pszDisplayName = strDirName;
    bi.lpszTitle = szString;
    bi.ulFlags = BIF_BROWSEFORCOMPUTER | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS;
    bi.lpfn = NULL;
    bi.lParam = 0;
    bi.iImage = 0;
    LPITEMIDLIST pItemIDList = ::SHBrowseForFolder(&bi);
    if(pItemIDList == NULL)
    {
    	return ;
    }
    ::SHGetPathFromIDList(pItemIDList, strDirName);

    三、遍历目录下的所有文件

    CString csFolder = csGPSDataPath + _T("\\*.txt");
    CFileFind finder;
    BOOL bWorking = finder.FindFile(csFolder);
    while (bWorking)
    {
    	bWorking = finder.FindNextFile();
    	if (finder.IsDots())
    	{
    		continue;
    	}
    	CString strPath = finder.GetFileName();
    	CString strFile = csGPSDataPath + _T("\\") + strPath;
    	vecAllFilePath.push_back(strFile);
    }
    finder.Close();
    

    四、打开windows上次打开的对话框

    BOOL CTestDlg::GetOpenSaveMRU(LPCTSTR strExtName,char *strMRUPath)
    {
    	HKEY hKEY;
    	const char *mru="Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\OpenSaveMRU\\";
    	CString strmru(mru);
    	strmru += strExtName;
    	long lRet = RegOpenKeyEx(HKEY_CURRENT_USER,strmru,0,KEY_READ,&hKEY);
    
    	if (lRet != ERROR_SUCCESS ) {
    		return FALSE;
    	}
    
    	DWORD keytype1 = REG_SZ;
    	DWORD dwInBytes = 256;
    	BYTE pInBuf[256];
    	lRet = RegQueryValueEx(hKEY,"MRUList",NULL,&keytype1,pInBuf,&dwInBytes);
    	if (lRet != ERROR_SUCCESS ) {
    		return FALSE;
    	}
    
    	dwInBytes = 256;
    	char strLast[] = {pInBuf[0],0};
    	lRet = RegQueryValueEx(hKEY,(LPTSTR)strLast,NULL,&keytype1,(LPBYTE)   strMRUPath,&dwInBytes);
    
    	if (lRet != ERROR_SUCCESS) {
    		return FALSE;
    	}
    
    	CString str1(strMRUPath);
    	int idx=str1.ReverseFind('\\');
    	strMRUPath[idx]=0;
    
    	RegCloseKey(hKEY);
    	return TRUE;
    }
    

      

  • 相关阅读:
    RegExp.$1
    Wide&Deep 模型学习教程
    docker 安装与使用的相关问题
    Centos 防火墙
    odoo ERP 系统安装与使用
    Linux 开机自动启动脚本
    intel RDT技术管理cache和memory_bandwidth
    tensorflow 中 inter_op 和 intra_op
    centos 7 安装 nginx 或 apache,及其比较
    Dependency injection in .NET Core的最佳实践
  • 原文地址:https://www.cnblogs.com/flysnail/p/2174905.html
Copyright © 2020-2023  润新知