目录对话诓的问题

tgzhang 2003-08-25 01:56:48
我得这段代码主要想在SHbrowseForFolder调用浏览目录诓时,定位在一个特定的目录上。

大家帮忙看看,我这个程序错误在什么地方?
[C++ Error] Unit1.cpp(18): E2108 Improper use of typedef 'HWND'
[C++ Error] Unit1.cpp(18): E2293 ) expected


#define NO_WIN32_LEAN_AND_MEAN
#include <shlobj.h>
#include <vcl.h>
#include "winbase.h"

#include "FileCtrl.hpp"
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int CALLBACK BrowseCallbackProc(HWND hwnd,UNIT uMsg,LPARAM lParam,LPARAM lpData)
//^^^^^^^问题就在这里
{
char path[256];
TForm1 * pMain=(TForm1 *)lpData;
switch(uMsg)
{
case BFFM_INITIALIZED:
{
SendMessage(hwnd,BFFM_SETSELETCTION,1,(LPARAM)(pMain->InitDir.c_str()));
return 0;
}
default:
return 0;
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::BrowseDirectory(AnsiString InitialPath,AnsiString &NewPath)
{
TBrowseInfo browse;
AnsiString InitDir;
if(DirectoryExists(InitialPath))
InitDir=InitialPath;
else
InitDir="";
ZeroMemory(&browse,sizeof(TBrowseInfo));
browse.hwndOwner=Handle;
browse.lpszTitle="Select a directory";
browse.lpfn=BrowseCallbackProc;
browse.lParam=(long)this;
browse.ulFlags=BIF_RETURNONLYFSDIRS |BIF_RETURNFSANCESTORS;
LPITEMIDLIST pDir=SHBrowseForFolder(&browse);
NewPath="";
if(pDir)
{
char Path[MAX_PATH];
SHGetPathFromIDList(pDir,Path);
CoTaskMemFree(pDir);
NewPath=Path;
}

return NewPath!="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
AnsiString NewPath;
if(BrowseDirectory("c:\\windows",NewPath))
ShowMessage(NewPath);
}
//---------------------------------------------------------------------------
...全文
35 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
everandforever 2003-08-30
  • 打赏
  • 举报
回复
UNIT....

是UINT才对.
FallenAngel 2003-08-30
  • 打赏
  • 举报
回复
你干吗不include windows.h呢?
xhusa 2003-08-29
  • 打赏
  • 举报
回复
extern PACKAGE bool __fastcall SelectDirectory(constAnsiString Caption, const WideString Root, AnsiString &Directory);
extern PACKAGE bool __fastcall SelectDirectory(AnsiString &Directory, TSelectDirOpts Options, int HelpCtx);

Description

Call SelectDirectory to let the user enter a directory name.

Use the first syntax to display the Windows directory browser. The Caption parameter specifies a caption for the dialog. The Root parameter specifies the root directory from which to browse. The selected directory is returned as the Directory parameter. When using this syntax, SelectDirectory does not change the value of the current directory.

Warning: You can抰 use the same variable for the Root parameter and the Directory parameter.

Use the second syntax to call the Select Directory dialog box. The directory passed to the function with the Directory parameter appears as the currently selected directory when the dialog box appears. The name of the directory the user selects becomes the value of Directory when the function returns.

The HelpCtx parameter is the help context ID number.

The Options parameter is a set of values. If Options is the empty set, the user can only select a directory that already exists. No edit box is provided for the user to enter a new directory name. If Options is not empty, the included values determine how the dialog responds when the user types a nonexistent directory name.

With either syntax, SelectDirectory returns true if the user selected a directory and chose OK, and false if the user chose Cancel or closed the dialog box without selecting a directory.

hy1080 2003-08-28
  • 打赏
  • 举报
回复
用全文搜索
对include整个目录搜一下.
tgzhang 2003-08-27
  • 打赏
  • 举报
回复
我的问题,我已经解决了。
主要是不知道那个头文件支持UNIT这个数据类型,主要是他出错,不是其他。
现在我也不知道到底那个头文件包含整个数据类型。那位知道,请不啻指教。
谢谢!

elfnet 2003-08-27
  • 打赏
  • 举报
回复
直接用SelectDirectory,需要include filectrl.hpp

1,222

社区成员

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

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