当在TForm1.OnCreate()中用API函数CreateWindow()创建一个(100分)

  • 主题发起人 主题发起人 inwin
  • 开始时间 开始时间
I

inwin

Unregistered / Unconfirmed
GUEST, unregistred user!
当在TForm1.OnCreate()中用API函数CreateWindow()创建一个<br>窗口后,如何使这个窗口响应Windows消息,如鼠标的双击?
 
不同的窗体处理也不一样,如按钮要先得到它的ID值,然后再自己重载WndProc<br>处理WM_COMMAND消息判断当wParam的值与ID值相等时进行自己的处理。有点像<br>16位编程不过这种方式不是很有必要,除了几个像IP地址编辑器等组件,大部分组<br>件都可视化了没必要再用CreateWindow生成。
 
这段代码或许对你有帮助<br><br>unit Unit4;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm4 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure FormShow(Sender: TObject);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; OldWndMeth, NewWndMeth: Pointer;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form4: TForm4;<br>&nbsp; he:Thandle;<br><br>implementation<br><br>{$R *.DFM}<br><br>var<br>&nbsp; OldWndProc: Pointer = nil;<br><br>function NewWinProc (Handle: THandle;<br>&nbsp; Msg, wParam, lParam: LongInt): LongInt; stdcall;<br>begin<br>&nbsp; if Msg = wm_keydown then<br>&nbsp; begin<br>&nbsp; &nbsp; Beep;<br>&nbsp; &nbsp; SetWindowText (Handle,<br>&nbsp; &nbsp; &nbsp; PChar (Format (' %s', [char(lParam)])));<br>&nbsp; end;<br>&nbsp; // pass call to old window proc<br>&nbsp; Result := CallWindowProc (OldWndProc, Handle,<br>&nbsp; &nbsp; Msg, wParam, lParam);<br>end;<br><br>procedure TForm4.FormShow(Sender: TObject);<br>begin<br>&nbsp; he:=createwindow('edit','edit',ws_border or ws_visible or ws_child,10,10,<br>&nbsp; 100,40,handle,0,hinstance,0);<br>end;<br><br>procedure TForm4.Button1Click(Sender: TObject);<br>begin<br>&nbsp; OldWndProc := Pointer (SetWindowLong<br>&nbsp; &nbsp; (he, gwl_WndProc, LongInt (@NewWinProc)));<br>end;<br><br>end.<br><br>
 
哈哈,好象这下我可以捞分了,试好了可要给呀!嘻嘻!<br>代码如下:<br>procedure OnMsg(var Msg: TMsg; var Handled: Boolean);<br>---implementation----<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; Application.OnMessage := OnMsg;<br>end;<br><br>procedure TfrmCpc.OnMsg(var Msg: TMsg; var Handled: Boolean);<br>begin<br>&nbsp; if (Msg.Message = WM_LBUTTONDBLCLK) then<br>&nbsp; begin<br>&nbsp; &nbsp; //你要做的信息-----<br>&nbsp; end;<br>end;<br>
 
上面的笔误,不好意思。!<br>procedure TForm1.OnMsg(var Msg: TMsg; var Handled: Boolean);<br><br>
 
多人接受答案了。
 
后退
顶部