|
// FolderBrowse.cpp: implementation of the CFolderBrowse class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FolderBrowse.h"
#include <shlobj.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFolderBrowse::CFolderBrowse(HWND hWnd /*= NULL*/)
{
m_hWnd = hWnd;
}
CFolderBrowse::~CFolderBrowse()
{
}
int CALLBACK BrowseCallbackProc(
HWND hwnd,
UINT uMsg,
LPARAM lParam,
LPARAM lpData
)
{
switch(uMsg)
{
case BFFM_INITIALIZED:
if(lpData)
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)lpData);
break;
case BFFM_SELCHANGED:
LPITEMIDLIST lpiil = (LPITEMIDLIST)lParam;
char szPath[MAX_PATH];
SHGetPathFromIDList(lpiil, szPath);
SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szPath);
break;
}
return 0;
}
bool CFolderBrowse::Browse(LPCSTR lpcsInitialFolder /*= NULL*/, LPCSTR lpcsTitle /*= NULL*/)
{
char szPath[MAX_PATH];
BROWSEINFO bi;
bi.hwndOwner = m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szPath;
bi.lpszTitle = lpcsTitle ? lpcsTitle : "Select folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT;
bi.lpfn = (BFFCALLBACK)BrowseCallbackProc;
bi.lParam = (int)lpcsInitialFolder;
LPITEMIDLIST lpiil = SHBrowseForFolder(&bi);
if(lpiil == NULL)
return false;
SHGetPathFromIDList(lpiil, szPath);
m_strFolder = szPath;
return true;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.