Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Component Name By Handle

1,212 views
Skip to first unread message

Rafael Colucci

unread,
Feb 16, 2005, 7:38:04 AM2/16/05
to
Hi people

Exists any way to get a component name using only your handle? I dont´t have
the component instance ....

Rafael Colucci


Jens Gruschel

unread,
Feb 16, 2005, 7:03:52 AM2/16/05
to
> Exists any way to get a component name using only your handle? I dont´t have
> the component instance ....

The only thing you can do is to loop through all components recursively
(use ComponentCount / Components) and check their handles. If you know
your control is derived from a custom control you wrote, of course you
can introduce some WM_USER + x message, which returns the control itself
(cast to an integer). Some CM_FIND_ME for all TWinControls would indeed
be nice, but then again it would not work from outside your application.
What you can do is using WM_GETTEXT to return the Text / Caption
property of a control. The text belongs to the handle, but the handle
doesn't necessarily belong to a Delphi control.

Jens

Rafael Colucci

unread,
Feb 16, 2005, 8:18:06 AM2/16/05
to
humm .. but the problem is i dont know if component was made in delphi or
not because i got the component handle in other window, other program ...
There´s any way to differentiate a control to other? Caption dont work
because 2 control can have the same caption ... Handle dont work too because
changes allways the application is restarted ....

Rafael Colucci


"Jens Gruschel" <nos...@pegtop.net> escreveu na mensagem
news:4213373e$1...@newsgroups.borland.com...

Rudy Velthuis [TeamB]

unread,
Feb 16, 2005, 8:01:06 AM2/16/05
to
Rafael Colucci wrote:

> humm .. but the problem is i dont know if component was made in
> delphi or not because i got the component handle in other window,
> other program

There are no component handles in Windows. Components are Delphi
constructs, most of the time wrapping Windows controls, but not always.
If you have a handle, it is a window handle. You can use
Windows.GetWindowText to get the text of the window. Windows and
controls don't have a name associated with them.

function GetWindowText(Window: THandle): string;
begin
SetLength(Result, GetWindowTextLength(Window));
Windows.GetWindowText(Window, PChar(Result), Length(Result) + 1);
end;

--
Rudy Velthuis [TeamB] http://rvelthuis.bei.t-online.de

"Humor is a rubber sword - it allows you to make a point without drawing
blood." -- Mary Hirsch

Jens Gruschel

unread,
Feb 16, 2005, 8:05:28 AM2/16/05
to
> humm .. but the problem is i dont know if component was made in delphi or
> not because i got the component handle in other window, other program ...

So how do you want to get the name, only existing for Delphi controls,
for non-Delphi controls?

> There´s any way to differentiate a control to other?

You mean differentiate it by a string (shown to the user)? There is no
such thing like a name as Delphi provides it.

> Handle dont work too because
> changes allways the application is restarted ....

You mean you want it to be unique persistently? Even a Delphi
application can create controls dynamically and assign random names to
them each time the application is started.

What do you want to achieve?

Jens

Peter Below (TeamB)

unread,
Feb 16, 2005, 9:52:14 AM2/16/05
to
In article <4213...@newsgroups.borland.com>, Rafael Colucci wrote:
> Exists any way to get a component name using only your handle? I dont´t have
> the component instance ....

Only if the component is part of your own process, in which case the
FindControl function will get you a TWincontrol reference from the window
handle. For windows in other processes you can usually get the classname
(using the API function Windows.GetClassname), and for some controls (edit and
button controls mostly) also the text the controls contain (by sending
WM_GETTEXTLENGTH and WM_GETTEXT messages to the control).


--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


0 new messages