Bring external application window to front

I'm launching an external application from my VB.net app using the Process.Start() function.  I need a way to bring that window to the front in order to send keys to it at various times throughout my VB.net app.

Any thoughts?
dudinatrixAsked:
Who is Participating?
 
RonaldBiemansCommented:
0
 
RonaldBiemansCommented:
you could use the shell function this has the possibility to do that

Shell("notepad.exe", AppWinStyle.MaximizedFocus)
0
 
dudinatrixAuthor Commented:
As I understand it, the Process.Start() function is the new, perferred "replacement" of the Shell function, since it has more control over the launched application.

What you suggest brings the window to the front when it launches (the Process.Start() function can do the same), but that isn't my issue.

I need to bring the external application to the front later, AFTER it loses focus.  I'll be switching between my VB.net application and my launched application, so it's important that I can bring it back to the front at any time, not just during the launch.
0
 
RonaldBiemansCommented:
Sorry, I see you need to it multiple times. So you need the setforegroundwindow API. I'll have a look
0
 
Javert93Commented:
Add this declare statement to a module in your project:

    Public Declare Auto Function SetForegroundWindow Lib "user32.dll" (ByVal hWnd As IntPtr) As Boolean

You can then activate the application's main window like this (assuming "p" is reference to your process):

    SetForegroundWindow(p.MainWindowHandle)

This should activate your window whenever you want.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.