当前位置:主页>销售管理软件> 列表

如何移动无标题窗体

进销存管理软件版1楼: 首先,以下代码可以实现移动。
procedure TForm1.wmncHitTest(var msg: twmnchittest);
begin
inherited;
if (htclient=msg.result) then
msg.result:=htcaption;
end;

但问题是,移动窗体的消息接收有效位置是窗体。在窗体上放置了TPanel、TImage,窗体被充满。这些控件并不拦截标题栏消息,导致无法移动窗体。

请问如何让这些控件也能拦截标题栏消息?

2楼: postmessage可以解决 如最新管家婆软件下载

3楼: 能提供具体代码吗?我不知道用什么参数值!谢谢!

4楼: TPanel、TImage的OnMouseDown指向同一个事件中,该事件添加代码:
ReleaseCapture;
Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);

5楼: //iamy 2005-9
unit MCaptionArea;

interface
uses
Windows, Controls, Messages, Dialogs, Forms, Classes, SysUtils, Graphics;


type

TMCaptionArea = Class(TGraphicControl)
private
FOldWndProc:Pointer;
FWndProc:TWndMethod;
FForm:TForm;
procedure HookProc(Var Msg:TMessage);
function GetParentForm(AOwner:TComponent):TForm;
procedure GetOleWinProc;
procedure SetHook;
procedure SetUnHook;
protected
procedure Loaded;override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Align;
property PopUpMenu;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
implementation

{ TMCaptionArea }

constructor TMCaptionArea.Create(AOwner: TComponent);
begin
inherited;
Self.SetHook;
end;

destructor TMCaptionArea.Destroy;
begin
Self.SetUnHook;
inherited;
end;

procedure TMCaptionArea.GetOleWinProc;
begin
if (not (csDesigning in Self.ComponentState)) and (Parent is TForm) then
FOldWndProc:=Pointer(SetWindowLong(FForm.Handle,GWL_WNDPROC,LongInt(MakeObjectInstance(FWndProc))));


end;

function TMCaptionArea.GetParentForm(AOwner: TComponent): TForm;
var
F:TComponent;
begin
F:=AOwner;
while not ((F=nil) or (F is TForm)) do
begin
F:=F.Owner;
end;
Result:=TForm(F);
end;

procedure TMCaptionArea.HookProc(var Msg:TMessage);
var
P:TPoint;
SP:TPoint;
begin
if not (csDestroying in Self.ComponentState) then
begin
Case Msg.Msg of
WM_NCHitTest:
begin
GetCursorPos(P);
SP.X:=Self.Left;
SP.Y:=Self.Top;
SP:=ClientToScreen(SP);
if (P.X>=SP.X)
and (P.X<=SP.X+Self.Width)
and (P.Y>=SP.Y)
and (P.Y<=SP.Y+Self.Height)
then
begin
Msg.Result:=HTCAPTION;
end else
Msg.Result := CallWindowProc(FOldWndProc,FForm.Handle,Msg.Msg,Msg.WParam, Msg.LParam);
end;
else
Msg.Result := CallWindowProc(FOldWndProc,FForm.Handle,Msg.Msg,Msg.WParam, Msg.LParam);
end;
end else
ExitThread(0);
end;


procedure TMCaptionArea.Loaded;
begin
inherited;
Self.GetOleWinProc;
end;




procedure TMCaptionArea.SetHook;
begin
if not (csDesigning in Self.ComponentState) then
begin
FForm:=Self.GetParentForm(Self.Owner);
Self.FWndProc:=HookProc;
end;
end;

procedure TMCaptionArea.SetUnHook;
begin
if not (csDesigning in Self.ComponentState) then
begin
SetWindowLong(FForm.Handle,GWL_WNDPROC,LongInt(FOldWndProc));
end;
end;

end.

6楼: 多谢lichengbin,搞定!
也感谢其他朋友!