如何调用Win2000风格的OpenDialog?[GetOpenFileName API](100分)

  • 主题发起人 主题发起人 Kingron
  • 开始时间 开始时间
K

Kingron

Unregistered / Unconfirmed
GUEST, unregistred user!
我用下面的API,总是不能调用出来,那位兄弟给看看?<br>错误信息是:参数错误。<br>type<br>&nbsp; TLPOFNHOOKPROC=function(h:hwnd;uMsg:UINT;wp:wparam;lp:lParam):integer;<br>type<br>&nbsp; TOpenInfo=packed record<br>&nbsp; &nbsp; &nbsp;lStructSize:dword;<br>&nbsp; &nbsp; &nbsp;hwndOwner:hwnd;<br>&nbsp; &nbsp; &nbsp;hInstance:Hwnd;<br>&nbsp; &nbsp; &nbsp;lpstrFilter:LPCTSTR;<br>&nbsp; &nbsp; &nbsp;lpstrCustomFilter:LPTSTR;<br>&nbsp; &nbsp; &nbsp;nMaxCustFilter:dword;<br>&nbsp; &nbsp; &nbsp;nFilterIndex:dword;<br>&nbsp; &nbsp; &nbsp;lpstrFile:lptstr;<br>&nbsp; &nbsp; &nbsp;nMaxFile:dword;<br>&nbsp; &nbsp; &nbsp;lpstrFileTitle:lptstr;<br>&nbsp; &nbsp; &nbsp;nMaxFileTitle:dword;<br>&nbsp; &nbsp; &nbsp;lpstrInitialDir:lpctstr;<br>&nbsp; &nbsp; &nbsp;lpstrTitle:lpctstr;<br>&nbsp; &nbsp; &nbsp;Flags:dword;<br>&nbsp; &nbsp; &nbsp;nFileOffset:word;<br>&nbsp; &nbsp; &nbsp;nFileExtension:word;<br>&nbsp; &nbsp; &nbsp;lpstrDefExt:lpctstr;<br>&nbsp; &nbsp; &nbsp;lCustData:Lparam;<br>&nbsp; &nbsp; &nbsp;lpfnHook:TLPOFNHOOKPROC;<br>&nbsp; &nbsp; &nbsp;lpTemplateName:lpctstr;<br>&nbsp; &nbsp; &nbsp;pvReserved:integer;<br>&nbsp; &nbsp; &nbsp;dwReserved:dword;<br>&nbsp; &nbsp; &nbsp;FlagsEx:dword;<br>&nbsp; end;<br><br>function GetOpenFileName(var info:TOpenInfo):boolean;stdcall; external 'comdlg32.dll' &nbsp;name 'GetOpenFileNameA';<br><br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br>&nbsp; info:TOpenInfo;<br>begin<br>&nbsp; info.lStructSize:=sizeof(info);<br>&nbsp; info.hWndOwner:=handle;<br>&nbsp; info.hInstance:=hinstance;<br>&nbsp; info.lpstrFilter:='';<br>&nbsp; info.lpstrCustomFilter:='';<br>&nbsp; info.nMaxCustFilter:=0;<br>&nbsp; info.nFilterIndex:=0;<br>&nbsp; info.lpstrFile:='c:/text.txt';<br>&nbsp; info.nMaxFile:=2;<br>&nbsp; info.lpstrFileTitle:='Open';<br>&nbsp; info.lpstrInitialDir:='c:/';<br>&nbsp; info.lpstrTitle:='Open Test';<br>&nbsp; info.Flags:=OFN_ENABLESIZING+OFN_EXPLORER;<br>&nbsp; info.nFileOffset:=0;<br>&nbsp; info.nFileExtension:=1;<br>&nbsp; info.lpstrDefExt:='.txt';<br>&nbsp; info.lCustData:=0;<br>&nbsp; info.lpfnHook:=nil;<br>&nbsp; info.lpTemplateName:='';<br>&nbsp; info.pvReserved:=0;<br>&nbsp; info.dwReserved:=0;<br>&nbsp; info.FlagsEx:=0;<br>&nbsp; GetOpenFileName(info);<br>&nbsp; caption:=SysErrorMessage(getlasterror);<br>end;
 
到这里看看<br>http://www.codeproject.com/dialog/win2kfiledlg.asp<br><br>欢迎访问vcl控件讨论区:http://vcl.xilubbs.com
 
可惜是VC的。而且我想用API来调用。看看我的题目。<br>..
 
那个结构delphi本身就有了<br>不用自己定义吧
 
问题在这儿,兄弟:<br>&nbsp; info.lStructSize:=sizeof(info);<br>&nbsp; info.hWndOwner:=handle;<br>&nbsp; info.hInstance:=hinstance;<br>&nbsp; info.lpstrFilter:=''; &nbsp;<br>&nbsp; info.lpstrCustomFilter:='';<br>&nbsp; info.nMaxCustFilter:=0;<br>&nbsp; info.nFilterIndex:=0;<br>&nbsp; info.lpstrFile:='c:/text.txt'; &nbsp;<br>&nbsp; &nbsp; //该参数使用来存放对话框返回的文件名(包含路径)的,得是一个至少256个长的Pchar<br>&nbsp; info.nMaxFile:=2; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp;//该参数使用来指定info.lpstrFile长度以及存放对话框返回的文件名的长度的 &nbsp;<br>&nbsp; info.lpstrFileTitle:='Open';<br>&nbsp; info.lpstrInitialDir:='c:/';<br>&nbsp; info.lpstrTitle:='Open Test';<br>&nbsp; &nbsp; //该参数使用来存放对话框返回的文件名的 &nbsp;info.nFileOffset:=0;<br>&nbsp; info.nFileExtension:=1;<br>&nbsp; info.lpstrDefExt:='.txt';<br>&nbsp; info.lCustData:=0;<br>&nbsp; info.lpfnHook:=nil;<br>&nbsp; <br>仔细查一查帮助吧,正确的调用如下:<br>var<br>&nbsp; info:TOpenInfo;<br>&nbsp; lpstrFile:array[0..1000] of char;<br>&nbsp; lpstrFileTitle:array[0..1000] of char;<br>&nbsp; lpstrFilter:array[0..50] of char;<br>&nbsp; S:String;<br>begin<br>&nbsp; FillChar(lpstrFile,SizeOf(lpstrFile),0);<br>&nbsp; FillChar(lpstrFileTitle,SizeOf(lpstrFileTitle),0);<br>&nbsp; FillChar(lpstrFilter,SizeOf(lpstrFilter),0);<br>&nbsp; S:='文本文件';<br>&nbsp; Move(S[1],lpstrFilter,Length(S));<br>&nbsp; S:='*.TXT';<br>&nbsp; Move(S[1],lpstrFilter[9],Length(S));<br><br>&nbsp; info.lStructSize:=sizeof(info);<br>&nbsp; info.hWndOwner:=handle;<br>&nbsp; info.hInstance:=hinstance;<br>&nbsp; info.lpstrFilter:=lpstrFilter;<br>&nbsp; info.lpstrCustomFilter:=nil;<br>&nbsp; info.nMaxCustFilter:=0;<br>&nbsp; info.nFilterIndex:=1;<br>&nbsp; info.lpstrFile:=lpstrFile;<br>&nbsp; info.nMaxFile:=SizeOf(lpstrFile);<br>&nbsp; info.lpstrFileTitle:=lpstrFileTitle;<br>&nbsp; info.nMaxFileTitle:=SizeOf(lpstrFileTitle);<br>&nbsp; info.lpstrInitialDir:='c:/';<br>&nbsp; info.lpstrTitle:='Open Test';<br>&nbsp; info.Flags:=0;//OFN_ENABLESIZING+OFN_EXPLORER;<br>&nbsp; info.nFileOffset:=0;<br>&nbsp; info.nFileExtension:=0;<br>&nbsp; info.lpstrDefExt:='txt';<br>&nbsp; info.lCustData:=0;<br>&nbsp; info.lpfnHook:=nil;<br>&nbsp; info.lpTemplateName:='';<br>&nbsp; info.pvReserved:=0;<br>&nbsp; info.dwReserved:=0;<br>&nbsp; info.FlagsEx:=0;<br>&nbsp; try<br>&nbsp; if GetOpenFileName(@info) then<br>&nbsp; ShowMessage(info.lpstrFile);<br>&nbsp; except<br>&nbsp; caption:=SysErrorMessage(getlasterror);<br>&nbsp; end;<br>
 
接受答案了.
 
后退
顶部