Hi,
Try the following smaple:
1. Open a new project and place a Text1 textbox on it.
2. Make the Text1. Multiline=True
3. Copy the following code to Form1:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, wParam As Long, lParam As Any)
As Long
Private Const EM_POSFROMCHAR = &HD6
Private Sub Text1_Click()
Dim nX As Integer
Dim nY As Integer
Call GetCharPos(Text1.hWnd, Text1.SelStart, nX, nY)
Debug.Print "X = "; nX; " Y = "; nY
End Sub
Private Sub GetCharPos(ByVal hWnd As Long, ByVal lCharPos As Long, nX As
Integer, nY As Integer)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Returns the X and Y coordinates of the char at position'
'specified by lCharPos. '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'NOTE: nX and nY coordinates are in pixels. '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INPUT: '
' lCharPos - long, 0-based index of character in '
' an Edit or Rich Edit control. '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'OUTPUT: '
' nX - integer, X coordinate, in pixels of the '
' char. '
' nY - integer, Y coordinate, in pixels of the '
' char. '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim lRetVal As Long
Dim lPos As Long
Dim lParam As Long
lPos = lCharPos
lRetVal = SendMessage(hWnd, EM_POSFROMCHAR, ByVal lPos, ByVal
lParam)
nX = lRetVal And &HFFFF&
nY = (lRetVal \ &H10000) And &HFFFF
End Sub
4. Run the project and paste some text in the Textbox and then click
somewhere over the text.
X and Y coordinates in pixels will be printed in the Debug window.
Regards,
Stoil
Quote:
> How to get the current Char position in pixel?
> I dont know which messages should I send to it and how to do.