wrapshl.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/wrapshl.h
  3. // Purpose: wrapper class for stuff from shell32.dll
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 2004-10-19
  7. // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MSW_WRAPSHL_H_
  11. #define _WX_MSW_WRAPSHL_H_
  12. #include "wx/msw/wrapwin.h"
  13. #ifdef __WXWINCE__
  14. #include <winreg.h>
  15. #include <objbase.h>
  16. #include <shlguid.h>
  17. #include <shellapi.h>
  18. #endif
  19. #include <shlobj.h>
  20. #include "wx/msw/winundef.h"
  21. #include "wx/log.h"
  22. // ----------------------------------------------------------------------------
  23. // wxItemIdList implements RAII on top of ITEMIDLIST
  24. // ----------------------------------------------------------------------------
  25. class wxItemIdList
  26. {
  27. public:
  28. // ctor takes ownership of the item and will free it
  29. wxItemIdList(LPITEMIDLIST pidl)
  30. {
  31. m_pidl = pidl;
  32. }
  33. static void Free(LPITEMIDLIST pidl)
  34. {
  35. if ( pidl )
  36. {
  37. LPMALLOC pMalloc;
  38. SHGetMalloc(&pMalloc);
  39. if ( pMalloc )
  40. {
  41. pMalloc->Free(pidl);
  42. pMalloc->Release();
  43. }
  44. else
  45. {
  46. wxLogLastError(wxT("SHGetMalloc"));
  47. }
  48. }
  49. }
  50. ~wxItemIdList()
  51. {
  52. Free(m_pidl);
  53. }
  54. // implicit conversion to LPITEMIDLIST
  55. operator LPITEMIDLIST() const { return m_pidl; }
  56. // get the corresponding path, returns empty string on error
  57. wxString GetPath() const
  58. {
  59. wxString path;
  60. if ( !SHGetPathFromIDList(m_pidl, wxStringBuffer(path, MAX_PATH)) )
  61. {
  62. wxLogLastError(wxT("SHGetPathFromIDList"));
  63. }
  64. return path;
  65. }
  66. private:
  67. LPITEMIDLIST m_pidl;
  68. wxDECLARE_NO_COPY_CLASS(wxItemIdList);
  69. };
  70. // enable autocompleting filenames in the text control with given HWND
  71. //
  72. // this only works on systems with shlwapi.dll 5.0 or later
  73. //
  74. // implemented in src/msw/utilsgui.cpp
  75. extern bool wxEnableFileNameAutoComplete(HWND hwnd);
  76. #endif // _WX_MSW_WRAPSHL_H_