Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3937346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:03:29+00:00 2026-05-20T00:03:29+00:00

In Delphi XE, I’m trying to use GetForegroundWindow to detect the window that was

  • 0

In Delphi XE, I’m trying to use GetForegroundWindow to detect the window that was active immediately before my application was activated. “Activated” means that the app may have been restored from iconic state, or it was switched to via alt+tab, or brought up by activaton hotkey, etc.

The problem is that all the available application events (OnActivate, OnRestore) come too late, so that GetForegroundWindow returns my own form’s handle. The main form’s events are even less useful. Processing WM_ACTIVATEAPP in the main form happens too late, too.

One way would be to keep checking the active window on timer while my application is not active, but this seems rather wasteful. A much better solution would be to subclass TApplication.WndProc and do my thing before WM_ACTIVATEAPP is processed, but I don’t think TApplication can be subclassed.

Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:03:30+00:00Added an answer on May 20, 2026 at 12:03 am

    When your application activates, it becomes the topmost window. IOW, it jumps to the top Z-order position.

    With this, previous topmost window is demoted to the “just below the new topmost window” position. IOW, it becomes second in the Z-order position.

    Calling GetNextWindow and passing it the handle of your form and GW_HWNDNEXT may give you just the result you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Delphi 7 SQLSERVER 2000 I am having a problem with a legacy application that
Delphi 2010, dbExpress, and SQL Server 2005 DB I am trying to make a
Delphi 2010 Windows 7 - 64 bit. I have an app which is reasonably
Delphi XE2, so I guess that is Indy 10(?). One server, 10 clients. I
Delphi 2010, Win32 VCL. I need to create a main menu for my application
Delphi TScreen object has a collection that accepts IME names. And the TControl offers
Delphi 2009 and above support unicode. I have few legacy pascal source files that
Delphi documentation says that Debug information [...] it does not affect the size or
Delphi does not use *nix timestamps. In other apps I have converted to *nix
Using Delphi 2009 on Windows XP to develop desktop application. Is there any way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.