Activate/BringToFront/SetForegroundWindow/SwitchToThisWindow our application

Posted on 2009-07-15
Medium Priority
Last Modified: 2012-05-07
We have two application (A and B) sending "messages" to each other in A there is a button that send a message to the B application that can be minimized or behind the other. When B get this message the application should be bring to front and be activated. The current code was a SetForegroundWindow

We have tryed many solution/combination of solution and cannot find any working solution:
SetForegroundWindow / SetActiveWindow / SwitchToThisWindow ...
but can't find any combination that work on my dev machine or other machine. Sometime it simply didn't work, some other time it's blinking orange.

Anyone know how to do it?

Currently we cannot change any code in A but can fix in B with our entry point.
Question by:TelDig
  • 3
  • 2
  • 2
LVL 30

Expert Comment

ID: 24862910
Have you tried the SetFocus() command?
LVL 30

Expert Comment

ID: 24862936
This article (first section) has some good info also on making sure that the active thread is correct for the window you are calling.

LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 24863113
The "...some other time it's blinking orange" bit throws up a red flag for me.

This behaviour sounds like the "prevent applications from stealing focus" feature of the Operating System itself.  Instead of apps taking the focus, they instead blink either indefinitely or for a configured number of times in the taskbar.  These setttings are stored in the registry.  The easiest way to change these settings are through Microsofts Tweak UI utility.

Download the Tweak UI tools from Microsoft:

Or do it manually:
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Author Comment

ID: 24863282
Idle Mind:
It's effectively caused by the "prevent applications from stealing focus"
but is there a work around that will only affect my application?

I cannot change the registry and affect all other applications of all users! It should have a way to do it like the TaskManager does?

we are calling the activate from the UI thread (sound good)
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24863384
What would be the point of that feature if an application could easily exclude itself from the system wide setting?...it's supposed to put the USER back in control...not the programmer.   =\

Wish I had a better answer for you....

Author Closing Comment

ID: 31603924
Yah! But would be nice if at least a user can configure this behavior only for our applications instead of a system wide feature ;o)

Author Comment

ID: 24868540
It's still strange that my computer is working fine even it the 'ForegroundLockTimeout' is set to default values (0x30b40).
And setting to 0 in the test computer fix the issue ;o)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

597 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