怎样使用WINDOWS API CreateDialog ? ?(50分)

  • 主题发起人 主题发起人 刘李子
  • 开始时间 开始时间

刘李子

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样使用WINDOWS API<br>HWND CreateDialog(<br><br>&nbsp; &nbsp; HINSTANCE hInstance, // handle to application instance<br>&nbsp; &nbsp; LPCTSTR lpTemplate, // identifies dialog box template name &nbsp;<br>&nbsp; &nbsp; HWND hWndParent, // handle to owner window<br>&nbsp; &nbsp; DLGPROC lpDialogFunc // pointer to dialog box procedure<br>&nbsp; &nbsp;);<br>下面代码的错误之处? ? ? <br>procedure TForm1.Button5Click(Sender: TObject);<br>&nbsp; function dlgpro(dlghandle:hwnd;dlgmsg:uint;dlgwp:wparam;dlglp:lparam):boolean;stdcall;<br>&nbsp; var<br>&nbsp; &nbsp; adc:hdc;<br>&nbsp; &nbsp; arect:trect;<br>&nbsp; &nbsp; agdiobj:hgdiobj;<br>&nbsp; begin<br>&nbsp; &nbsp; case dlgmsg of<br>&nbsp; &nbsp; wm_initdialog:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; getwindowrect(dlghandle,arect);<br>&nbsp; &nbsp; &nbsp; agdiobj:=getstockobject(black_brush);<br>&nbsp; &nbsp; &nbsp; adc:=getdc(dlghandle);<br>&nbsp; &nbsp; &nbsp; fillrect(adc,arect,agdiobj);<br>&nbsp; &nbsp; &nbsp; result:=true;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; wm_paint:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; updatewindow(dlghandle);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>var<br>&nbsp; ainstance,ret:thandle;<br>begin<br>&nbsp; ainstance:=loadlibrary('comdlg32.dll');<br>&nbsp; if ainstance &lt;&gt; 0 then begin<br>&nbsp; ret:=createdialog(ainstance,'open',application.handle,@dlgpro);<br>&nbsp; if ret=0 then showmessage('Create dialog failed !');<br>&nbsp; freelibrary(ainstance);<br>&nbsp; end<br>&nbsp; else showmessage('Load library failed !');<br>end;<br>
 
不能这样用,LPCTSTR lpTemplate是在你的资源文件中定义的对话框的资源名字,不能随便<br>起。而且hInstance参数的值应该是你的应用程序的hInstance,不是comdlg32.dll的。<br><br>不过你真的有必要用API创建窗体吗?
 
我是想调用COMDLG32.DLL里面OPEN文件打开对话框。<br>不用TOPENDIALOG怎样用WINDOWS API调用系统的文件打开对话框呢?<br>我想知道我不知道的WINDOWS API 函数调用,这就是我的目的。<br>望相救! !<br>
 
原来你是想这样,试试下面的代码吧:<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; ofn:tagOFNA;<br>&nbsp; szFile:Pchar;<br>begin<br>GetMem(szFile,260);<br>ZeroMemory(szFile,260);<br>// Initialize OPENFILENAME<br>ZeroMemory(@ofn, sizeof(tagOFNA));<br>ofn.lStructSize := sizeof(tagOFNA);<br>ofn.hwndOwner := Application.Handle;<br>ofn.lpstrFile := szFile;<br>ofn.nMaxFile := 260;<br>ofn.lpstrFilter := pchar('All'#0'*.*'#0'Text'#0'*.TXT'#0);<br>ofn.nFilterIndex := 1;<br>ofn.lpstrFileTitle := nil;<br>ofn.nMaxFileTitle := 0;<br>ofn.lpstrInitialDir := nil;<br>ofn.Flags := OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST;<br>// Display the Open dialog box.<br>if (GetOpenFileName(ofn))then<br>&nbsp; ShowMessage(szFile)<br><br>FreeMem(szFile);<br><br>end;<br>
 
谢谢ZHHC的支持!<br>但我的意思是用CREATEDIALOG这个函数,至于函数GETOPENFILENAME我会用的了,<br>请给予CREATEDIALOG函数例子:)
 
把你的程序改了一下,看看吧,不过这些关于对话框的还是对于Delphi没什么用。<br>下面的程序还不完善,不过可以显示对话框了。<br>procedure TForm1.Button2Click(Sender: TObject);<br>&nbsp; function dlgpro(dlghandle:hwnd;dlgmsg:uint;dlgwp:wparam;dlglp:lparam):boolean;stdcall;<br>&nbsp; var<br>&nbsp; &nbsp; adc:hdc;<br>&nbsp; &nbsp; arect:trect;<br>&nbsp; &nbsp; agdiobj:hgdiobj;<br>&nbsp; &nbsp; p:PAINTSTRUCT;<br>&nbsp; begin<br>&nbsp; &nbsp; case dlgmsg of<br>&nbsp; &nbsp; wm_initdialog:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; result:=true;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; wm_paint:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; BeginPaint(dlghandle,p);<br>&nbsp; &nbsp; &nbsp; agdiobj:=getstockobject(black_brush);<br>&nbsp; &nbsp; &nbsp; fillrect(p.hdc,p.rcPaint,agdiobj);<br>&nbsp; &nbsp; &nbsp; EndPaint(dlghandle,p);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>var<br>&nbsp; ainstance,ret:thandle;<br>begin<br>&nbsp; ainstance:=loadlibrary('comdlg32.dll');<br>&nbsp; if ainstance &lt;&gt; 0 then begin<br>&nbsp; ret:=createdialog(ainstance,MAKEINTRESOURCE(1547),application.handle,@dlgpro);<br>&nbsp; if ret=0 then showmessage('Create dialog failed !');<br>&nbsp; freelibrary(ainstance);<br>&nbsp; end<br>&nbsp; else showmessage('Load library failed !');<br>end;<br>
 
对ZHHC再次表示感谢,但问题的关键是MAKEINTRESOURCE(1547)中的1547你是怎么<br>得知的呢? ? ?告之 ,立马给分 !
 
翟海辰,有空联系!<br>多多向你请教 !
 
我是用VC打开comdlg32.dll看它的资源,1547就是文件打开对话框的资源ID。<br>另外:我的名字应该是琛不是辰
 
i don't know
 
翟海琛,聪明!<br>多谢你的帮助。送上50分!<br>满意不? ? ?请回答——
 
我代码createdialog(ainstance,'open',application.handle,@dlgpro);中<br>的“OPEN”意思是OPEN FILE DIALOG,我看通用对话框的名字为OPEN、SAVE AS、<br>PRINT。。。。所以设之为OPEN,就是没法打开。不过用MAKEINTRESOURCE MACRO是行<br>的,那就行了。呵呵
 
奇怪,我怎么不能运行这段代码?<br>在 dlgpro 里设断点,发现dlgpro根本就没运行<br>...........................................<br>&nbsp;function dlgpro(dlghandle:hwnd;dlgmsg:uint;dlgwp:wparam;dlglp:lparam):boolean;stdcall;<br>&nbsp;var<br>&nbsp; &nbsp;adc:hdc;<br>&nbsp; &nbsp;arect:trect;<br>&nbsp; &nbsp;agdiobj:hgdiobj;<br>&nbsp; &nbsp;p:PAINTSTRUCT;<br>&nbsp;begin<br>&nbsp; &nbsp;case dlgmsg of<br>&nbsp; &nbsp;wm_initdialog:<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;result:=true;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;wm_paint:<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;BeginPaint(dlghandle,p);<br>&nbsp; &nbsp; &nbsp;agdiobj:=getstockobject(black_brush);<br>&nbsp; &nbsp; &nbsp;fillrect(p.hdc,p.rcPaint,agdiobj);<br>&nbsp; &nbsp; &nbsp;EndPaint(dlghandle,p);<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;end;<br>&nbsp;end;<br>var<br>&nbsp;ainstance,ret:thandle;<br>begin<br>&nbsp;ainstance:=loadlibrary('comdlg32.dll');<br>&nbsp;if ainstance &lt;&gt; 0 then begin<br>&nbsp;ret:=createdialog(ainstance,MAKEINTRESOURCE(1547),application.handle,@dlgpro);<br>&nbsp;if ret=0 then showmessage('Create dialog failed !');<br>&nbsp;freelibrary(ainstance);<br>&nbsp;end<br>&nbsp;else showmessage('Load library failed !');<br>end;
 
后退
顶部