admfotad
asked on
Component handle while mouse is over
Hi
I would like to ask you how can I get handle of any component while mouse is over and for example move this component while mouse is over or change the caption (get parent ).
Regards
I would like to ask you how can I get handle of any component while mouse is over and for example move this component while mouse is over or change the caption (get parent ).
Regards
I think that this is what you need:
You can check on every component that you want to react on mouse over int the 2 procedures onEnter and onExit
The "parent" that you mentioned above is the Sender from the two procedures.
...
private
FFocusControl: TControl;
procedure ApplicationIdle(Sender: TObject; var Done: Boolean);
{ Private declarations }
public
procedure OnEnter(Sender: TObject);
procedure OnExit(Sender: TObject);
{ Public declarations }
procedure TForm1.ApplicationIdle(Sen der: TObject; var Done: Boolean);
var
CurControl: TControl;
P: TPoint;
begin
GetCursorPos(P);
CurControl := FindDragTarget(P, True);
if FFocusControl <> CurControl then
begin
if FFocusControl <> nil then
OnExit(FFocusControl);
FFocusControl := CurControl;
if FFocusControl <> nil then
OnEnter(FFocusControl);
end;
end;
procedure TForm1.OnEnter(Sender: TObject);
begin
//OnEnter code
if (sender = Image2)or(sender=Label14) then
begin
Image2.Left:=Image2.Left+1 ;
Image2.Picture.LoadFromFil e('C:\save 1.bmp');
Label14.Font.Style:=[fsBol d];
end;
end;
procedure TForm1.OnExit(Sender: TObject);
begin
//OnExit code
if (sender = Image2)or(sender=Label14) then
begin
Image2.Left:=Image2.Left-1 ;
Image2.Picture.LoadFromFil e('C:\save 2.bmp');
Label14.Font.Style:=[];
end;
end;
You can check on every component that you want to react on mouse over int the 2 procedures onEnter and onExit
The "parent" that you mentioned above is the Sender from the two procedures.
...
private
FFocusControl: TControl;
procedure ApplicationIdle(Sender: TObject; var Done: Boolean);
{ Private declarations }
public
procedure OnEnter(Sender: TObject);
procedure OnExit(Sender: TObject);
{ Public declarations }
procedure TForm1.ApplicationIdle(Sen
var
CurControl: TControl;
P: TPoint;
begin
GetCursorPos(P);
CurControl := FindDragTarget(P, True);
if FFocusControl <> CurControl then
begin
if FFocusControl <> nil then
OnExit(FFocusControl);
FFocusControl := CurControl;
if FFocusControl <> nil then
OnEnter(FFocusControl);
end;
end;
procedure TForm1.OnEnter(Sender: TObject);
begin
//OnEnter code
if (sender = Image2)or(sender=Label14) then
begin
Image2.Left:=Image2.Left+1
Image2.Picture.LoadFromFil
Label14.Font.Style:=[fsBol
end;
end;
procedure TForm1.OnExit(Sender: TObject);
begin
//OnExit code
if (sender = Image2)or(sender=Label14) then
begin
Image2.Left:=Image2.Left-1
Image2.Picture.LoadFromFil
Label14.Font.Style:=[];
end;
end;
ASKER
calinutz I was trying to say that i'd like to get handle any component and not only this component's placed on the form
regards
regards
ASKER
Kate I think that it's not what I'm looking for :(((
I have to get handle of any component and in examples in this link it's not working for me ....moreover i had a listning what i'm lookin for but now i can not find it :)
I have to get handle of any component and in examples in this link it's not working for me ....moreover i had a listning what i'm lookin for but now i can not find it :)
ASKER
Another words for instance I'd like to get handle of "My computer" when mouse is over this component and so on
Regards
Regards
Hi again, did you tried:
unit Mouse;
interface
uses Controls;
const
MouseCallback: procedure(AControl: TControl; X, Y: Integer) = nil;
unit Main;
type
TMainForm = class(TForm)
end;
var
MainForm: TMainForm;
implementation
uses Mouse;
procedure MyMouse(AControl: TControl; X, Y: Integer);
begin
if MainForm <> nil then
if AControl <> nil then MainForm.Caption := AControl.Name
else MainForm.Caption := '';
end;
initialization
MouseCallback := MyMouse;
end.
End of Example.
You can encapsuled this code in a Component.
Sorry for my english.}
implementation
uses Windows, Messages;
const
FMouseHook: hHook = 0;
FInProc: Integer = 0;
FMouseControl: TControl = nil;
function MouseProc(Code: Integer; wParam: WParam; lParam: LParam): LResult; stdcall; export;
var
C: TControl;
P: TPoint;
begin
if (Code = hc_Action) and (FInProc = 0) then
try
Inc(FInProc); {Disables Recursion's}
if (wParam = wm_MouseMove) or (wParam = wm_NCMouseMove) then
begin
GetCursorPos(P);
C := FindDragTarget(P, True);
if C <> FMouseControl then
begin
FMouseControl := C; // here C.Handle is your handle to control the mouse is actually over
if Assigned(MouseCallback) then MouseCallback(FMouseContro l, P.X, P.Y);
end;
end;
finally
Dec(FInProc);
end;
Result := CallNextHookEx(FMouseHook, Code, wParam, lParam);
end;
initialization
FMouseHook := SetWindowsHookEx(WH_MOUSE, MouseProc, 0, GetCurrentThreadID);
finalization
if FMouseHook <> 0 then UnHookWindowsHookEx(FMouse Hook);
FMouseHook := 0;
end.
**********
in FMouseControl.Handle is your desired handle moreover it works not
just for your application but for whole desktop if you'll encapsulate it
in DLL.
regards,
Kate
unit Mouse;
interface
uses Controls;
const
MouseCallback: procedure(AControl: TControl; X, Y: Integer) = nil;
unit Main;
type
TMainForm = class(TForm)
end;
var
MainForm: TMainForm;
implementation
uses Mouse;
procedure MyMouse(AControl: TControl; X, Y: Integer);
begin
if MainForm <> nil then
if AControl <> nil then MainForm.Caption := AControl.Name
else MainForm.Caption := '';
end;
initialization
MouseCallback := MyMouse;
end.
End of Example.
You can encapsuled this code in a Component.
Sorry for my english.}
implementation
uses Windows, Messages;
const
FMouseHook: hHook = 0;
FInProc: Integer = 0;
FMouseControl: TControl = nil;
function MouseProc(Code: Integer; wParam: WParam; lParam: LParam): LResult; stdcall; export;
var
C: TControl;
P: TPoint;
begin
if (Code = hc_Action) and (FInProc = 0) then
try
Inc(FInProc); {Disables Recursion's}
if (wParam = wm_MouseMove) or (wParam = wm_NCMouseMove) then
begin
GetCursorPos(P);
C := FindDragTarget(P, True);
if C <> FMouseControl then
begin
FMouseControl := C; // here C.Handle is your handle to control the mouse is actually over
if Assigned(MouseCallback) then MouseCallback(FMouseContro
end;
end;
finally
Dec(FInProc);
end;
Result := CallNextHookEx(FMouseHook,
end;
initialization
FMouseHook := SetWindowsHookEx(WH_MOUSE,
finalization
if FMouseHook <> 0 then UnHookWindowsHookEx(FMouse
FMouseHook := 0;
end.
**********
in FMouseControl.Handle is your desired handle moreover it works not
just for your application but for whole desktop if you'll encapsulate it
in DLL.
regards,
Kate
ASKER
kate i know but don't want to encapsulate it in dll .... :)
regards
regards
ASKER
I have to keep all application is single file
regards
regards
Then I'll be glad to see a different working
approach. IMHO you can't catch the global
messages differently then thru a global hook.
Which is at the best to be encapsulated in
a DLL file. Maybe you'll have to do some
compromises if none will shows us otherwise.
best regards,
Kate
approach. IMHO you can't catch the global
messages differently then thru a global hook.
Which is at the best to be encapsulated in
a DLL file. Maybe you'll have to do some
compromises if none will shows us otherwise.
best regards,
Kate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ZhaawZ... you're right
Thanks for help.
Points are going to Zhaawz
Regards
Thanks for help.
Points are going to Zhaawz
Regards
ASKER
ZhaawZ.. if you could tell me how can I get the caption of icons on the desktop while mouse is over i would be very appreciate
Regards
Regards
Actually icons on desktop aren't separate controls. Desktop ir a ListView control, and icons are items of it.
There was a similar question some time ago (about getting info about icons on desktop):
https://www.experts-exchange.com/questions/21335971/Moving-icons-on-Desktop.html
There was a similar question some time ago (about getting info about icons on desktop):
https://www.experts-exchange.com/questions/21335971/Moving-icons-on-Desktop.html
ASKER
Thanks for help
Regards
Regards
ASKER
Maybe i'm boring but there has to be any possibility to check the caption of icon link on the desktop while somebody is trying to click it with mouse .... if somebody knows any idea then I will post another question here and I will grant him 250 points.
Regards
P.S> let me know
Regards
P.S> let me know
https://www.experts-exchange.com/questions/10049373/Knowing-when-mouse-moves-over-component.html?query=mouseover+active+control&topics=85
is what you want :)
regards,
Kate