View Full Version : Sample how to call EM_CHARFROMPOS
Hullo,
could anyone post an example of how to call the windows messages EM_CHARFROMPOS and/or EM_POSFROMCHAR ? I need some functionality in text-boxes and need to know on which position the cursor is if the control has focus.
TIA,
Matt
Chris T.
09-11-2001, 03:42 AM
Hi,
use it like this:
<tt> Pos := LoWord( SendMessage(Handle, EM_CHARFROMPOS, 0, MakeLParam(X, Y)) );
Line := HiWord( SendMessage(Handle, EM_CHARFROMPOS, 0, MakeLParam(X, Y)) );</tt>
Where X and Y are the mouseposition.
But this will get the position of your mousecursor in an edit control. With EM_POSFROMCHAR you can get where a Char is in the edit control.
================================
<tt>See You, Chris
mail: chris@little-helpers.de</tt>
Hi Chris, thanks ! Got the one you listed to work.
I guess I need EM_POSFROMCHAR too. I'm just not sure what you mean by "you can get where a Char is in the edit control". If I have a string 'aaalllfffaaa' the 'a' occurs 6 times in different positions ! Which one will be returned ?
Your help is much appreciated. Tx,
Matt
Chris T.
09-18-2001, 03:34 AM
Hi,
you replied just in time. Just back from my holidays ;)
As I can remeber it gets the first one, like Pos()
But if you need something more effective use:
WM_GETTEXT or GetWindowText()
(WM_GETTEXTLENGTH or GetWindowTextLength())
So you could parse what you need.
================================
<tt>See You, Chris
mail: chris@little-helpers.de</tt>
Hi Chris, thanks again. My holidays are coming up next week :-)))
I'll try GETTEXT. But what I really need is a function that returns the position of the leftmost visible character. If the string is 'abcde' and the visible part is 'bcde' it should be 2. If the visible part is 'cde' it should be 3.
Because I have to scroll a label in synch with the textbox. As they don't have scrollbars, I try to do it with code.
And it should always work, not just with mouse-clicks like EM_CHARFROMPOS. Particularly with HOME, END or the left- or right-arrows are press
Or do you know of a control that functions like a textbox but comes with scrollbars ? Is there a way to force a memo control to be 1 line only ?
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.