?? cnfindwndbase.pas
字號:
{*
================================================================================
* 軟件名稱:控件查看器
* 單元名稱:CnFindWndBase
* 單元作者:cjsh
* 備 注:控件查看器的基類
* 開發(fā)平臺:PWin2000Srv + Delphi 5.0
* 兼容測試:PWin9X/2000/XP + Delphi 5
* 本 地 化:
* 更新記錄:2003.12.13 V1.0
* 創(chuàng)建單元
* 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);
{* 設(shè)置畫筆模式}
procedure CnDrawFocusRect(aValue: Boolean);
{* 畫虛框}
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
{* 構(gòu)造}
destructor Destroy; override;
{* 析構(gòu)}
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 }
//設(shè)置畫筆模式
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;
//構(gòu)造
constructor TCnFindWnd.Create(AOwner: TComponent);
var
Dc: HDC;
begin
inherited Create(AOwner);
FScreenCanvas := TCanvas.Create;
//取桌面句柄
dc := GetDC(0);
FScreenCanvas.Handle := dc;
end;
//析構(gòu)
destructor TCnFindWnd.Destroy;
begin
FScreenCanvas.Free;
inherited;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -