xwindows.pas

来自「在深度历险网站上发布的所有delphi程序原码。对初学delphi者很有用。」· PAS 代码 · 共 54 行

PAS
54
字号
unit xWindows;

interface

uses Windows, Sysutils, Controls, Forms;

const
  DEFAULT_FOCUSRECT_WIDTH = 3;
  
function FindControl(Handle: HWND; ProcessID: DWORD = 0): TWinControl;
function IsDelphiHandle(Handle: HWND; ProcessID: DWORD = 0): Boolean;

function FindTopmostWindow(ParentWnd: HWND; Pt: TPoint): HWND;

procedure MyDrawFocusRect(DC: HDC; R: TRect; Width: Integer = DEFAULT_FOCUSRECT_WIDTH);
procedure DrawWindowFocusRect(Wnd: HWND; Width: Integer = DEFAULT_FOCUSRECT_WIDTH);
procedure DrawControlFocusRect(Control: TControl; Width: Integer = DEFAULT_FOCUSRECT_WIDTH);

implementation

uses xKernel;

var
  WindowAtom : TAtom;               
  ControlAtom: TAtom;               
  
  AtomText   : array[0..31] of Char;
  
  { Find a TWinControl given a window handle }
  
function FindControl(Handle: HWND; ProcessID: DWORD = 0): TWinControl;
begin
//  DebugStrFmt('Find Control Handle = %x',[Handle]);
  if Handle <> 0 then
  begin
    if ProcessID = 0 then
      GetWindowThreadProcessId(Handle, @ProcessID);
    WindowAtom := GlobalAddAtom(StrFmt(AtomText, 'Delphi%.8X',[ProcessID]));
    Result := Pointer(GetProp(Handle, MakeIntAtom(WindowAtom)));
//    DebugStrFmt('Find Control PID = %x Result = %p',[ProcessID, Pointer(Result)]);
  end else
    Result := nil;
end;

function IsDelphiHandle(Handle: HWND; ProcessID: DWORD = 0): Boolean;
begin
  Result := FindControl(Handle, ProcessID) <> nil;
end;

function FindTopmostWindow(ParentWnd: HWND; Pt: TPoint): HWND;
var
  R: TRect;
begin
  Result := GetWindow(ParentWnd, GW_CHILD); // 

⌨️ 快捷键说明

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