Solved

Another program location

Posted on 2013-11-07
2
253 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
[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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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