Bringing a program to the front

T

Thore Berntsen

Does anyone know how I can check if a program is running, if the answer is
yes then bring it to the front, if no start it?

Thore Berntsen
 
S

Stelrad Doulton

to find out what is running you can pinvoke CreateToolhelp32Snapshot and
Process32First and Process32Next
 
S

Sergey Bogdanov

There are different approaches for this. One of this method is use
FindWindow, SetForegroundWindow:

// in the main function
IntPtr nWnd = FindWindow(null, "Main Window Title");

if(nWnd != IntPtr.Zero)
{
SetForegroundWindow(nWnd);
Application.Exit();
}

....

[DllImport("coredll",EntryPoint="FindWindow")]
private static extern IntPtr FindWindow(string className, string
windowName);

[DllImport("coredll",EntryPoint="SetForegroundWindow")]
private static extern bool SetForegroundWindow(IntPtr hWnd);




Best regards,
Sergey Bogdanov
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Desktop or device 2
Windows CE 4.2 Input panel 1
Formatting storage card 1
OpenNetCF for VS2005 4
Oracle Lite 1
Application that looses foucus 9
ThreadPool 1
DateTimePicker - Where is it? 3

Top