Results 1 to 8 of 8

Thread: How do you get X and Y coordinates of a foreign application?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Hello everyone. I know how to get the X and Y coordinates of a foreign application, but like to know if there is any faster and easier method. Currently, I am using GetWindowRect.


    Thank You
    Chemically Formulated As:
    Dr. Nitro

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You can use ClienttoWindow API, but i'm not sure if it's faster in any way.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Hello Kedaman!

    Long time no talk to. Thank you for replying but there is no API call ClientToWindow. Do you mean ClientToScreen? I am going to play around with it now.
    Chemically Formulated As:
    Dr. Nitro

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    GetWindowRect or ClientToScreen

    Kedaman! This is very interesting. Try this code by stepping through it with F8. Make sure you step through it with F8. I got two different results for the X and Y.

    Drop it into a form that is not maximize during run time.
    Code:
    Option Explicit
    Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    
    Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long
    Private Type Rect
      Left As Long
      Top As Long
      Right As Long
      Bottom As Long
    End Type
    
    Private Sub Form_Click()
        Dim p_Positon As POINTAPI
        Call ClientToScreen(Me.hwnd, p_Positon)
        
        Dim r_Positon As Rect
        Call GetWindowRect(Me.hwnd, r_Positon)
        
        Call SetCursorPos(p_Positon.X, p_Positon.Y)
        Call SetCursorPos(r_Positon.Left, r_Positon.Top)
    End Sub
    Thanks for introducing a new API to me, Kedaman.
    Chemically Formulated As:
    Dr. Nitro

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Red face oh, i meant that

    Well, you use a pointapi to retrive the position
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    I am not quite sure what you mean, but I used both API to see the difference. The ClientToScreen uses a PointAPI to get the position. The GetWindowRect uses Rect to get Left and Top.
    Chemically Formulated As:
    Dr. Nitro

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    sorry, wrote that before you posted, such things happens to me all the time well, have fun with it
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb GetCursorPos API

    I think use the GetCursorPos API will do.

    Code:
    Option Explicit
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Private pt As POINTAPI
    
    Private Sub Command1_Click()
    Dim dl As Long
    Dim PosX As Long
    Dim PosY As Long
    
        dl = GetCursorPos(pt)
        PopX = ScaleX(pt.x, vbPixels, vbTwips)
        PopY = ScaleY(pt.y, vbPixels, vbTwips)
        Msgbox "Current Mouse Position is " & PopX & ", " & PopY
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width