
RichTextBox and Millimeter
have a stab at it with this...
Drop a textbox on the form to run the code un-alterd..
TextBox1
And of Course, a RichTextBox
RichText1
Code is adapted form the Hyperlink example at
http://www.vb-world.net/demos/hyperlink/CHyperlinks.cls.html
D.
Option Explicit
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
Private Const EM_GETLINE = &HC4
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINEINDEX = &HBB
Private Const MAXLINELENGTH = 512
Public Sub CalcSpot()
Dim strLine As String
Dim lngLine As Long
Dim lngLineIndex As Long
Dim lngSelStart As Long
Dim lngHWnd As Long
Dim bLine(MAXLINELENGTH - 1) As Byte
Dim i As Integer, iPos As Integer
Dim WhichMode As Integer
lngHWnd = RichTextBox1.hwnd
lngSelStart = RichTextBox1.SelStart
'Get the line number we're on
lngLine = SendMessage(lngHWnd, EM_LINEFROMCHAR, lngSelStart, 0&)
lngLineIndex = SendMessage(lngHWnd, EM_LINEINDEX, lngLine, 0&)
lngSelStart = lngSelStart - lngLineIndex
bLine(0) = MAXLINELENGTH And 255
bLine(1) = MAXLINELENGTH \ 256
'get the line and save it in the byte array
SendMessage lngHWnd, EM_GETLINE, lngLine, bLine(0)
For i = 0 To MAXLINELENGTH - 1
If bLine(i) = 0 Then
Exit For
End If
strLine = strLine & Chr$(bLine(i))
Next
WhichMode = vbMillimeters
'WhichMode = vbInches
Text1.Text = ScaleX(TextWidth(Mid$(strLine, 1, lngSelStart)),
Me.ScaleMode, WhichMode)
End Sub
Private Sub RichTextBox1_SelChange()
CalcSpot
End Sub
Quote:
> I'm using a richtextbox control as core for our own tiny
> word processor that we plan to include in our application.
> Is there a way to determine in millimeter or in twips the
> position of the pointed character versus the size of the
> richtext box itself ?
> Best regards
> Jean-Claude