How to set focus to other process ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to allow single instance of my process.
I did found the other System.Diagnostics.Process as follow:
System.Diagnostics.Process currentProcess =
System.Diagnostics.Process.GetCurrentProcess();
// Get all instances of GciViewer running on the local machin.
System.Diagnostics.Process[] localByName =
System.Diagnostics.Process.GetProcessesByName("GciViewer");
foreach( System.Diagnostics.Process process in localByName )
{
if( currentProcess.Id != process.Id )
{
// TO DO: How to set the focus to the process !!
}
}

How can I set focus to other process?
 
Hello Sharon,

First, use Mutex with "Global\" pattern for single app instance
And SetForegroundWindow + MainWindowHandle API function (apply pinvoke) to
bring process on front

S> I need to allow single instance of my process.
S> I did found the other System.Diagnostics.Process as follow:
S> System.Diagnostics.Process currentProcess =
S> System.Diagnostics.Process.GetCurrentProcess();
S> // Get all instances of GciViewer running on the local machin.
S> System.Diagnostics.Process[] localByName =
S> System.Diagnostics.Process.GetProcessesByName("GciViewer");
S> foreach( System.Diagnostics.Process process in localByName )
S> {
S> if( currentProcess.Id != process.Id )
S> {
S> // TO DO: How to set the focus to the process !!
S> }
S> }
S> How can I set focus to other process?
S>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
I was hoping for C# API/code.

But if I must use the Win32 API; can I use the send SendMessage() with
WM_SETFOCUS ?

Can you post some sample code on how to set the focus to the other process?
 

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

Back
Top