你要的就是这个吧:
uses
CommDlg;
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';
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 := OFN_EXPLORER + OFN_ALLOWMULTISELECT;
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;