From: Jan Opitz on
Hello,

I am trying to get the character next to the mouseup position using pointapi
and sending CHARFROMPOS.
This works fine with a RichTextBox, but with with Morcillo's RichEdit pos is
0 whatever line I place the cursor.
Also, x and y are far from precise. Since I am processing double byte chars
I would not like to switch to
MS controls.

Any suggestions?

Jan


Declaration and main code:

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long
Public Type POINTAPI
x As Long
y As Long
End Type
Public Const EM_CHARFROMPOS& = &HD7

Private Function GetWord(rich1 As RichEdit, ByVal x&, ByVal y&) As String

MPointer.x = x \ Screen.TwipsPerPixelX
MPointer.y = y \ Screen.TwipsPerPixelY
Pos = SendMessage(rich1.hwnd, EM_CHARFROMPOS, 0&, (MPointer.x +
MPointer.y * &H10000))


From: mayayana on
The last parameter is a POINTAPI or PONIT
structure. You seem to be sending a numeric
value. Also, the offset is relative the the RTB.
If Eduardo Morcillo's RTB doesn't give you
those values then you have to calculate them.

The following is an example of getting the bottom
visible line by getting the character offset of the
first character in that line:

'-----------------------------------------

Dim R1 As RECT
Dim Pt1 As POINT
Dim LRet As Long, CPos As Long
'-- get the window rect.
LRet = SendMessageAny(hRTB, EM_GETRECT, 0&, R1)

'-- set up POINT to accord with bottom left-hand corner of RTB.
Pt1.X = 1
Pt1.Y = (R1.Bottom - R1.Top) - 1

'-- get character offset.
LRet = SendMessageAny(hRTB, EM_CHARFROMPOS, 0&, Pt1)

'-- returns bottom visible line number.
BottomLine = SendMessageLong(hRTB, EM_EXLINEFROMCHAR, 0&, LRet)

'-------------------------------------------

Note that the docs say EM_CHARFROMPOS returns the nearest
char. offset in the low word and the nearest line number in the
high word. That info. seems to be either outdated or just wrong.
As far as I can tell, the return value is just the char. offset.
(Which makes sense. If it were the low word then only 65000-odd
characters could be counted.)

> Hello,
>
> I am trying to get the character next to the mouseup position using
pointapi
> and sending CHARFROMPOS.
> This works fine with a RichTextBox, but with with Morcillo's RichEdit pos
is
> 0 whatever line I place the cursor.
> Also, x and y are far from precise. Since I am processing double byte
chars
> I would not like to switch to
> MS controls.
>
> Any suggestions?
>
> Jan
>
>
> Declaration and main code:
>
> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal
> hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
> Long
> Public Type POINTAPI
> x As Long
> y As Long
> End Type
> Public Const EM_CHARFROMPOS& = &HD7
>
> Private Function GetWord(rich1 As RichEdit, ByVal x&, ByVal y&) As String
>
> MPointer.x = x \ Screen.TwipsPerPixelX
> MPointer.y = y \ Screen.TwipsPerPixelY
> Pos = SendMessage(rich1.hwnd, EM_CHARFROMPOS, 0&, (MPointer.x +
> MPointer.y * &H10000))
>
>


From: Jan Opitz on
Thank you, this helped me a lot for clarification.

The problem with the calculation is that y
would vary with different fontsizes being used within the same
text. So I cannot find out easily in which line I am.
It is quite convenient to get the character position
with a RTB.
But I assume there is no other way that would make it easier to
find the line.

Regards

Jan




"mayayana" <mayaXXyana(a)rcXXn.com> schrieb im Newsbeitrag
news:uqWMpgWhJHA.1248(a)TK2MSFTNGP03.phx.gbl...
> The last parameter is a POINTAPI or PONIT
> structure. You seem to be sending a numeric
> value. Also, the offset is relative the the RTB.
> If Eduardo Morcillo's RTB doesn't give you
> those values then you have to calculate them.
>
> The following is an example of getting the bottom
> visible line by getting the character offset of the
> first character in that line:
>
> '-----------------------------------------
>
> Dim R1 As RECT
> Dim Pt1 As POINT
> Dim LRet As Long, CPos As Long
> '-- get the window rect.
> LRet = SendMessageAny(hRTB, EM_GETRECT, 0&, R1)
>
> '-- set up POINT to accord with bottom left-hand corner of RTB.
> Pt1.X = 1
> Pt1.Y = (R1.Bottom - R1.Top) - 1
>
> '-- get character offset.
> LRet = SendMessageAny(hRTB, EM_CHARFROMPOS, 0&, Pt1)
>
> '-- returns bottom visible line number.
> BottomLine = SendMessageLong(hRTB, EM_EXLINEFROMCHAR, 0&, LRet)
>
> '-------------------------------------------
>
> Note that the docs say EM_CHARFROMPOS returns the nearest
> char. offset in the low word and the nearest line number in the
> high word. That info. seems to be either outdated or just wrong.
> As far as I can tell, the return value is just the char. offset.
> (Which makes sense. If it were the low word then only 65000-odd
> characters could be counted.)
>
>> Hello,
>>
>> I am trying to get the character next to the mouseup position using
> pointapi
>> and sending CHARFROMPOS.
>> This works fine with a RichTextBox, but with with Morcillo's RichEdit pos
> is
>> 0 whatever line I place the cursor.
>> Also, x and y are far from precise. Since I am processing double byte
> chars
>> I would not like to switch to
>> MS controls.
>>
>> Any suggestions?
>>
>> Jan
>>
>>
>> Declaration and main code:
>>
>> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
> (ByVal
>> hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
>> Long
>> Public Type POINTAPI
>> x As Long
>> y As Long
>> End Type
>> Public Const EM_CHARFROMPOS& = &HD7
>>
>> Private Function GetWord(rich1 As RichEdit, ByVal x&, ByVal y&) As String
>>
>> MPointer.x = x \ Screen.TwipsPerPixelX
>> MPointer.y = y \ Screen.TwipsPerPixelY
>> Pos = SendMessage(rich1.hwnd, EM_CHARFROMPOS, 0&, (MPointer.x +
>> MPointer.y * &H10000))
>>
>>
>
>



From: mayayana on

> The problem with the calculation is that y
> would vary with different fontsizes being used within the same
> text. So I cannot find out easily in which line I am.
> It is quite convenient to get the character position
> with a RTB.
> But I assume there is no other way that would make it easier to
> find the line.
>

I don't understand. I thought that you wanted to know
what character offset is nearest where the mouse clicked.
Doesn't EM_CHARFROMPOS do that, regardless of font size?
Maybe you should explain what you're trying to accomplish.


From: "Bill McCarthy" TPASoft.com Are Identity on
Hi Jan,

If you are using the mouse up, unless you intervene, the selection has been
set. In which case you really only need to call EM_LINEFROMCHAR passing
in -1 as the wParam. That will give you the line index of the selection.



"Jan Opitz" <next1NO(a)SPAMgmx.de> wrote in message
news:ec80CHUhJHA.3444(a)TK2MSFTNGP03.phx.gbl...
> Hello,
>
> I am trying to get the character next to the mouseup position using
> pointapi and sending CHARFROMPOS.
> This works fine with a RichTextBox, but with with Morcillo's RichEdit pos
> is 0 whatever line I place the cursor.
> Also, x and y are far from precise. Since I am processing double byte
> chars I would not like to switch to
> MS controls.
>
> Any suggestions?
>
> Jan
>
>
> Declaration and main code:
>
> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
> (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
> Any) As Long
> Public Type POINTAPI
> x As Long
> y As Long
> End Type
> Public Const EM_CHARFROMPOS& = &HD7
>
> Private Function GetWord(rich1 As RichEdit, ByVal x&, ByVal y&) As String
>
> MPointer.x = x \ Screen.TwipsPerPixelX
> MPointer.y = y \ Screen.TwipsPerPixelY
> Pos = SendMessage(rich1.hwnd, EM_CHARFROMPOS, 0&, (MPointer.x +
> MPointer.y * &H10000))
>
>

 |  Next  |  Last
Pages: 1 2 3
Prev: SendInput and Unicode
Next: Run Time Creating Controls