Link to home
Start Free TrialLog in
Avatar of Gurkan
Gurkan

asked on

FindVCLWindow 4 other applications' forms

I can get the name of the control by the following:
FindVCLWindow(Mouse.CursorPos).Name;
But it works only in my form(s) otherwise raises access violation error. What can I do 2 get it work in other windows.
Avatar of Radler
Radler

Hi Gurkan;

What you need has a limitation to VCL Controls see the sample.
If isn't this what you want, tell us. By the way more points will be necessary.
//###Code
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
      Pt : TPoint;
      Control : TWinControl;
      Hnd : THandle;
      Str : array[0..255] of char;
begin
      GetCursorPos( Pt );
      Control:=FindVCLWindow( Pt ); //To NonVCL Windows the return is nil
      if Assigned( Control ) then begin
            Self.Edit1.Text:=Control.Name;
      end else begin
            Hnd:=WindowFromPoint( Pt );
            if Hnd <> 0 then begin
                  GetWindowText( Hnd, Str, 255 );
                  Edit1.Text:=Str;
                  if Str = EmptyStr then begin
                        GetClassName( Hnd, Str, 255 );
                        Edit1.Text:=Str;
                  end;
            end else begin
                  Edit1.Text:='NONE';
            end;
      end;
end;

end.


//### The DFM
object Form1: TForm1
  Left = 196
  Top = 103
  Width = 711
  Height = 172
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 99
    Top = 32
    Width = 505
    Height = 21
    TabOrder = 0
    Text = 'Edit1'
  end
  object Button1: TButton
    Left = 336
    Top = 96
    Width = 75
    Height = 25
    Caption = 'Get it'
    TabOrder = 1
    OnClick = Button1Click
  end
end


T++, Radler.
Avatar of Gurkan

ASKER

Adjusted points to 50
Avatar of Gurkan

ASKER

In fact your answer is the answer for my question but I just noticed that the name is not enough for me. I want to control its properties how can I do that? (Points Adjusted)
ASKER CERTIFIED SOLUTION
Avatar of Radler
Radler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gurkan

ASKER

Thx