Results 1 to 8 of 8

Thread: Want to know where is text cursor..?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    india
    Posts
    63

    Want to know where is text cursor..?

    HELLO EVERBODY,
    I want to know how can I find where is the text cursor at any time even outside my application anywhere in windows.
    For instance, Say when I was writing this message I saw two cursors. One for mouse. Other at a place where I was writing this message. I wanna know info may be handle, classname of control and application where currently it is?

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    You can find the mouse Mouse cursors x,y values by by calling the GetCursorPos API

    VB Code:
    1. Type PointApi
    2.    X as long
    3.    Y as long
    4. End Type
    5.  
    6. Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
    7.  
    8. Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long


    but i dont know how to get information about the text cursor if that was what u were asking about
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    I think you're actually looking for the caret. I don't know how to do what you're looking for, but maybe using "caret" in your search will help you out.
    Please rate my post.

  4. #4
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    Each thread can have it's own caret and only one window in that thread will have the active CARET.

    VB Code:
    1. Private Type RECT
    2.     Left As Long
    3.     Top As Long
    4.     Right As Long
    5.     Bottom As Long
    6. End Type
    7.  
    8. Private Type GUITHREADINFO
    9.     cbSize As Long
    10.     flags As Long
    11.     hWndActive As Long
    12.     hwndFocus As Long
    13.     hwndCapture As Long
    14.     hwndMenuOwner As Long
    15.     hwndMoveSize As Long
    16.     hwndCaret As Long
    17.     rcCaret As RECT
    18. End Type
    19.  
    20. Private Declare Function GetGUIThreadInfo Lib "user32" (ByVal hThreadId As Long, pGuiThreadInfo As GUITHREADINFO) As Long
    21.  
    22. Private Declare Function GetCurrentThread Lib "kernel32" () As Long
    23.  
    24. Public Function GetActiveCaretHwnd() As Long
    25.  
    26. Dim gti As GUITHREADINFO
    27.  
    28. If GetGUIThreadInfo(GetCurrentThread(), gti) Then
    29.    GetActiveCaretHwnd = gti.hwndCaret
    30. End If
    31.  
    32. End Function
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  5. #5
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    What about getting its position in a textbox?
    Please rate my post.

  6. #6
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    If the textbox is in your app. then use the SelStart property - otherwise use Sendmessage and send it a EM_GETSEL message...search MSDN for info on this message...
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  7. #7
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Got it - thanks.
    Please rate my post.

  8. #8
    Fanatic Member alexandros's Avatar
    Join Date
    Oct 2002
    Location
    Milky Way Galaxy
    Posts
    694
    you may want to try the GetCaretPos function.
    it is very unknown but i use it and it works fine !
    it gives you the position of the caret in points. the position on the screen ! not the character index within the editbox.
    note that you have to change the points to pixels or twips afterwards if you want to make better use of this.

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