Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

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.
0
Gurkan
Asked:
Gurkan
  • 3
  • 2
1 Solution
 
RadlerCommented:
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.
0
 
GurkanAuthor Commented:
Adjusted points to 50
0
 
GurkanAuthor Commented:
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)
0
 
RadlerCommented:
Gurkan,

If the results is a VCLWindow you can changes the properties easily, but if the results show a window from another app you can changes a limited set of properties using the API. See the functions SetWindow* and some messages WM_SETTEXT.
I put again like answer, please before reject give a comment, OK !

T++, Radler.
0
 
GurkanAuthor Commented:
Thx
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now