Results 1 to 4 of 4

Thread: Cannot get EM_CHARFROMPOS to work with TextBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Sweden
    Posts
    8

    Unhappy Cannot get EM_CHARFROMPOS to work with TextBox

    I'm so tired.

    really.

    To get the character nearest to the mouse pointer, in my RichTextBox, I send the EM_CHARFROMPOS message.

    It works just fine.

    But when I try to do the same thing in my TextBox, it doesn't matter how much I yell or cry or change LPARAM's value... it just won't give me anything else then 0 in return.

    Help?

    Anyone?
    ---
    This life is killing me
    ---

  2. #2
    Megatron
    Guest
    The LoWord of the return value is the x pos and the HiWord is the y pos.

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Add Textbox and a Label:
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    2. Private Type POINTL
    3.         x As Long
    4.         y As Long
    5. End Type
    6. Private Const EM_CHARFROMPOS = &HD7
    7.  
    8. Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    9.     Dim pt As POINTL
    10.     Dim lngRet As Long
    11.    
    12.     pt.x = x / Screen.TwipsPerPixelX
    13.     pt.y = y / Screen.TwipsPerPixelY
    14.    
    15.     lngRet = SendMessage(Text1.hwnd, EM_CHARFROMPOS, ByVal 0&, ByVal pt.x)
    16.     Label1.Caption = lngRet
    17. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Sweden
    Posts
    8

    EM_CHARFROMPOS=WM_USER + 39 won't work with TextBox (Resolved)

    Thanks!
    Apperently the EM_CHARFROMPOS constant I used with my RichTextBox wasn't valid for the TextBox

    Works only with RTB:
    Private Const WM_USER=&H400
    Private Const EM_CHARFROMPOS=WM_USER + 39

    Works with both RTB & TextBox
    Private Const EM_CHARFROMPOS=&HD7
    ---
    This life is killing me
    ---

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