본문 바로가기
Delphi Tip/Windows

마우스 포인터 좌표의 윈도우 정보얻기

by MonoSoft 2024. 3. 1.
728x90
반응형

마우스 포인터 좌표의 윈도우 정보얻기

 

728x90

 

마우스 포인터가 있는 좌표의 윈도우의 핸들, 클래스, 명칭을 보여주는 예제입니다.

 

 

unit unit1;

 

interface

 

uses

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

 

type

TForm1 = class(TForm)

Timer1: TTimer;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

procedure FormCreate(Sender: TObject);

procedure Timer1Timer(Sender: TObject);

private

procedure ShowHwndAndClassName(CrPos: TPoint);

public

end;

 

var

Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

// ============ 요기가 핵심 부분 ===================

procedure TForm1.ShowHwndAndClassName(CrPos: TPoint);

var

hWnd: THandle;

aName,Text : array [0..255] of char;

begin

hWnd := WindowFromPoint(CrPos);

Label1.Caption := 'Handle : ' + IntToStr(hWnd);

if boolean(GetClassName(hWnd, aName, 256)) then

Label2.Caption := 'ClassName : ' + string(aName)

else

Label2.Caption := 'ClassName : not found';

SendMessage(hWnd, WM_GETTEXT, SizeOf(Text), integer(@Text));

Label3.Caption := 'Text :' + Text;

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

Form1.FormStyle := fsStayOnTop;

Timer1.Interval := 50;

end;

 

procedure TForm1.Timer1Timer(Sender: TObject);

var

rPos: TPoint;

begin

if boolean(GetCursorPos(rPos)) then

ShowHwndAndClassName(rPos);

end;

end.

 

728x90
반응형

댓글