windows開發雜記

來源:互聯網
上載者:User

一、判斷檔案或者檔案夾是否存在。

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

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.