Exists any way to get a component name using only your handle? I dont´t have
the component instance ....
Rafael Colucci
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
"Jens Gruschel" <nos...@pegtop.net> escreveu na mensagem
news:4213373e$1...@newsgroups.borland.com...
> 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
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
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