Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check application main form focus

Posted on 2002-04-18
4
Medium Priority
?
340 Views
Last Modified: 2010-04-04
I want to know if my main form is focused or there is another application focused.
I tried Form's Focused property, IsWindowShowing, etc, but I didn't get any result.

Motaz
0
Comment
Question by:Motaz
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
dMa earned 800 total points
ID: 6949826
check forst the windows api function getfocus
GetActiveWindow(VOID)
GetFocus(VOID)
0
 
LVL 17

Expert Comment

by:geobul
ID: 6949886
Hi,

procedure TForm1.Timer1Timer(Sender: TObject);
var
  h: HWND;
begin
  h := GetForegroundWindow;
  if IsWindow(h) then
    if Application.MainForm.Handle = h then
      Label1.Caption := 'Active'
    else Label1.Caption := 'Not active';
end;

Regards, Geo
0
 
LVL 7

Author Comment

by:Motaz
ID: 6949965
Thanks, that's exactly what I want.

   If GetActiveWindow = 0 then
      FlashWindow(Application.Handle, False);

Motaz
0
 
LVL 17

Expert Comment

by:geobul
ID: 6950114
The code you've chosen doesn't guarantee you that your main form has the focus. It could be any form belonging to your app.

On the other hand, my code does.

Regards, Geo
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question