关于createwindow的问题,有点难度!(100分)

  • 主题发起人 主题发起人 tanggangsheng
  • 开始时间 开始时间
T

tanggangsheng

Unregistered / Unconfirmed
GUEST, unregistred user!
hwndButton:=CreateWindow('BUTTON',<br>'OKfgdgdgd',<br>WS_VISIBLE,<br>210,<br>210,<br>100,<br>100,<br>form1.Handle,<br>MainMenu1.Handle,//问题一:C++中的NULL ,DELPHI用什么取代<br>GetWindowLong(form1.Handle,GWL_HINSTANCE),<br>nil//问题二:这个可以用nil取代null,为什么mainMenu1.handle不能用nil取代呢?<br>);<br>//问题三:创建一个窗口包含了一个按扭,可这个按扭怎么用呢?想按下这个按扭弹出个对话框什么的!
 
问题一:用nil吧.<br>问题二:HWND是LongWord类型,不是指针类型,不能nil,而是0.<br>问题三:用createwindow创建的window,你必须先子类化一个新的子类出来,<br>然后将窗口定义成该子类,然后用setwiondowlong来设置它的wndproc.最后在<br>wndproc里面处理按键消息.<br>或者如下:<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> &nbsp;StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Edit1: TEdit;<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; &nbsp; procedure mymessage(var msg:TMsg;var handled:boolean);<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br> &nbsp;hb: hwnd;<br>implementation<br><br>{$R *.DFM}<br>var<br> &nbsp;oldmessage:TMessageEvent;<br>procedure tform1.mymessage(var msg:TMsg;var handled:boolean);<br>begin<br> &nbsp;if @oldmessage&lt;&gt;nil then<br> &nbsp; &nbsp;oldmessage(msg,handled);<br> &nbsp;if msg.hwnd=hb then<br> &nbsp;begin<br> &nbsp; &nbsp;if msg.message=WM_KEYDOWN then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;if msg.wParam=VK_F1 then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;msg.wParam:=integer('2');<br>// &nbsp; &nbsp; &nbsp; &nbsp;handled:=true;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br><br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br><br> &nbsp;hb:=Createwindow('edit',nil,ws_child or ws_visible or ws_border,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10,10,200,20,self.handle,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hmenu(-1),hinstance,nil);<br> &nbsp;oldmessage:=application.OnMessage;<br> &nbsp;application.OnMessage:=mymessage;<br>end;<br><br>end.
 
后退
顶部