SDC C-Project CF Review 프로그램
LYW
2021-09-27 b9b6752e83c701cc67241923d2b74dc3a963d243
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "StdAfx.h"
#include "PropertyGridDirectoryPicker.h"
 
// mch
//#define BIF_NEWDIALOGSTYLE 0x0040
 
CString CPropertyGridDirectoryPicker::m_strTitle = _T("Choose a directory");
 
CPropertyGridDirectoryPicker::CPropertyGridDirectoryPicker()
{
}
 
CPropertyGridDirectoryPicker::~CPropertyGridDirectoryPicker()
{
}
 
int CALLBACK CPropertyGridDirectoryPicker::BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData)
{
  switch(uMsg)
  {
    // If the dialog is being initialised
  case BFFM_INITIALIZED:
    {
      // Send a SetSelection message on the passed directory
      SendMessage(hwnd,BFFM_SETSELECTION,TRUE,pData);
      break;
    }
  }
  return 0;
}
 
bool CPropertyGridDirectoryPicker::PickDirectory(CString &directory, HWND hwnd)
{
  TCHAR pszBuffer[MAX_PATH];
  pszBuffer[0] = '\0';
 
  // Gets the Shell's default allocator
  LPMALLOC pMalloc;
  if (::SHGetMalloc(&pMalloc) == NOERROR)
  {
    BROWSEINFO bi;
    LPITEMIDLIST pidl;
 
    // Get help on BROWSEINFO struct
    bi.hwndOwner = hwnd;
    bi.pidlRoot = NULL;
    bi.pszDisplayName = pszBuffer;
    bi.lpszTitle = m_strTitle;
    bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE ;
 
    // The callback function initialises the dialog with the passed value
    bi.lpfn = BrowseCallbackProc;
    bi.lParam = LPARAM(&directory);
 
    // This next call issues the dialog box.
    if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
    {
      // Get the full path into pszBuffer
      ::SHGetPathFromIDList(pidl, pszBuffer);
      // Free the PIDL allocated by SHBrowseForFolder.
      pMalloc->Free(pidl);
    }
    // Release the shell's allocator.
    pMalloc->Release();
  }
 
  // get the result
  if (_tcslen(pszBuffer) != 0)
  {
    directory = pszBuffer;
    return TRUE;
  }
  return FALSE;
}