|
-
Oct 3rd, 2000, 10:11 AM
#1
Thread Starter
Addicted Member
Hi,
Has anybody got any idea as to how I can find out the current X,Y positions of a cursor in a richtextbox.
Thanks in advance
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Oct 3rd, 2000, 10:43 AM
#2
Fanatic Member
Shaun,
I just tried this code, and it tells you how many characters from the beginning the cursor is currently sitting at, the value gets stored in Endselect.
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_GETSEL = &HB0
Private Sub Command1_Click()
Dim StartSelect, Endselect As Long
SendMessage RichTextBox1.hwnd, EM_GETSEL, StartSelect, Endselect
End Sub
Try it, see what you think...
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Oct 3rd, 2000, 11:07 AM
#3
Thread Starter
Addicted Member
Hi crispin,
Thanks for that, but it's not really what I'm looking for.
With your example, If the user selects a different font then, yes, the position in characters will stay the same but the cursor may be in a totally different place dependant on the font width.
I have tried using the GetCursorPos API without much success. It seems to be returning all sorts of different values! 
Has anyone else got any ideas on how to get the X,Y position of the cursor in a RichTextBox???
Thanks
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Oct 3rd, 2000, 11:45 AM
#4
Fanatic Member
Private Declare Function GetCaretPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Command1_Click()
Dim posX As POINTAPI
Dim iResult
iResult = GetCaretPos(posX)
MsgBox "X = " & posX.x & " Y = " & posX.y
End Sub
I think this works...(you are trying to get the flashing cursor position and not the mouse cursor position aren't you? - otherwise i'm barking up the wrong tree completely
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Oct 3rd, 2000, 11:48 AM
#5
Thread Starter
Addicted Member
That's the one 
Cheers for your help
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|