Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms and Handles

Status
Not open for further replies.

12221

Technical User
Jul 22, 2004
2
SI
Is there a way to get a pointer to a form if I know the forms handle?
 
You can easily search through all the components owned by your application and compare the handle of each component with your handle.

For example, this function returns the form that corresponds to the handle passed as a parameter:

Code:
function TForm1.GetFormFromHandle(h: THandle): TForm;
var
  c: integer;
  f: TForm;
begin
  result := nil;
  for c := 0 to Application.ComponentCount - 1 do
    if Application.Components[c] is TForm then begin
      f := Application.Components[c] as TForm;
      if f.Handle = h then begin
        result := f;
        break;
      end;
    end;
end;


Andrew
Hampshire, UK
 
Thx Towerbase. Yes this is the solution if the handle belongs to one of our applications components. But the issue is, that I want to get the pointer of a form in another process. The handle was retrieved by API call "EnumWindowsProc".
 
As far as I know, if it is a handle for a window that belongs to another process, how do you know that this "process" was written in Delphi??
Once you step "outside" your application, you have to use whatever Windows provides (DLLs, Handles, Win32API, COM, DDE)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top