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();
}
}

...全文
61 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hukay 2002-08-31
  • 打赏
  • 举报
回复
没问题了
cdws222 2002-08-31
  • 打赏
  • 举报
回复
应该没问题了吧
Hukay 2002-08-31
  • 打赏
  • 举报
回复
jishiping(JSP 季世平):
真的谢谢你,
你的两种方法都正确。
不过我还是想问一下
NO_WIN32_LEAN_AND_MEAN
哪有介绍
  • 打赏
  • 举报
回复
#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.hpp>
#include <vcl.h>
jishiping 2002-08-31
  • 打赏
  • 举报
回复
定义的方式不对。有两个方法:
1. 将头文件shlobj.h放在vcl.h之前,同时宏定义也要放在shlobj.h之前,也
就是:
#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.h>
#include <vcl.h>

2. 选择菜单命令[Project]|[Options...],然后选择“Directories/
Conditionals”,在“Conditional defines”里加入宏,多个宏用分号隔
开。如:_DEBUG;NO_WIN32_LEAN_AND_MEAN
Hukay 2002-08-31
  • 打赏
  • 举报
回复
#define NO_WIN32_LEAN_AND_MEAN
不行啊
jishiping 2002-08-31
  • 打赏
  • 举报
回复
在IDE里定义宏 NO_WIN32_LEAN_AND_MEAN 就可以了。
Hukay 2002-08-31
  • 打赏
  • 举报
回复
pazee:
能不能再说清楚一点。
Thank You
耙子 2002-08-31
  • 打赏
  • 举报
回复
老问题了,打开这个头文件 <shlobj.h>
你看看头几行的注释怎么说明的

1,222

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧