Windows development Note

Source: Internet
Author: User

1. Determine whether a file or folder exists.

If (! Pathfileexists (csfilepath ))
{: Createdirectory (csfilepath, null );}

2. Open the windows Type dialog box

Static tchar strdirname [max_path]; browseinfo Bi; cstring szstring = text ("select a folder"); 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 );

3. traverse all files in the directory

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

4. Open the dialog box that was last opened in 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;}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.