精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>Windows API函数>>[文章]调用Wind2000风格的对话框

主题:[文章]调用Wind2000风格的对话框
发信人: kingron( )
整理人: delfan(2001-04-03 17:35:59), 站内信件
Win2000风格的OpenDialog左边有一个PlaceBar,就是几个大的按钮,可以快速切换!在Delphi应该如下调用;
主要利用API  GetOpenFileName。

type   //定义打开文件对话框信息结构回调函数
  TLPOFNHOOKPROC=function(h:hwnd;uMsg:UINT;wp:wparam;lp:lParam):integer;
type  //定义打开文件对话框信息结构
  TOpenInfo=packed record
     lStructSize:dword;
     hwndOwner:hwnd;
     hInstance:Hwnd;
     lpstrFilter:LPCTSTR;
     lpstrCustomFilter:LPTSTR;
     nMaxCustFilter:dword;
     nFilterIndex:dword;
     lpstrFile:lptstr; //该参数使用来存放对话框返回的文件名(包含路径)的,得是一个至少256个长的Pchar
     nMaxFile:dword; //该参数使用来指定info.lpstrFile长度以及存放对话框返回的文件名的长度的
     lpstrFileTitle:lptstr;
     nMaxFileTitle:dword;
     lpstrInitialDir:lpctstr;
     lpstrTitle:lpctstr;
     Flags:dword;
     nFileOffset:word;
     nFileExtension:word;
     lpstrDefExt:lpctstr;
     lCustData:Lparam;
     lpfnHook:TLPOFNHOOKPROC;
     lpTemplateName:lpctstr;
     pvReserved:integer;
     dwReserved:dword;
     FlagsEx:dword;
  end;

function GetOpenFileName(var info:TOpenInfo):boolean;stdcall; external 'comdlg32.dll'  name 'GetOpenFileNameA';

//上面是声明API函数,下面是调用举例:

procedure TForm1.Button1Click(Sender: TObject);
var
  info:TOpenInfo;
  lpstrFile:array[0..1000] of char;
  lpstrFileTitle:array[0..1000] of char;
  lpstrFilter:array[0..50] of char;
  S:String;
begin
  FillChar(lpstrFile,SizeOf(lpstrFile),0);
  FillChar(lpstrFileTitle,SizeOf(lpstrFileTitle),0);
  FillChar(lpstrFilter,SizeOf(lpstrFilter),0);
  S:='文本文件';
  Move(S[1],lpstrFilter,Length(S));
  S:='*.TXT';
  Move(S[1],lpstrFilter[9],Length(S));

  info.lStructSize:=sizeof(info);
  info.hWndOwner:=handle;
  info.hInstance:=hinstance;
  info.lpstrFilter:=lpstrFilter;
  info.lpstrCustomFilter:=nil;
  info.nMaxCustFilter:=0;
  info.nFilterIndex:=1;
  info.lpstrFile:=lpstrFile;
  info.nMaxFile:=SizeOf(lpstrFile);
  info.lpstrFileTitle:=lpstrFileTitle;
  info.nMaxFileTitle:=SizeOf(lpstrFileTitle);
  info.lpstrInitialDir:='c:\';
  info.lpstrTitle:='Open Test';
  info.Flags:=0;//OFN_ENABLESIZING+OFN_EXPLORER;
  info.nFileOffset:=0;
  info.nFileExtension:=0;
  info.lpstrDefExt:='txt';
  info.lCustData:=0;
  info.lpfnHook:=nil;
  info.lpTemplateName:='';
  info.pvReserved:=0;
  info.dwReserved:=0;
  info.FlagsEx:=0;
  try
  if GetOpenFileName(info) then
  ShowMessage(info.lpstrFile);
  except
  caption:=SysErrorMessage(getlasterror);
  end;
end;


----
<img src="http://uh1.gz.163.com photo?name=kingron" border=0 alt="我是谁?">  

[关闭][返回]