Collect all active window class names

2019-07-13 03:09发布

问题:

Many programs (True Transparancy and others) can get all active or running in background window class names like this one:

Delphi 7 Object Inspector name is tpropertyinspector
Opera main window class name is operawindowclass
etc.

So how to get any opened window class name in Delphi?

回答1:

Call EnumWindows to get all the top level windows. Then call GetClassName to find out the window class name for each window. If you also wish to probe child windows then call EnumChildWindows on each top level window.

Call GetClassName like this:

var
  ClassName: string;
  len: Integer;
...
SetLength(ClassName, 256);
len := GetClassName(window, PChar(ClassName), Length(ClassName));
if len=0 then
  RaiseLastOSError;
SetLength(ClassName, len);


回答2:

Simply use the GetClassName function in the Windows API (same way in Delphi as in any language).