Click here to Skip to main content
16,011,436 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Setup an deployment Pin
BoudewijnEctor2-Dec-03 23:56
BoudewijnEctor2-Dec-03 23:56 
GeneralRe: Setup an deployment Pin
BoudewijnEctor3-Dec-03 0:05
BoudewijnEctor3-Dec-03 0:05 
QuestionHow to open the dialog 'Open Folder' not 'Open File' ?? Pin
Grrrr2-Dec-03 22:42
Grrrr2-Dec-03 22:42 
AnswerRe: How to open the dialog 'Open Folder' not 'Open File' ?? Pin
BaldwinMartin2-Dec-03 22:44
BaldwinMartin2-Dec-03 22:44 
AnswerRe: How to open the dialog 'Open Folder' not 'Open File' ?? Pin
RChin2-Dec-03 23:13
RChin2-Dec-03 23:13 
GeneralRe: How to open the dialog 'Open Folder' not 'Open File' ?? Pin
Grrrr2-Dec-03 23:27
Grrrr2-Dec-03 23:27 
GeneralRe: How to open the dialog 'Open Folder' not 'Open File' ?? Pin
RChin2-Dec-03 23:37
RChin2-Dec-03 23:37 
AnswerRe: How to open the dialog 'Open Folder' not 'Open File' ?? Pin
Juan Carlos SM2-Dec-03 23:48
Juan Carlos SM2-Dec-03 23:48 
try this class:
------------------------------
DirDialog.h
class CDirDialog
{
public:

CDirDialog();
virtual ~CDirDialog();

BOOL DoBrowse(CWnd *pwndParent = NULL);

CString m_strWindowTitle;
CString m_strPath;
CString m_strInitDir;
CString m_strSelDir;
CString m_strTitle;
int m_iImageIndex;
BOOL m_bStatus;

private:

virtual BOOL SelChanged(LPCSTR lpcsSelection, CString& csStatusText) { return TRUE; };
static int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData);
};
------------------------------
DirDialog.cpp
// Callback function called by SHBrowseForFolder's browse control
// after initialization and when selection changes
int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) {
CDirDialog* pDirDialogObj = (CDirDialog*)lpData;
if (uMsg == BFFM_INITIALIZED) {
if (!pDirDialogObj->m_strSelDir.IsEmpty() )
::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir));
if (!pDirDialogObj->m_strWindowTitle.IsEmpty() )
::SetWindowText(hwnd, (LPCTSTR) pDirDialogObj->m_strWindowTitle);
}
else
if (uMsg == BFFM_SELCHANGED) {
LPITEMIDLIST pidl = (LPITEMIDLIST)lParam;
char selection[MAX_PATH];
if (!::SHGetPathFromIDList(pidl, selection) )
selection[0] = '\0';
CString csStatusText;
BOOL bOk = pDirDialogObj->SelChanged(selection, csStatusText);
if (pDirDialogObj->m_bStatus )
::SendMessage(hwnd, BFFM_SETSTATUSTEXT , 0, (LPARAM)(LPCSTR)csStatusText);
::SendMessage(hwnd, BFFM_ENABLEOK, 0, bOk);
}
return 0;
}

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDirDialog::CDirDialog() {
m_bStatus = FALSE;
}

CDirDialog::~CDirDialog() {
}

BOOL CDirDialog::DoBrowse(CWnd *pwndParent) {
if (!m_strSelDir.IsEmpty()) {
m_strSelDir.TrimRight();
if( m_strSelDir.Right(1) == "\\" || m_strSelDir.Right(1) == "//" )
m_strSelDir = m_strSelDir.Left(m_strSelDir.GetLength() - 1);
}
LPMALLOC pMalloc;
if (SHGetMalloc(&pMalloc) != NOERROR )
return FALSE;
BROWSEINFO bInfo;
LPITEMIDLIST pidl;
ZeroMemory((PVOID)&bInfo, sizeof(BROWSEINFO) );
BOOL bIsRepository(m_strInitDir.IsEmpty() );
if (!m_strInitDir.IsEmpty() ) {
OLECHAR olePath[MAX_PATH];
ULONG chEaten;
ULONG dwAttributes;
HRESULT hr;
LPSHELLFOLDER pDesktopFolder;
//
// Get a pointer to the Desktop's IShellFolder interface.
//
if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder) ) ) {
//
// IShellFolder::ParseDisplayName requires the file name be in Unicode.
//
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
m_strInitDir.GetBuffer(MAX_PATH),
-1,
olePath,
MAX_PATH);
m_strInitDir.ReleaseBuffer(-1);
//
// Convert the path to an ITEMIDLIST.
//
hr = pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pidl, &dwAttributes);
if (FAILED(hr) ) {
pMalloc->Free(pidl);
pMalloc->Release();
return FALSE;
}
bInfo.pidlRoot = pidl;
}
} else
bInfo.pidlRoot = NULL;
bInfo.hwndOwner = pwndParent == NULL ? NULL : pwndParent->GetSafeHwnd();
bInfo.pszDisplayName = m_strPath.GetBuffer(MAX_PATH);
bInfo.lpszTitle = (m_strTitle.IsEmpty()) ? "Open" : m_strTitle;
bInfo.ulFlags = BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
| (m_bStatus ? BIF_STATUSTEXT : 0 );

bInfo.lpfn = BrowseCtrlCallback; // address of callback function
//bInfo.lpfn = NULL;
bInfo.lParam = (LPARAM)this; // pass address of object to callback function

if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)
return FALSE;

CString strTmp(m_strPath);
m_iImageIndex = bInfo.iImage;
if (::SHGetPathFromIDList(pidl, m_strPath.GetBuffer(MAX_PATH)) == FALSE) {
pMalloc->Free(pidl);
pMalloc->Release();
if (!bIsRepository)
return FALSE;
//Chapuza, para que se pase el nombre de la maquina solamente, sin ningun directorio
m_strPath.Format(_T("\\\\%s"), strTmp.GetBuffer(MAX_PATH) );
m_iImageIndex = bInfo.iImage;
return TRUE;
}

m_strPath.ReleaseBuffer();
pMalloc ->Free(pidl);
pMalloc ->Release();
return TRUE;
}
---------------------------------
Use:

CDirDialog dirDialog;

dirDialog.m_strInitDir = _T(""); //the root dir
dirDialog.m_strSelDir = //Initial select dir
dirDialog.m_strTitle.LoadString(IDS_STRING_SELECT_DIR); //title
dirDialog.m_strWindowTitle.LoadString(IDS_STRING_SELECT_REPOSITORIO); //title window

if (dirDialog.DoBrowse( this ) ) {
dirDialog.m_strPath; //Here is the select dir
}
-----------------------------------------------------


Generalkeyboard Pin
viliam2-Dec-03 22:35
viliam2-Dec-03 22:35 
GeneralRe: keyboard Pin
BaldwinMartin2-Dec-03 22:46
BaldwinMartin2-Dec-03 22:46 
GeneralRe: keyboard Pin
viliam2-Dec-03 23:25
viliam2-Dec-03 23:25 
Generalcompilation speed vs6 vs. vs.net 2003 Pin
niklo2-Dec-03 22:28
niklo2-Dec-03 22:28 
GeneralRe: compilation speed vs6 vs. vs.net 2003 Pin
Antti Keskinen3-Dec-03 2:59
Antti Keskinen3-Dec-03 2:59 
GeneralRe: compilation speed vs6 vs. vs.net 2003 Pin
niklo3-Dec-03 3:06
niklo3-Dec-03 3:06 
GeneralRe: compilation speed vs6 vs. vs.net 2003 Pin
Antti Keskinen3-Dec-03 3:22
Antti Keskinen3-Dec-03 3:22 
GeneralRe: compilation speed vs6 vs. vs.net 2003 Pin
niklo3-Dec-03 3:56
niklo3-Dec-03 3:56 
Generalopen dialog.. Pin
R. Thomas2-Dec-03 21:23
R. Thomas2-Dec-03 21:23 
GeneralRe: open dialog.. Pin
BaldwinMartin2-Dec-03 22:48
BaldwinMartin2-Dec-03 22:48 
GeneralRe: open dialog.. Pin
R. Thomas3-Dec-03 5:41
R. Thomas3-Dec-03 5:41 
GeneralRe: open dialog.. Pin
BaldwinMartin3-Dec-03 5:50
BaldwinMartin3-Dec-03 5:50 
GeneralRe: open dialog.. Pin
R. Thomas3-Dec-03 15:50
R. Thomas3-Dec-03 15:50 
GeneralRe: open dialog.. Pin
BaldwinMartin4-Dec-03 1:35
BaldwinMartin4-Dec-03 1:35 
GeneralOpen Program @ File Pin
Best Friend2-Dec-03 21:22
Best Friend2-Dec-03 21:22 
GeneralRe: Open Program @ File Pin
RChin2-Dec-03 22:32
RChin2-Dec-03 22:32 
GeneralSimple dialo app, memory leak Pin
J.B.2-Dec-03 21:13
J.B.2-Dec-03 21:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.