Windows Develop Bookmark and Share   
 index > Windows Forms General > Bring another application to front.
 

Bring another application to front.

I have searched this forum, and many sites before. And somehow I couldn't find the correct answer.

The codes I find do not work for me.

And my problem is:

I would like to bring to front/focus an application, that's already running.

For example, notepad, I saw they usually pick it for tutorials like this.

And my situation: I have my form opened, and now I'd like to bring notepad to front.

If someone could stick the code for the example with notepad?

Any help appreciated.

Thank you

ex-Ath  Friday, January 30, 2009 3:24 PM
Since you are using Visual Basic, there is also the possiblity of calling AppActivate instead of using P/Invoke.

http://msdn.microsoft.com/en-us/library/dyz95fhy.aspx
  • Marked As Answer byex-Ath Sunday, February 01, 2009 1:54 PM
  •  
BinaryCoder  Saturday, January 31, 2009 7:38 PM
All you need is to call this,if you are using VB.Net

AppActivate("Untitled - Notepad")

This will set the running notepad application as foreground window.

If you are using other laguages then you will have to call the win32 API's ,FindWindow() and SetForeGroundWindow() through Platform invoke.

P/Invoke Implementation:
since i am not familiar with C# iam showing this code using vb.

'Declare the Win32 API's


Declare Auto Function FindWindow Lib "User32.dll" (ByVal lpClassName As String,ByVal lpWindowName As String) As IntPtr

Declare Auto Funtion SetForeGroundWindow Lib "User32.dll"(ByVal Hwnd As IntPtr) As Long

'Call these API's through your code

Dim Handle as IntPtr = FindWindow(Nothing,"Untitled - Notepad")

SetForeGroundWindow(Handle)
  • Marked As Answer byex-Ath Sunday, February 01, 2009 1:54 PM
  • Edited by_asgar Sunday, February 01, 2009 7:24 AMaddl
  •  
_asgar  Sunday, February 01, 2009 6:57 AM

Dimpsi As New ProcessStartInfo("notepad.exe")
psi.WindowStyle = ProcessWindowStyle.Maximized
Dimproc As Process = Process.Start(psi)

Dont have the time to do more but try getting the window handle or use the processID.....


printf("Love");
eBlackman  Friday, January 30, 2009 5:52 PM
I can't. Just can not make it work.

The process is already started..
ex-Ath  Saturday, January 31, 2009 3:52 PM
You'll need to P/Invoke SetForegroundWindow(). Visit pinvoke.net for the required declaration.
Hans Passant.
nobugz  Saturday, January 31, 2009 4:04 PM
Since you are using Visual Basic, there is also the possiblity of calling AppActivate instead of using P/Invoke.

http://msdn.microsoft.com/en-us/library/dyz95fhy.aspx
  • Marked As Answer byex-Ath Sunday, February 01, 2009 1:54 PM
  •  
BinaryCoder  Saturday, January 31, 2009 7:38 PM
All you need is to call this,if you are using VB.Net

AppActivate("Untitled - Notepad")

This will set the running notepad application as foreground window.

If you are using other laguages then you will have to call the win32 API's ,FindWindow() and SetForeGroundWindow() through Platform invoke.

P/Invoke Implementation:
since i am not familiar with C# iam showing this code using vb.

'Declare the Win32 API's


Declare Auto Function FindWindow Lib "User32.dll" (ByVal lpClassName As String,ByVal lpWindowName As String) As IntPtr

Declare Auto Funtion SetForeGroundWindow Lib "User32.dll"(ByVal Hwnd As IntPtr) As Long

'Call these API's through your code

Dim Handle as IntPtr = FindWindow(Nothing,"Untitled - Notepad")

SetForeGroundWindow(Handle)
  • Marked As Answer byex-Ath Sunday, February 01, 2009 1:54 PM
  • Edited by_asgar Sunday, February 01, 2009 7:24 AMaddl
  •  
_asgar  Sunday, February 01, 2009 6:57 AM
Woah, lifesavers!
I almost ate myself.

No for real, thanks for help.
Every thing's working fine.
ex-Ath  Sunday, February 01, 2009 1:55 PM

You can use google to search for other answers

Custom Search

More Threads

• Multiple video playback
• Calls to OnPaint() - WinForms
• sharing values between a form and a class
• How to access to MdiChild form variables..
• Resolving a relative/absolute path?
• COM Experts Help! on Com Exception
• Problem with GraphicsPath.IsVisible()
• multiple tables in datagrid - update statement
• How can add an image as a property in a custom userControl ,store and retrieve property dynamically
• Word 2003