Solved

Check application main form focus

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now