
January 5th, 2006, 11:00 PM
|
|
Contributing User
|
|
Join Date: Jul 2004
Location: Brisbane Australia
Posts: 158
Time spent in forums: 18 h 36 m 42 sec
Reputation Power: 5
|
|
RichTextBox
Hey Guys, my first post in this forum (I think) ... :-)
the following function, tells me the position under the cursor (ie what line it is on) and the current character under the cursor ...
what I would like to be able to do is get the WORD under the cursor ... now I know that I have to search for the first chr(32) prior to the cursor position and the first chr(32) after the cursor position ... that way I get the word in between ... but, I have little if no idea about going backwards from the cursor position in a string to find the chr(32) ...
there are API calls through the function, and these work fine ... if needed I can post the declarations and type variables ... I didnt think they would be necessary here ..
See the line commented out as '// DWE
Code:
Private Sub rtbSyntax_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim P As POINTAPI, CurPos As Long, tmpChar As String
'On Error Resume Next
'Hide the Caret
'If ConcealCaret Then HideCaret rtbSyntax.hwnd
'Current position
P.x = x / Screen.TwipsPerPixelX
P.y = y / Screen.TwipsPerPixelY
'Use the API to discover the character number
CurPos = SendMessageP(Me.rtbSyntax.hwnd, EM_CHARFROMPOS, 0, P)
Form2.lblCharacterNumber.Caption = "Character Pos: " & CurPos
'The richtextbox will tell us the line number
Form2.lblLineNumber.Caption = "Line: " & rtbSyntax.GetLineFromChar(CurPos)
'What character is it?
tmpChar = Mid(rtbSyntax.Text, CurPos + 1, 1)
Form2.lblCharacter.Caption = "Character: " & IIf(tmpChar = vbCr, "vbCr", tmpChar)
'// DWE
' Form2.lblWord.Caption = "Word: " & WordUnderCursor
If CBool(Form2.ChCaret.Value) Then
'move the Caret as required
rtbSyntax.SetFocus
rtbSyntax.SelStart = CurPos
End If
If CBool(Form2.ChSelectCharacter.Value) Then
'Select the character
rtbSyntax.SetFocus
rtbSyntax.SelStart = CurPos
rtbSyntax.SelLength = 1
End If
End Sub
MTIA
Darrin
Last edited by dwe : January 5th, 2006 at 11:04 PM.
|