我写了个控件,你只要把他放在form上,form就不会到处乱动了,可以不用写代码改
了。
unit StaticForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TStaticForm = class(TComponent)
private
{ Private declarations }
OldWndProc,NewWndProc
ointer;
protected
{ Protected declarations }
function FormHandle:THandle;
procedure NewWndMethod(var Msg:TMessage);
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('hubdog lib', [TStaticForm]);
end;
{ TStaticForm }
constructor TStaticForm.Create(AOwner: TComponent);
var
I:integer;
begin
for I:=0 to AOwner.ComponentCount-1do
if AOwner.Components
is TStaticForm then
raise Exception.Create('only one instatnce can be put on Form');
inherited;
if (Owner=nil) or not (Aowner is TForm) then
raise Exception.Create('Owner must be a Form');
if not (csDesigning in ComponentState) then
begin
NewWndProc:=MakeObjectInstance(NewWndMethod);
OldWndProc:=Pointer(SetWindowLong(FormHandle,gwl_wndPRoc,Longint(NewWndPRoc)));
end
else
begin
NewWndPRoc:=nil;
OldWndProc:=nil;
end;
end;
destructor TStaticForm.Destroy;
begin
if Assigned(NewWndPRoc) then
begin
//SetWindowLong(FormHandle,gwl_WndPRoc,
//Longint(OldWndProc));
FreeObjectInstance(NewWndProc);
end;
inherited;
end;
function TStaticForm.FormHandle: THandle;
begin
Result:=(Owner as TForm).Handle;
end;
procedure TStaticForm.NewWndMethod(var Msg: TMessage);
begin
if Msg.Msg=wm_NCHitTest then
begin
Msg.Result:=CallWindowProc(oldWndProc,
FormHandle,Msg.Msg,Msg.wParam,Msg.lParam);
if Msg.Result=htCaption then
Msg.Result:=htClient;
end
else
Msg.Result:=CallWindowProc(oldWndProc,
FormHandle,Msg.Msg,Msg.wParam,Msg.lParam);
end;
end.