Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.3 KiB

  1. //-----------------------------------------------------------------------------
  2. // PromptForPathDlg.cpp
  3. //-----------------------------------------------------------------------------
  4. #include "StdAfx.h"
  5. #include "PromptForPathDlg.h"
  6. #include <shlobj.h>
  7. CPromptForPathDlg::CPromptForPathDlg( CComBSTR bszDef, HINSTANCE hInst, BOOL bWinSB ) :
  8. m_bWinSB(bWinSB)
  9. {
  10. m_bszDef = bszDef;
  11. m_hInst = hInst;
  12. }
  13. LRESULT CPromptForPathDlg::OnInitDialog( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
  14. {
  15. USES_CONVERSION;
  16. CenterWindow( GetParent() );
  17. TCHAR szTitle[MAX_PATH];
  18. TCHAR szDlgPathText[MAX_PATH];
  19. LoadString( m_hInst, m_bWinSB ? IDS_WinSBTitle : IDS_SBSTitle, szTitle, sizeof(szTitle)/sizeof(TCHAR) );
  20. SetWindowText( szTitle );
  21. SetDlgItemText( IDC_EBPath, (TCHAR*)(OLE2T( (BSTR) m_bszDef )) );
  22. // depending on BOS or SBS, load the prompt
  23. UINT uPromptID = m_bWinSB ? IDS_WinSBPrompt : IDS_SBSPrompt;
  24. TCHAR szPrompt[MAX_PATH * 2];
  25. LoadString( m_hInst, uPromptID, szPrompt, MAX_PATH * 2 );
  26. SetDlgItemText( IDC_STPromptDlgText, szPrompt );
  27. return (0);
  28. }
  29. LRESULT CPromptForPathDlg::OnOK( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& handled )
  30. {
  31. TCHAR* psz = new TCHAR[::GetWindowTextLength(GetDlgItem(IDC_EBPath)) + 1];
  32. if (psz)
  33. {
  34. GetDlgItemText( IDC_EBPath, psz, ::GetWindowTextLength(GetDlgItem(IDC_EBPath)) + 1 );
  35. m_bszDef = psz;
  36. delete[] psz;
  37. }
  38. else
  39. {
  40. m_bszDef = _T("");
  41. }
  42. EndDialog( IDOK );
  43. return (0);
  44. }
  45. LRESULT CPromptForPathDlg::OnCancel( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& handled )
  46. {
  47. EndDialog( IDCANCEL );
  48. return (0);
  49. }
  50. LRESULT CPromptForPathDlg::OnBrowse( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& handled )
  51. {
  52. CoInitialize(NULL);
  53. // Browse for folder.
  54. // If they pressed Cancel, change nothing.
  55. // If they chose a new folder, let's change our current path (m_bszDef).
  56. TCHAR pszDisplayName[MAX_PATH];
  57. int iImage = 0;
  58. LPMALLOC pMalloc;
  59. HRESULT hr = ::SHGetMalloc(&pMalloc);
  60. if (SUCCEEDED(hr))
  61. {
  62. //CString csTitle;
  63. TCHAR szTitle[MAX_PATH];
  64. LoadString( m_hInst, IDS_ChooseFolderTitle, szTitle, sizeof(szTitle)/sizeof(TCHAR) );
  65. BROWSEINFO BrowseInfo;
  66. BrowseInfo.hwndOwner = m_hWnd;
  67. BrowseInfo.pidlRoot = NULL;
  68. BrowseInfo.pszDisplayName = pszDisplayName;
  69. BrowseInfo.lpszTitle = szTitle;
  70. BrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS;
  71. BrowseInfo.lpfn = NULL;
  72. BrowseInfo.lParam = NULL;
  73. BrowseInfo.iImage = iImage;
  74. LPITEMIDLIST pList = ::SHBrowseForFolder(&BrowseInfo);
  75. TCHAR pBuffer[MAX_PATH];
  76. if (::SHGetPathFromIDList(pList, pBuffer))
  77. {
  78. m_bszDef = pBuffer;
  79. SetDlgItemText( IDC_EBPath, pBuffer );
  80. }
  81. pMalloc->Free(pList);
  82. pMalloc->Release();
  83. }
  84. else
  85. {
  86. TCHAR szErrTitle[1024] = { 0 };
  87. TCHAR szErrMsg[1024] = { 0 };
  88. LoadString( m_hInst, IDS_ErrorTitle, szErrTitle, 1024 );
  89. LoadString( m_hInst, IDS_BrowseFailed, szErrMsg, 1024 );
  90. ::MessageBox(0, szErrMsg, szErrTitle, MB_OK | MB_ICONERROR);
  91. }
  92. CoUninitialize();
  93. return (0);
  94. }