home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F37582_dirdialog.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-16  |  3.9 KB  |  136 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11.  
  12. ///////////////////////////////////////////////////////////////////////////
  13. // DirDialog.cpp: implementation of the CDirDialog class.
  14. //
  15. //////////////////////////////////////////////////////////////////////
  16.  
  17. #include "stdafx.h"
  18. #include "DirDialog.h"
  19. #include "shlobj.h"
  20.  
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char THIS_FILE[]=__FILE__;
  24. #define new DEBUG_NEW
  25. #endif
  26.  
  27. // Callback function called by SHBrowseForFolder's browse control
  28. // after initialization and when selection changes
  29. static int __stdcall BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  30. {
  31.   CDirDialog* pDirDialogObj = (CDirDialog*)lpData;
  32.  
  33.   if (uMsg == BFFM_INITIALIZED && !pDirDialogObj->m_strSelDir.IsEmpty())
  34.   {
  35.     ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir));
  36.   }
  37.   else // uMsg == BFFM_SELCHANGED
  38.   {
  39.   }
  40.  
  41.   return 0;
  42. }
  43.  
  44. //////////////////////////////////////////////////////////////////////
  45. // Construction/Destruction
  46. //////////////////////////////////////////////////////////////////////
  47.  
  48. CDirDialog::CDirDialog()
  49. {
  50. }
  51.  
  52. CDirDialog::~CDirDialog()
  53. {
  54. }
  55.  
  56. int CDirDialog::DoBrowse( HWND oWner)
  57. {
  58.   LPMALLOC pMalloc;
  59.   if (SHGetMalloc (&pMalloc)!= NOERROR)
  60.   {
  61.       return 0;
  62.   }
  63.  
  64.   BROWSEINFO bInfo;
  65.   LPITEMIDLIST pidl;
  66.   ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO));
  67.  
  68.   if (!m_strInitDir.IsEmpty ())
  69.   {
  70.     OLECHAR       olePath[MAX_PATH];
  71.     ULONG         chEaten;
  72.     ULONG         dwAttributes;
  73.     HRESULT       hr;
  74.     LPSHELLFOLDER pDesktopFolder;
  75.     //
  76.     // Get a pointer to the Desktop's IShellFolder interface. 
  77.     //
  78.     if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
  79.     {
  80.       //
  81.       // IShellFolder::ParseDisplayName requires the file name be in Unicode.
  82.       //
  83.       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir.GetBuffer(MAX_PATH), -1,
  84.                           olePath, MAX_PATH);
  85.  
  86.       m_strInitDir.ReleaseBuffer (-1);
  87.       //
  88.       // Convert the path to an ITEMIDLIST.
  89.       //
  90.       hr = pDesktopFolder->ParseDisplayName(NULL,
  91.                                             NULL,
  92.                                             olePath,
  93.                                             &chEaten,
  94.                                             &pidl,
  95.                                             &dwAttributes);
  96.       if (FAILED(hr))
  97.       {
  98.         pMalloc ->Free (pidl);
  99.         pMalloc ->Release ();
  100.         return 0;
  101.       }
  102.       bInfo.pidlRoot = pidl;
  103.  
  104.     }
  105.   }
  106.   bInfo.hwndOwner = oWner;
  107.   bInfo.pszDisplayName = m_strPath.GetBuffer (MAX_PATH);
  108.   CString strOpen;
  109.   strOpen.LoadString(IDS_STRING107);
  110.   bInfo.lpszTitle = (m_strTitle.IsEmpty()) ? strOpen:m_strTitle;
  111.   bInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS|BIF_DONTGOBELOWDOMAIN;
  112.   bInfo.lpfn = BrowseCtrlCallback;  // address of callback function
  113.   bInfo.lParam = (LPARAM)this;      // pass address of object to callback function
  114.  
  115.   if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)
  116.   {
  117.     return 0;
  118.   }
  119.   m_strPath.ReleaseBuffer();
  120.   m_iImageIndex = bInfo.iImage;
  121.  
  122.   if (::SHGetPathFromIDList(pidl,m_strPath.GetBuffer(MAX_PATH)) == FALSE)
  123.   {
  124.     pMalloc ->Free(pidl);
  125.     pMalloc ->Release();
  126.     return 0;
  127.   }
  128.  
  129.   m_strPath.ReleaseBuffer();
  130.  
  131.   pMalloc ->Free(pidl);
  132.   pMalloc ->Release();
  133.  
  134.   return 1;
  135. }
  136.