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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:13:02+00:00 2026-06-09T03:13:02+00:00

I work eg. in Firefox, and my C#.NET app brings its window to the

  • 0

I work eg. in Firefox, and my C#.NET app brings its window to the front. That’s ok, but when I use SendToBack() to hide the form, it doesn’t activate Firefox’s window, so altough Firefox is in the foreground, I have to click into the window to be able to scroll, etc. How can I activate the previously focused window in C#?

i have tried these:

[DllImport("User32")]
private static extern int SetForegroundWindow(IntPtr hwnd);

[DllImport("user32.dll")]
static extern bool AllowSetForegroundWindow(int dwProcessId);

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

[...]

AllowSetForegroundWindow(System.Diagnostics.Process.GetCurrentProcess().Id);
SendToBack();
SetForegroundWindow(GetForegroundWindow());

I hoped that after sending my window back, the previous one will be returned by GetForegroundWindow, but it doesn’t work.

Secondly, I’ve tried to override WndProc, and handle the WM_ACTIVATE message to get the previous window from lParam, but it doesn’t work either if I use SetForegroundWindow() with this handle.

protected override void WndProc(ref Message msg) {
        if (msg.Msg == 0x0006) {
            prevWindow = msg.LParam;
        }
        base.WndProc(ref msg);
}

[...]

SetForegroundWindow(prevWindow);
  • 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-06-09T03:13:04+00:00Added an answer on June 9, 2026 at 3:13 am

    did you try the SetActiveWindow function? Its separate from the SetForgroundWindow function, although it seems that you may need to use them both.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms646311%28v=vs.85%29.aspx

    There is also a SetFocus function which sounds like it could work.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms646312%28v=vs.85%29.aspx

    Update

    To get the current Active Window, I would fire off the GetActiveWindow function before moving your application to the front of the stack, that way you have the handle for the window that was active before hand.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms646292%28v=vs.85%29.aspx

    Another Update
    I did a bit more digging around on the site and came up with the following three links, which might work better. The keyboard input functions seem to be dependent on the Window you are trying to set being part of the calling threads message queue, which since we are dealing with two separate application threads, is likely to not be the case.

    GetGUIThreadInfo Get the threads information, including active window

    GUITHREADINFO The GUITHREADINFO structure

    SwitchToThisWindow Another method of window changing

    All of these are in the same method stack as the SetForegroundWindow method, which seems to make them more likely to do what you are attempting.

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

Sidebar

Related Questions

Firefox recently blacklisted the plugin that allows xbaps to work in firefox This is
Hi all Why this piece of javascript code doesn't work on firefox var nfiles
Can someone tell me please why the following example work in Firefox but not
The last log in the following code doesn't work in Firefox. Why? (function() {
Why doesn't following code work correctly in FireFox 3.6? I have tested in IE7,
This works perfectly in Firefox but doesnt work in ie i get the following
I'm using Firefox and I've been reading some forums claiming this doesn't work in
In my asp.net web app, I create a popup window with a button. When
This seems to work fine in Firefox but, in IE8 specifically (it may work
Text Scrolling doesn't work in firefox (In IE it does). Markup + javascript: <!DOCTYPE

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.