DirDialog.cpp
上传用户:lusi_8715
上传日期:2007-01-08
资源大小:199k
文件大小:4k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /**************************************************************************************
  2.  *                                                                                    *
  3.  * This application contains code from OpenDivX and is released as a "Larger Work"    *
  4.  * under that license. Consistant with that license, this application is released     *
  5.  * under the GNU General Public License.                                              *
  6.  *                                                                                    *
  7.  * The OpenDivX license can be found at: http://www.projectmayo.com/opendivx/docs.php *
  8.  * The GPL can be found at: http://www.gnu.org/copyleft/gpl.html                      *
  9.  *                                                                                    *
  10.  * Copyright (c) 2001 - Project Mayo                                                  *
  11.  *                                                                                    *
  12.  * Authors: Damien Chavarria <adrc at projectmayo.com>                                *
  13.  *                                                                                    *
  14.  **************************************************************************************/
  15. #include "DirDialog.h"
  16. #include <shlobj.h>
  17. static int __stdcall BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  18. {
  19.   CDirDialog* pDirDialogObj = (CDirDialog*)lpData;
  20.   if (uMsg == BFFM_INITIALIZED && !pDirDialogObj->m_strSelDir != NULL)
  21.   {
  22.   
  23.   }
  24.   else // uMsg == BFFM_SELCHANGED
  25.   {
  26.   }
  27.   return 0;
  28. }
  29. //////////////////////////////////////////////////////////////////////
  30. // Construction/Destruction
  31. //////////////////////////////////////////////////////////////////////
  32. CDirDialog::CDirDialog()
  33. {
  34. this->m_strPath    = (char *) malloc(32768);
  35.     this->m_strInitDir = NULL;
  36.     this->m_strSelDir  = NULL;
  37.     this->m_strTitle   = NULL;
  38. }
  39. CDirDialog::~CDirDialog()
  40. {
  41. }
  42. int CDirDialog::DoBrowse()
  43. {
  44.   BROWSEINFO bInfo;
  45.   LPITEMIDLIST pidl;
  46.   ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO));
  47.   if (m_strInitDir != NULL)
  48.   {
  49.     OLECHAR       olePath[MAX_PATH];
  50.     ULONG         chEaten;
  51.     ULONG         dwAttributes;
  52.     HRESULT       hr;
  53.     LPSHELLFOLDER pDesktopFolder;
  54.     // 
  55.     // Get a pointer to the Desktop's IShellFolder interface. 
  56.     //
  57.     
  58. if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
  59.     {
  60.       //
  61.       // IShellFolder::ParseDisplayName requires the file name be in Unicode.
  62.       //
  63.       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir, -1,
  64.                           olePath, MAX_PATH);
  65.       //
  66.       // Convert the path to an ITEMIDLIST.
  67.       //
  68.       hr = pDesktopFolder->ParseDisplayName(NULL,
  69.                                             NULL,
  70.                                             olePath,
  71.                                             &chEaten,
  72.                                             &pidl,
  73.                                             &dwAttributes);
  74.       bInfo.pidlRoot = pidl;
  75.     }
  76.   }
  77.  
  78.   bInfo.hwndOwner      = NULL;
  79.   bInfo.pszDisplayName = m_strPath;
  80.   bInfo.lpszTitle      = "Select Directory";
  81.   bInfo.ulFlags        = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
  82.   bInfo.lpfn           = BrowseCtrlCallback;
  83.   bInfo.lParam         = (LPARAM)this;
  84.   if ((pidl = SHBrowseForFolder(&bInfo)) == NULL)
  85.   {
  86.   MessageBox(NULL, "Test", "", MB_OK);
  87.   return 0;
  88.   }
  89.   m_iImageIndex = bInfo.iImage;
  90.   if (SHGetPathFromIDList(pidl, m_strPath) == FALSE)
  91.   {
  92.     return 0;
  93.   }
  94.   return 1;
  95. }