#define NO_WIN32_LEAN_AND_MEAN // BCB6 一定要有這句, 不然會錯
#include

AnsiString szPreDir = "";
int __stdcall BrowseProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM lpData )
{
char szDir[MAX_PATH];

switch(uMsg)
{
case BFFM_INITIALIZED:
SendMessage(hwnd, BFFM_SETSTATUSTEXT,0, (LPARAM)"Greetings");

// Set the initial directory. If WPARAM is TRUE, then LPARAM is a
// string that contains the path. If WPARAM is FALSE, then LPARAM
// should be a lovely PIDL
if (szPreDir != "")
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szPreDir.c_str());
break;
case BFFM_SELCHANGED:
if(SHGetPathFromIDList((LPITEMIDLIST)lParam, szDir))
Form1->Label3->Caption = szDir;
break;
}
return 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
BROWSEINFO info;
char szDir[MAX_PATH];
char szDisplayName[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;

if(SHGetMalloc(&pShellMalloc) == NO_ERROR)
{
memset(&info, 0x00, sizeof(info));
info.hwndOwner = 0;
info.pidlRoot = NULL;
info.pszDisplayName = szDisplayName;
info.lpszTitle = "Browse Title";
info.ulFlags = BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT|BIF_DONTGOBELOWDOMAIN;
info.lpfn = BrowseProc; // callback function

pidl = SHBrowseForFolder(&info);

if(pidl)
{
if(SHGetPathFromIDList(pidl, szDir))
{
Label1->Caption = szDir;
szPreDir = szDir;
}

Label2->Caption = info.pszDisplayName;

pShellMalloc->Free(pidl);
pShellMalloc->Release();
}
}
}
//---------------------------------------------------------------------------

全站熱搜

Nelson 發表在 痞客邦 留言(0) 人氣()