Click here to Skip to main content
15,904,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How do you bring an application to the front? Not a window of an application (SetWindowPos()), but the whole application?

I won't go into the why, but I have an app. with a dialog that opens a second dialog in a separate thread. I disable the calling dialog that starts this thread so that the thread acts more modal. When the dialog in the thread gets dismissed, I re-enable the calling dialog. What happens, though, is that the calling dialog's application doesn't have focus anymore. I want the calling dialog/application to have focus. I tried using SetWindowPos() but that doesn't work unless you use the wndTopMost flag. But I don't want it to be top most permanently (which is what happens), but just to maintain its focus.

Any ideas?

Thanks in advance
Posted
Updated 28-Apr-11 7:20am
v2

This is a combination of SetActiveWindows or BringWindowToTop with SetForegroundWindow.

—SA
 
Share this answer
 
v2
You could try ::BringWindowToTop(HWND hWnd).

See here: http://msdn.microsoft.com/en-us/library/ms632673%28v=vs.85%29.aspx[^]
 
Share this answer
 
Comments
Koolski 28-Apr-11 15:18pm    
Unfortunately this doesn't work--from the MSDN, "...BringWindowToTop does not make a window a top-level window."
Hans Dietrich 28-Apr-11 15:26pm    
Right, because you said "I don't want it to be top most permanently".

BringWindowToTop() will bring it to the top, without making it a top-most window. Did you try it?
Koolski 28-Apr-11 16:33pm    
Yes, I sure did, but it didn't work. Other applications are coming up in front of my original app.
Hans Dietrich 28-Apr-11 16:57pm    
I had a similar problem with an MFC app that used the Feature Pack ribbon stuff.

You may have to use SetWindowPos to make it top-most, redraw the window, and then call SetWindowPos again to make it non-top-most.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900