Click to See Complete Forum and Search --> : Bring window to top/foreground
Kelvin
May 3rd, 1999, 10:38 PM
Please help!
I can restore a minimized window by calling ShowWindow(SW_SHOWNORMAL), but i just can't
bring a window from the back to foreground. I tried using pFirstWnd->BringWindowToTop(), also tried using
SetActiveWindow(), pFirstWnd->GetLastActivePopup(); etc etc....but non of it seemed to be working,
what is wrong with it??
eric33
May 4th, 1999, 01:35 AM
Normally BringWindowToTop must work.
This function do not change the window style to pass the window as a top level window.
You can try the method SetWindowPos
SetWindowPos(wndTop,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
Jason Teagle
May 4th, 1999, 02:38 AM
The most likely thing I can think of is that somewhere in your code, when the window is activated it immediately passes the focus on to another window, even though you may not have intended that; it would then look like it never gets the focus (= comes to the top). Is it always the same window that appears on top when you try this (that might be the window your code keeps passing focus to)?
Try overriding the OnKillFocus() method of one of the controls on the window you are trying to activate (or override OnActivateView() if it is a CView-derivative), and see if you can tell where the focus is going to.
Ashley Antony
May 4th, 1999, 03:32 AM
When Windows starts one thread will start running called “RIT – Raw Input thread”. It is this thread which accepts keyboard and mouse inputs from the user and redirects it to appropriate thread’s Virtualized Input Queue(VIQ). For a mouse event RIT determines which window is under the mouse cursor and then places the mouse event in the VIQ associated with the thread which created the window. For keystroke events, RIT determines which thread is currently running and keyboard event will be placed in that thread’s VIQ. VIQ will decide to which of the windows(assuming that thread got the ownership of more than one window) the keystroke is meant to be.
SetFocus()/SetActiveWindow behavior:
Suppose you got two threads, each owning 3 windows each. Thread 1 is connected to RIT.
Thread 2 is calling SetFocus to any of its windows. This call won’t do anything because the thread which called the API is not connected to RIT.
But if thread 1 had called SetFocus/SetAct..()with any of thread 1 windows focus would have changed.
Now if thread 1 is calling the same with a handle of the window owned to thread 2, thread 2 ‘s local input state variables(like showing a caret if it is a text box) will be changed to reflex the changes and that particular window will receive the keystrokes when RIT is next connected to thread 2. The call won’t make RIT to direct inputs to thread 2’s VIQ. It should be connected by some other way, after connecting focus will be with the window you called SetFocus.
BringWindowToTop() behavior:
If the API was called by a thread which is the foreground thread the result will be as you expected. But if your thread was in background while calling this, nothing will happen.
The easiest API for your purpose is nothing but “SetForegroundWindow()”.
If this doesn’t suffice your query please ask me,
Best Regards,
Ashley Antony Elenjickal
Ashley.Antony@in.bosch.com
Robert Bosch India Ltd
Bangalore 95.
India.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.