Shell ApI 问题,急。
Hukay 2002-08-31 02:35:22 我想用下面这段代码。但
#include <shlobj.h>
会编译通不过。
运行环境:
OS:Windows98,BCB5.1
请高手解答。
void __fastcall TForm1::Button1Click(TObject *Sender)
{
BROWSEINFO info;
char szDir[MAX_PATH];
char szDisplayName[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
// SHBrowseForFolder returns a PIDL. The memory for the PIDL is
// allocated by the shell. Eventually, we will need to free this
// memory, so we need to get a pointer to the shell malloc COM
// object that will free the PIDL later on.
if(SHGetMalloc(&pShellMalloc) == NO_ERROR)
{
// if we were able to get the shell malloc object,
// then proceed by initializing the BROWSEINFO stuct
memset(&info, 0x00,sizeof(info));
info.hwndOwner = Handle; // Owner window
info.pidlRoot = 0; // root folder
info.pszDisplayName = szDisplayName; // return display name
info.lpszTitle = "Browse Title"; // label caption
info.ulFlags = BIF_RETURNONLYFSDIRS; // config flags
info.lpfn = 0; // callback function
// execute the browsing dialog
pidl = SHBrowseForFolder(&info);
// pidl will be null if they cancel the browse dialog.
// pidl will be not null when they select a folder
if(pidl)
{
// try to convert the pidl to a display string
// return is true if success
if(SHGetPathFromIDList(pidl, szDir))
{
// set one caption to the directory path
Label1->Caption = szDir;
}
// set another caption based on the display name
Label2->Caption = info.pszDisplayName;
// use the shell malloc com object to free the pidl.
// then call Relasee to signal that we don't need
// the shell malloc object anymore
pShellMalloc->Free(pidl);
}
pShellMalloc->Release();
}
}