请讲讲setwindowlong,最好有简单的例子(100分)

  • 主题发起人 主题发起人 nickname
  • 开始时间 开始时间
一个简单的例子。DELPHI7+WIN2000上测试通过<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, ExtCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Panel1: TPanel;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; FClientInstance, FPrevClientProc : TFarProc;<br>&nbsp; &nbsp; hand:THandle;<br>&nbsp; &nbsp; procedure ClientWndProc(var Message: TMessage);<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>procedure TForm1.ClientWndProc(var Message: TMessage);<br>begin<br>&nbsp; case Message.Msg of<br>&nbsp; &nbsp; WM_LBUTTONDBLCLK:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage ('WM_LBUTTONDBLCLK事件');<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; &nbsp;Message.Result := CallWindowProc(FPrevClientProc, hand, Message.Msg, Message.wParam, Message.lParam);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp;hand:=Panel1.Handle;<br>&nbsp; &nbsp;FClientInstance := MakeObjectInstance(ClientWndProc);<br>&nbsp; &nbsp;FPrevClientProc := Pointer(GetWindowLong(hand, GWL_WNDPROC));<br>&nbsp; &nbsp;SetWindowLong(hand, GWL_WNDPROC, LongInt(FClientInstance));<br>end;<br><br>end.<br><br>
 
给你一个更详细的例子!<br>procedure TForm1.CheckBox1Click(Sender: TObject);<br>var<br>&nbsp; &nbsp;WindowStyle: Longint; &nbsp; // holds the window style<br>begin<br>&nbsp; &nbsp;{get the current styles used by this window}<br>&nbsp; &nbsp;WindowStyle:=GetWindowLong(Form1.Handle, GWL_STYLE);<br><br>&nbsp; &nbsp;{toggle the WS_CAPTION style}<br>&nbsp; &nbsp;if (CheckBox1.Checked) then<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle OR WS_CAPTION<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle AND NOT WS_CAPTION;<br><br>&nbsp; &nbsp;{toggle the WS_BORDER style}<br>&nbsp; &nbsp;if (CheckBox2.Checked) then<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle OR WS_BORDER<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle AND NOT WS_BORDER;<br><br>&nbsp; &nbsp;{toggle the WS_SYSMENU style}<br>&nbsp; &nbsp;if (CheckBox3.Checked) then<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle OR WS_SYSMENU<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle AND NOT WS_SYSMENU;<br><br>&nbsp; &nbsp;{toggle the WS_MAXIMIZEBOX style}<br><br>&nbsp; &nbsp;if (CheckBox4.Checked) then<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle OR WS_MAXIMIZEBOX<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle AND NOT WS_MAXIMIZEBOX;<br><br>&nbsp; &nbsp;{toggle the WS_MINIMIZEBOX style}<br>&nbsp; &nbsp;if (CheckBox5.Checked) then<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle OR WS_MINIMIZEBOX<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; WindowStyle:=WindowStyle AND NOT WS_MINIMIZEBOX;<br><br><br>&nbsp; &nbsp;{make the window use the new styles}<br>&nbsp; &nbsp;SetWindowLong(Form1.Handle, GWL_STYLE, WindowStyle);<br><br>&nbsp; &nbsp;{this little trick forces the entire window to redraw,<br>&nbsp; &nbsp; including non-client areas}<br>&nbsp; &nbsp;SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_DRAWFRAME or SWP_NOACTIVATE or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER);<br><br>&nbsp; &nbsp;{display the current styles used by this window}<br>&nbsp; &nbsp;Label1.Caption:='Current Style: '+IntToStr(WindowStyle);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>&nbsp; &nbsp;WindowStyle: Longint; &nbsp; // holds the window style information<br><br>begin<br>&nbsp; &nbsp;{get the current styles used by this window}<br>&nbsp; &nbsp;WindowStyle:=GetWindowLong(Form1.Handle, GWL_STYLE);<br><br>&nbsp; &nbsp;{initialize the check boxes according to the styles that are present}<br>&nbsp; &nbsp;if (WindowStyle AND WS_CAPTION)&gt;0 then CheckBox1.Checked:=TRUE;<br>&nbsp; &nbsp;if (WindowStyle AND WS_BORDER)&gt;0 then CheckBox2.Checked:=TRUE;<br>&nbsp; &nbsp;if (WindowStyle AND WS_SYSMENU)&gt;0 then CheckBox3.Checked:=TRUE;<br>&nbsp; &nbsp;if (WindowStyle AND WS_MAXIMIZEBOX)&gt;0 then CheckBox4.Checked:=TRUE;<br><br>&nbsp; &nbsp;if (WindowStyle AND WS_MINIMIZEBOX)&gt;0 then CheckBox5.Checked:=TRUE;<br><br>&nbsp; &nbsp;{hook up the OnClick events for the checkboxes. this step is necessary<br>&nbsp; &nbsp; because the OnClick event is automatically fired when the Checked<br>&nbsp; &nbsp; property is accessed.}<br>&nbsp; &nbsp;CheckBox1.OnClick:=CheckBox1Click;<br>&nbsp; &nbsp;CheckBox2.OnClick:=CheckBox1Click;<br>&nbsp; &nbsp;CheckBox3.OnClick:=CheckBox1Click;<br>&nbsp; &nbsp;CheckBox4.OnClick:=CheckBox1Click;<br>&nbsp; &nbsp;CheckBox5.OnClick:=CheckBox1Click;<br>end;<br>希望你能理解,其实很简单!
 
多人接受答案了。
 
后退
顶部