Solved

Check application main form focus

Posted on 2002-04-18
4
322 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 242
Delphi XE10, MySQL Query 4 167
Delphi: how to implement a User Shortcut mapper? 1 121
how to send memory stream from ics Client To ics server ? 11 139
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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