13 Votes

Delphi/Lazarus: Get Handle of focused Window

Question by Guest | 2016-01-18 at 18:46

Is it possible to determine the handle of the window that is currently active? I am talking about the window that has the focus at the moment and this window can also be the window of another application (not my own one). I am using the Windows operating system.

If possible, can someone give me an example code for that? I am really not good at all of this Windows API stuff.

ReplyPositiveNegative
Avatar
2Best Answer2 Votes

That is really not a problem, you have even a function for that purpose, you only have to know its name. The function is called GetForegroundWindow and here I have a small example for usage:

var
  AHandle: HWND;
begin
  AHandle := GetForegroundWindow; 
end;

This example stores the handle of the window that has the focus at present. If you are using Lazarus, do not forget to add the unit "Windows" to your "uses" section.
2016-01-18 at 21:43

ReplyPositive Negative
Reply

Related Topics

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.