Windows的选中效果,如何判断?(200分)

Z

zxl893

Unregistered / Unconfirmed
GUEST, unregistred user!
拖动鼠标,如何知道有几个控件在这区域内?
 
有没有人知道啊???
 
可能要计算鼠标的座标的范围,然后得到窗口中每个控件座标
 
怎样知道鼠标的坐标与控件的坐标相交呢?
 
可以使用IntersectRect函数判断并可以返回相交的矩形。
 
逐个检测!
 
根据控件的Left,Width和Top,Height判断呀。

给你一个Form内鼠标钩子的例子:
{
demonstrate a mouse hook in a form.
}
unit Unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
FMHook: HHOOK;
function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;

implementation

{$R *.DFM}

function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
begin
if Msg.Message = WM_MOUSEMOVE then
with form1 do
begin
caption := format('Mouse Pos in the form:%d,%d',[msg.pt.x,msg.pt.y]);
//做你要做的事
end ;
Result := CallNextHookEx(FMHook, Code, WParam, Longint(@Msg)); //放出消息给下一个.
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FMHook := SetWindowsHookEx(WH_GETMESSAGE, @FMHookProc, 0, GetCurrentThreadID);
end;

end.
 
接受答案
 

Similar threads

顶部