[Tutor] Setting the focus to a window

Alan Gauld alan.gauld at freenet.co.uk
Mon Jan 17 00:13:28 CET 2005


> me in the past 2 days or so), I need to change the focus from the
> current window to another window (from Windows Media Player to
Audacity
> so that the simulated keypress will have an effect).

There are a couple of options and its a wee while since I did
any deep windows hacking. But I think the functions you need
are called something like GetActiveWindow(title), and
SetActiveWindow(handle). Theres also SetForegroundWindow...

One of the wacky things about Windows is that there are
usually about 3 ways to do anything and only one of them
actually works the way you expect so you have to
experiment a lot!

ISTR You can also GetDesktopWindow() and front that get all the
child windows which includes most of the running apps.

ie You can get the window handle(aka identifier) using the title
in the title bar, and then you make it the active window
using the handle.

However I believe the Windows PostMessage will actually
work from the handle directly. But you will need to check
the docs, thisis all from very olfd memories! The XP API
may even be very different to the Win95 that I used to
work on...

Alan G.



More information about the Tutor mailing list