Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How Can I Activate an App from Another App and Send Key Strokes

Posted on 2006-04-21
3
Medium Priority
?
316 Views
Last Modified: 2012-08-13
I have 2 separate applications running. From One application I need to activate (bring to front) the other application and send some keyboard keys to simulate the used pressing those keys.
The application that will activate the other is on VB.NET VS2005
0
Comment
Question by:ofern01
3 Comments
 
LVL 6

Accepted Solution

by:
JRossi1 earned 1000 total points
ID: 16507825
To activate another app:  store the window handle of the other application and then use BringWindowToTop to activate the app.

Also, look at this:  http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21112857.html#11941064
0
 
LVL 1

Author Comment

by:ofern01
ID: 16507977
I do not call the other app from my VB program. It is already running when I exec my App. So i will need a way to find that handle from my VB program.
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 1000 total points
ID: 16507989
You can use code like this to get a handle to the other apps window and Send keystrokes:

    Private Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hWnd As IntPtr) As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ps() As Process = Process.GetProcessesByName("notepad")
        If ps.Length > 0 Then
            Dim p As Process = ps(0)
            Dim hWnd As IntPtr = p.MainWindowHandle
            SetForegroundWindow(hWnd)
            SendKeys.Send("Hello World!")
        End If
    End Sub

Notice that in GetProcessesByName(), we pass in the name of the Exectuable without any path and without the ".exe" extension.
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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

810 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