Try using the SetForegroundWindow function.
However, keep in mind that there are limitations to this that are explained in the note sections on the MSDN page, and I copied it here.
The system limits which processes can set the foreground window. a process can set a foreground window only if one of the following conditions is true:
- A process is a foreground process. The process was started by the foreground process.
- The process received the last input event.
- There is no foreground process.
- The foreground process is being debugged.
- The foreground is not locked (see LockSetForegroundWindow).
- The foreground lock timed out (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
- There is no menu.
An application cannot force a window to the forefront while a user is working with another window. Instead, Windows flashes the taskbar to notify the user.
This means that if you do not own the current foreground process (which probably occurs when the user logs in), you cannot set a new foreground window.
There are several hacks (google SetForegroundWindow, and you will find them), but they are hacks, not a good idea - they allow the user to decide what is in the foreground! (also, as Raymond Chen explains in his blog here, hacks can often cause a program to freeze)
source share