Solved

Another program location

Posted on 2013-11-07
2
251 Views
Last Modified: 2013-11-07
I need to get the screen Top and Left position of another application.  
Example:
How could I get the Top and Left position of NotePad.exe from My Application.

Please give example code.

Thanks in advance for your help.
0
Comment
Question by:PhilChapmanJr
2 Comments
 
LVL 8

Accepted Solution

by:
5teveo earned 500 total points
ID: 39630729
Use these declarations

    Public Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure

    Dim tWnd As Long

    Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

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

    Public Overloads Declare Function GetWindowRect Lib "User32" Alias "GetWindowRect" (ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Int32
.
.
.
then code this into a button to test logic of finding a NOTEPAD window with label of
"Untitled - Notepad"

   Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim R As RECT
        For Each p As Process In Process.GetProcesses
            If InStr(p.MainWindowTitle, "Untitled - Notepad") > 0 Then
                'SetForegroundWindow(p.MainWindowHandle)
                GetWindowRect(p.MainWindowHandle, R)

                MsgBox("Top=" & R.Top.ToString & vbCrLf & _
                       "LEFT=" & R.Left.ToString & vbCrLf & _
                       "bottom=" & R.Bottom.ToString & vbCrLf & _
                       "right=" & R.Right.ToString)
                Exit For
            End If
        Next

    End Sub

good luck!
0
 
LVL 2

Author Closing Comment

by:PhilChapmanJr
ID: 39631197
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now