Results 1 to 5 of 5

Thread: Getting Caret's Position

  1. #1

    Thread Starter
    Member Eikon's Avatar
    Join Date
    Jan 2001
    Posts
    33

    Getting Caret's Position

    Using the win32 API calls GetCaretPos and ClientToScreen with a POINTAPI structure is not returning the right values for the screen posistion of the caret. It also only updates when the window is moved.... heres the code:

    GetCaretPos Pt
    ClientToScreen hWnd, Pt
    Text1.Text = Pt.X ' Update
    Text2.Text = Pt.Y

    What am I doing wrong? I need screen coords, not client.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You need to pass the handle to the window containing the caret, not the form, i.e.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type POINTAPI
    4.         x As Long
    5.         y As Long
    6. End Type
    7.  
    8. Private Declare Function GetCaretPos Lib "user32" (lpPoint As POINTAPI) As Long
    9. Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    10.  
    11. Private Sub Form_Load()
    12.   Timer1.Interval = 100
    13.   Timer1.Enabled = True
    14. End Sub
    15.  
    16. Private Sub Form_Unload(Cancel As Integer)
    17.   Timer1.Enabled = False
    18. End Sub
    19.  
    20. Private Sub Timer1_Timer()
    21.   Dim tPOINT As POINTAPI
    22.  
    23.   Call GetCaretPos(tPOINT)
    24.   Call ClientToScreen(Text1.hwnd, tPOINT)
    25.  
    26.   Caption = "X: " & tPOINT.x & " - Y:" & tPOINT.y
    27. End Sub

  3. #3

    Thread Starter
    Member Eikon's Avatar
    Join Date
    Jan 2001
    Posts
    33
    Thx, ill try that out.

  4. #4

    Thread Starter
    Member Eikon's Avatar
    Join Date
    Jan 2001
    Posts
    33
    I need to be able to get the caret position from other apps. How could I go about getting the handles for each child window in an app? I need help using the EnumChildWindows API call.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    What about the FindWindow / FindWindowEx API calls?

    s.

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