Solved

Check application main form focus

Posted on 2002-04-18
4
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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