]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dirdlg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/dialog.h"
28 #include "wx/dirdlg.h"
31 #if (defined(__WIN95__) && !defined(__GNUWIN32__))||defined(wxUSE_NORLANDER_HEADERS)
32 #include "shlobj.h" // Win95 shell
35 #include "wx/msw/private.h"
36 #include "wx/cmndata.h"
42 #define wxDIALOG_DEFAULT_X 300
43 #define wxDIALOG_DEFAULT_Y 300
45 #if !USE_SHARED_LIBRARY
46 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
50 BrowseCallbackProc(HWND hwnd
,UINT uMsg
,LPARAM lp
, LPARAM pData
)
52 TCHAR szDir
[MAX_PATH
];
56 case BFFM_INITIALIZED
:
57 // We have put m_path into pData.
58 // TRUE -> passing char *, not dir id.
59 SendMessage(hwnd
,BFFM_SETSELECTION
,TRUE
,pData
);
63 // Set the status window to the currently selected path.
64 if (SHGetPathFromIDList((LPITEMIDLIST
) lp
,szDir
))
66 SendMessage(hwnd
,BFFM_SETSTATUSTEXT
,0,(LPARAM
)szDir
);
77 wxDirDialog::wxDirDialog(wxWindow
*parent
, const wxString
& message
,
78 // const wxString& caption,
79 const wxString
& defaultPath
,
80 long style
, const wxPoint
& pos
)
83 // m_caption = caption;
84 m_dialogStyle
= style
;
89 int wxDirDialog::ShowModal(void)
91 // Unfortunately Gnu-Win32 doesn't yet have COM support
92 #if (defined(__WIN95__) && !defined(__GNUWIN32__))||defined(wxUSE_NORLANDER_HEADERS)
94 if (m_parent
) hWnd
= (HWND
) m_parent
->GetHWND();
98 // LPITEMIDLIST pidlPrograms; // PIDL for Programs folder
99 LPITEMIDLIST pidlBrowse
; // PIDL selected by user
100 LPMALLOC pMalloc
= NULL
;
102 HRESULT result
= ::SHGetMalloc(&pMalloc
);
104 if (result
!= NOERROR
)
107 // Allocate a buffer to receive browse information.
108 if ((lpBuffer
= (LPTSTR
) pMalloc
->Alloc(MAX_PATH
)) == NULL
)
115 // Get the PIDL for the Programs folder.
116 if (!SUCCEEDED(SHGetSpecialFolderLocation(
117 parent->GetSafeHwnd(), CSIDL_PROGRAMS, &pidlPrograms))) {
118 pMalloc->Free(lpBuffer);
124 // Fill in the BROWSEINFO structure.
126 bi
.pidlRoot
= NULL
; // pidlPrograms;
127 bi
.pszDisplayName
= lpBuffer
;
128 bi
.lpszTitle
= m_message
; // BC++ 4.52 says LPSTR, not LPTSTR?
130 bi
.lpfn
= BrowseCallbackProc
;
131 bi
.lParam
= (LPARAM
)m_path
.c_str();
133 // Browse for a folder and return its PIDL.
134 pidlBrowse
= SHBrowseForFolder(&bi
);
137 if (pidlBrowse
!= NULL
) {
139 // Show the display name, title, and file system path.
140 if (SHGetPathFromIDList(pidlBrowse
, lpBuffer
))
143 // Free the PIDL returned by SHBrowseForFolder.
144 pMalloc
->Free(pidlBrowse
);
150 // pMalloc->Free(pidlPrograms);
151 pMalloc
->Free(lpBuffer
);