Dmi*_*try 3 delphi winapi delphi-xe2
如何在Delphi上获取活动表单的ClassName(可能来自另一个应用程序)?
似乎只Application.ActiveFormHandle
返回活跃的形式Application
.
我相信,你正在寻找的窗户把手是由它回来的GetForegroundWindow
.
要获取类名,请将该窗口句柄传递给Windows API函数GetClassName
.这是该API函数的Delphi包装器:
function GetWindowClassName(Window: HWND): string;
const
MaxClassNameLength = 257;//256 plus null terminator
var
Buffer: array [0..MaxClassNameLength-1] of Char;
len: Integer;
begin
len := GetClassName(Window, Buffer, Length(Buffer));
if len=0 then
RaiseLastOSError;
SetString(Result, Buffer, len);
end;
Run Code Online (Sandbox Code Playgroud)
我使用了长度为256的缓冲区,因为窗口类名称不允许长于此值.