|
-
Oct 31st, 2001, 04:36 PM
#1
Thread Starter
Hyperactive Member
(Resolved by Serge) Gurus - Em_CharFromPos
Is EM_CHARFROMPOS available in Windows 2000? I am using this code:
VB Code:
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_CHARFROMPOS& = &HD7
Public Type POINTAPI
x As Long
y As Long
End Type
Public Function WordUnderCursor(txtBox As TextBox, x As Single, y As Single) As String
Dim mPosAs POINTAPI
Dim cPos As Integer
mPos.x = x / Screen.TwipsPerPixelX
mPos.y = y / Screen.TwipsPerPixelY
cPos = SendMessage(txtBox.hWnd, EM_CHARFROMPOS, 0&, mPos)
etc.......
cPos is always returned as -1. Also I cannot find EM_CHARFROMPOS in the API Viewer.
Does anyone have any ideas?
TIA
-TiPeRa
Last edited by TiPeRa; Nov 9th, 2001 at 03:53 PM.
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Oct 31st, 2001, 04:38 PM
#2
PowerPoster
-
Oct 31st, 2001, 04:43 PM
#3
Thread Starter
Hyperactive Member
The code works for a RichTextBox, but I can't get it to work for a TextBox
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Oct 31st, 2001, 05:29 PM
#4
Thread Starter
Hyperactive Member
Hmmm...Well...
According to MSDN:
Edit controls: The low word of lParam contains the horizontal coordinate. The high word contains the vertical coordinate.
So I now have this:
VB Code:
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_CHARFROMPOS& = &HD7
Public Type POINTAPI
x As Long
y As Long
End Type
Public Function WordUnderCursor(txtBox As TextBox, x As Single, y As Single) As String
Dim mPosAs POINTAPI
Dim cPos As Integer
mPos.x = x / Screen.TwipsPerPixelX
mPos.y = y / Screen.TwipsPerPixelY
cPos = SendMessage(txtBox.hWnd, EM_CHARFROMPOS, 0&, LParam(pt.x, pt.y)
etc.......
End Function
Function LoWord(ByVal Num As Long) As Integer
If Num And &H8000& Then
LoWord = Num Or &HFFFF0000
Else
LoWord = Num And &HFFFF&
End If
End Function
Public Function LParam(wLow As Long, wHigh As Long) As Long
LParam = LoWord(wLow) Or (&H10000 * LoWord(wHigh))
End Function
But it still doesn't work
Please help me
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Oct 31st, 2001, 06:28 PM
#5
Thread Starter
Hyperactive Member
This sort of works:
VB Code:
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_CHARFROMPOS& = &HD7
Public Type POINTAPI
x As Long
y As Long
End Type
Public Function WordUnderCursor(txtBox As TextBox, x As Single, y As Single) As String
Dim mPosAs POINTAPI
Dim cPos As Integer
mPos.x = x / Screen.TwipsPerPixelX
mPos.y = y / Screen.TwipsPerPixelY
cPos = SendMessage(txtBox.hWnd, EM_CHARFROMPOS, 0&, [B]pt.x[/B] )
etc.......
End Function
But only for the top line
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Oct 31st, 2001, 06:29 PM
#6
PowerPoster
remind me what you're trying to do again...
-
Oct 31st, 2001, 06:42 PM
#7
Fanatic Member
yes please
It might be helpfull if you could describe what the goal is of the procedure
-
Nov 1st, 2001, 04:32 AM
#8
Thread Starter
Hyperactive Member
I am trying to get the character that appears underneath the cursor, the code at the top works for RichTexBoxes but not TextBoxes.
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Nov 7th, 2001, 09:10 AM
#9
-
Nov 9th, 2001, 02:05 PM
#10
Thread Starter
Hyperactive Member
-
Nov 9th, 2001, 03:20 PM
#11
Well, if you have a multilined textbox, then its fairly simple to make it to work with that:
VB Code:
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 Type POINTL
x As Long
y As Long
End Type
Private Const EM_CHARFROMPOS = &HD7
Function MakeDWord(LOWORD As Integer, HIWORD As Integer) As Long
MakeDWord = (HIWORD * &H10000) Or (LOWORD And &HFFFF&)
End Function
Function LOWORD(DWord As Long) As Integer
If DWord And &H8000& Then
LOWORD = DWord Or &HFFFF0000
Else
LOWORD = DWord And &HFFFF&
End If
End Function
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim pt As POINTL
Dim lngRet As Long
Dim lngVal As Long
pt.x = x / Screen.TwipsPerPixelX
pt.y = y / Screen.TwipsPerPixelY
lngVal = MakeDWord(CInt(pt.x), CInt(pt.y))
lngRet = SendMessage(Text1.hwnd, EM_CHARFROMPOS, 0&, ByVal lngVal)
lngRet = LOWORD(lngRet)
Label1.Caption = lngRet
End Sub
-
Nov 9th, 2001, 03:51 PM
#12
Thread Starter
Hyperactive Member
You are a GOD.
145 views and one correct answer, yours.
Thankyou, thankyou, thankyou.
I have finally been able tp track down the bug in MY code:
VB Code:
cPos = SendMessage(txtBox.hWnd, EM_CHARFROMPOS, 0&, LParam(pt.x, pt.y)
should be:
VB Code:
cPos = SendMessage(txtBox.hWnd, EM_CHARFROMPOS, 0&, [b]ByVal[/b] LParam(pt.x, pt.y)
Thankyou again.
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Nov 9th, 2001, 04:02 PM
#13
You're welcome.
It's amazing how exiting people get when they get something resolved.
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
|