How to steal focus on 2K/XP

You used to use SetForegroundWindow, but that only blinks your window now, this is because stealing focus is evil. It can be done and it’s evil.
You use the AttachThreadInput API call. The process is attach, focus, detach.

AttachThreadInput(GetWindowThreadProcessId(
GetForegroundWindow(), NULL),
GetCurrentThreadId(), TRUE);
SetForegroundWindow(hWnd);
AttachThreadInput(GetWindowThreadProcessId(
GetForegroundWindow(), NULL),
GetCurrentThreadId(), FALSE);

Again, this is doable, the problem is that it’s not good UI design as this will make your window focus even if your application wasn’t in the foreground, which as we all know is a no-no.

[Listening to: Purple Haze – Groove Armada – The Best of Groove Armada (4:03)]