⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cnfindwndbase.pas

📁 控件查看器 最新版本. 该工具可以用来查看控件的Handle、Caption、Class、Rect属性。
💻 PAS
字号:
{*
================================================================================
* 软件名称:控件查看器
* 单元名称:CnFindWndBase
* 单元作者:cjsh
* 备    注:控件查看器的基类
* 开发平台:PWin2000Srv + Delphi 5.0
* 兼容测试:PWin9X/2000/XP + Delphi 5
* 本 地 化:
* 更新记录:2003.12.13 V1.0
*              创建单元
*           2003.12.17 V1.1
*           增加画虚框
*           增加查看坐标
================================================================================
}
unit CnFindWndBase;

interface

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

Type
  TCnFindWnd = Class(TComponent)
  private
    FScreenCanvas: TCanvas;
    FDrawHandle: THandle;
    FDrawFocus: Boolean;
    FCurRect: TRect;
    FWndCaption, FWndHandle, FWndClass, FWndRect: String;
    Procedure SetDrawStyle(AValue: Boolean);
    {* 设置画笔模式}
    procedure CnDrawFocusRect(aValue: Boolean);
    {* 画虚框}
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    {* 构造}
    destructor Destroy; override;
    {* 析构}
    Procedure FindWndExecute;
    {* 查找句柄}
  published
    property WndHandle: String read FWndHandle;
    property WndCaption: String read FWndCaption;
    property WndClass: String read FWndClass;
    property WndRect: String read FWndRect;
    property DrawFocus: Boolean read FDrawFocus Write FDrawFocus;
  end;

implementation

{ TCnFindWnd }

//设置画笔模式
procedure TCnFindWnd.SetDrawStyle(AValue: Boolean);
begin
  With FScreenCanvas Do
  begin
    if AValue then
    begin
      Pen.Color := clAqua;
      Pen.Mode := pmXor;
      Pen.Style := psDot;
      Pen.Width := 2;
    end
    else
    begin
      Pen.Mode := pmNot;
      Pen.Width := 2;
      Pen.Style := psClear;
      Brush.Style := bsclear; //空白刷子
    end;
  end;
end;

//画虚框
procedure TCnFindWnd.CnDrawFocusRect(aValue: Boolean);
var
  FForwardRect: TRect;
begin
  if Not aValue then Exit;
  if FForwardRect.Left <> FCurRect.Left then
  begin
    SetDrawStyle(False);
    FScreenCanvas.Rectangle(FCurRect);
  end;

  FForwardRect := FCurRect;
  SetDrawStyle(True);
  FScreenCanvas.Rectangle(FCurRect);
end;

//查找句柄
procedure TCnFindWnd.FindWndExecute;
var
  Pos: TPoint;
  Buf: array[0..1024] of Char;
begin
  GetCursorPos(Pos);
  FDrawHandle := WindowFromPoint(Pos);
  FWndHandle := IntToStr(FDrawHandle);   //Handle
  GetClassName(FDrawHandle, Buf, 1024);  //Class
  FWndClass := Buf;
  SendMessage(FDrawHandle, WM_GETTEXT, 1024, Integer(@Buf)); //Text
  FWndCaption := Buf;
  GetWindowRect(FDrawHandle, FCurRect); //Rect
  FWndRect := Format('(%d,%d)-(%d,%d) %d,%d', [FCurRect.Left, FCurRect.Top,
    FCurRect.Right, FCurRect.Bottom, FCurRect.Right-FCurRect.Left,
    FCurRect.Bottom-FCurRect.Top]);
  CnDrawFocusRect(DrawFocus); //画虚框
end; 

//构造
constructor TCnFindWnd.Create(AOwner: TComponent);
var
  Dc: HDC;
begin
  inherited Create(AOwner);
  FScreenCanvas := TCanvas.Create;
  //取桌面句柄
  dc := GetDC(0);
  FScreenCanvas.Handle := dc;
end;

//析构
destructor TCnFindWnd.Destroy;
begin
  FScreenCanvas.Free;
  inherited;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -