gApi.cpp
上传用户:sz4588
上传日期:2022-05-26
资源大小:2253k
文件大小:1k
源码类别:

压缩解压

开发平台:

Visual C++

  1. #include "StdAfx.h" 
  2. #include "gAPI.h"
  3. CString ApiGetFileName(CString FullPath)
  4. {
  5. int n=FullPath.ReverseFind('\');
  6. int nL=FullPath.GetLength();
  7. return FullPath.Right(nL-n-1);
  8. }
  9. CString ApiGetFolderName(CString FullPath)
  10. {
  11. int n=FullPath.ReverseFind('\');
  12. return FullPath.Left(n+1);
  13. }
  14. bool GetFolder(CString&  folderpath, const char* szCaption, HWND hOwner)
  15. {
  16. bool retVal = false;
  17. BROWSEINFO bi; // The BROWSEINFO struct tells the shell
  18. memset(&bi, 0, sizeof(bi)); //how it should display the dialog.
  19. bi.ulFlags   =NULL; //BIF_USENEWUI;
  20. bi.hwndOwner = hOwner;
  21. bi.lpszTitle = szCaption;
  22. ::OleInitialize(NULL); // must call this if using BIF_USENEWUI
  23. // Show the dialog and get the itemIDList for the 
  24. LPITEMIDLIST pIDL = ::SHBrowseForFolder(&bi); // selected folder.
  25. if(pIDL != NULL)
  26. {
  27. // Create a buffer to store the path, then 
  28. char buffer[_MAX_PATH] = {''}; // get the path.
  29. if(::SHGetPathFromIDList(pIDL, buffer) != 0)
  30. {
  31. folderpath = buffer; // Set the string value.
  32. retVal = true;
  33. }
  34. CoTaskMemFree(pIDL); // free the item id list
  35. }
  36. ::OleUninitialize();
  37. return retVal;
  38. }