zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    06 is和==的区别 encode()编码 decode()解码
    05 dic的增删改查 字典的嵌套 考试题dic.get()的相关使用
    03 编码 int ,bool,str的常用操作 主要讲str
    01 基本数据类型 变量 if语句
    04 列表的增删改查 常用方法 元祖 range
    02 while循环 格式化输出 运算符
    多校2 Harmonious Army hdu6598 网络流
    P3159 [CQOI2012]交换棋子 网络流
    P2172 [国家集训队]部落战争 最大流
    P2402 奶牛隐藏 网络流
  • 原文地址:https://www.cnblogs.com/flysnail/p/2174905.html
Copyright © 2011-2022 走看看