Delphi/Lazarus: Get Title of Active Window
Tip by Delphian | 2014-08-13 at 17:05
Today, I would like to show you how to retrieve the title respectively caption of the window currently having the focus in Windows.
The following function is working with Delphi as well as Lazarus (the unit Windows has to be included).
function GetTitleOfActiveWindow: string; var AHandle: THandle; ATitle: string; ALen: Integer; begin Result := ''; AHandle := GetForegroundWindow; if AHandle <> 0 then begin ALen := GetWindowTextLength(AHandle) + 1; SetLength(ATitle, ALen); GetWindowText(AHandle, PChar(ATitle), ALen); result := Trim(ATitle); end; end;
First of all, we determine the handle of the window that is in the foreground at the moment and thus has the focus. After that, we are reading out the title of this window returning it as the result of the function.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
Delphi: Multiline Caption for TLabel (at Run Time and Design Time)
Tutorial | 1 Comment
Delphi/Lazarus: How to set up a Link to a Website in an Application
Tutorial | 0 Comments
Delphi: System-Wide HotKey
Tutorial | 1 Comment
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
VirtualBox: Change Date and Time
Tutorial | 10 Comments
Lazarus: Detect Operating System (Compiler Switch)
Tutorial | 0 Comments
Delphi: Event Order of a Form - From OnCreate to OnDestroy
Info | 1 Comment
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.