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

  • SEARCH
  • Home
  • 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 2009 has changed its string type to use 2 bytes to represent a
Delphi has a $WARN compiler directive that allows one to selectively enable or disable
Delphi strings use single quotes, for example ' a valid string '. How does
In Delphi, I want to be able to create an private object that's associated
Delphi (and probably a lot of other languages) has class helpers. These provide a
Delphi 2009, among some cool stuff, has also just got Anonymous methods. I've seen
Delphi 2009 introduced a hierarchical system for project options configuration, where you set base
Delphi 8 introduced Class Helpers for the purposes of mapping the VCL/RTL to the
Delphi sometimes adds {$R *.res} in front of the unit path in the .dpr
Does Delphi call inherited on overridden procedures if there is no explicit call in

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.