Click to See Complete Forum and Search --> : Hooking onto a console window


Macgoober
July 1st, 2009, 02:44 AM
In general, I'm coding an external program with Ruby and would like to issue some API commands, but I'm afraid this is where Ruby becomes limited in its ability.

I want to have the console window set to be "Always on Top" in a sense. So how would I go about hooking onto a console and bring it to the top with C++ and Window's API?

I'm running into confusion with SetWindowPos() and SetForegroundWindow()

Any help/advice is much appreciated

Thanks,

- Mac

olivthill2
July 1st, 2009, 06:04 AM
See MSDN description of SetWindowPos() function at http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx , where it is said:
If an application is not in the foreground, and should be in the foreground, it must call the SetForegroundWindow function.
My understanding is that there are two z-orders: one for the display, and another one (not named "z-order" in the manuals) for the keyboard and events.

SetWindowsPos() changes the z-order for the screen.
SetForegroundWindow() changes both the z-order for the screen and for the keyboard.