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 690689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:27:44+00:00 2026-05-14T02:27:44+00:00

My application uses multiple windows I want to hide one specific window in case

  • 0

My application uses multiple windows

I want to hide one specific window in case the application loses focus (when the Active Window is not the application window) source

I am handling the Deactivate event of my main form.

    private void MainForm_Deactivate(object sender, EventArgs e) 
    {
      Console.WriteLine("deactivate");
      if (GetActiveWindow() == this.Handle) 
      {
        Console.WriteLine("isactive=true");
      }
      else
      {
        Console.WriteLine("isactive=false");
      }
    }

[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();

The output is always

deactivate
isactive=true

I have observed the same behavior if a new window within my application receives focus and also if I click into a different application.

I would expect GetActiveWindow to return the handle of the new active window when called from the Deactivate handler. Instead it always returns the handle of my application window.

How is this possible? Is the Deactivate event handled “too soon”? (while the main form is still active?).

How can I detect that my application has lost focus (my application window is not the active window) and another application gained it without running GetActiveWindow on a timer?

  • 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-14T02:27:44+00:00Added an answer on May 14, 2026 at 2:27 am

    From what I can see GetActiveWindow get’s the active window for the calling thread, i.e. your app so it’s always going to return the current window of your app. I think perhaps you are looking for GetForegroundWindow which will return the handle to the window the user currently has active.

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

Sidebar

Related Questions

I'm building a large Java application that uses multiple pop-up windows. Some of these
My application uses multiple threads with one managed object context per thread. For clarity
I'm developing an AIR application which uses multiple windows. I'm running into an issue
I've a .Net 3.5 windows application.One of the modules uses a Oracle stored proc
I have a Winforms application that uses show multiple top-level windows: Form1 form1 =
I have an application that uses multiple WebViews. Nowhere do I set the priority
I'm working on an application that uses multiple threads to process its data. The
My application uses a MapView which will display multiple places. I have the latitude
I have a Windows Mobile application written in Java that uses AWT for the
I have an unmanaged Win32 C++ application that uses multiple C++ DLLs. The DLLs

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.