Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bring external application window to front

Posted on 2004-09-01
7
Medium Priority
?
1,791 Views
Last Modified: 2010-04-23
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?
0
Comment
Question by:dudinatrix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11953483
you could use the shell function this has the possibility to do that

Shell("notepad.exe", AppWinStyle.MaximizedFocus)
0
 

Author Comment

by:dudinatrix
ID: 11953654
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
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11953667
Sorry, I see you need to it multiple times. So you need the setforegroundwindow API. I'll have a look
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 252 total points
ID: 11953704
0
 
LVL 4

Assisted Solution

by:Javert93
Javert93 earned 248 total points
ID: 11968089
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question