谁会使用 CreateDialog 函数?请给个确实可用的例子,谢谢。(50分)

  • 主题发起人 主题发起人 WorldCreater
  • 开始时间 开始时间
W

WorldCreater

Unregistered / Unconfirmed
GUEST, unregistred user!
谁会使用 CreateDialog 函数?请给个确实可用的例子,谢谢。
 
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>
 
怎么对话框总是创建失败?
 
我怎么试了一下可以呢?<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(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><br><br>end.<br>
 
总是显示消息框 "create dialog failed"<br><br>你这例子好象是大富翁论坛以前提问的吧
 
行了,我现用的这机器有问题,换了台就好了。换歉。呵呵
 
这个例子有时行,有时不行,好象跟机器有关啊?
 
后退
顶部