So I asked this question in my previous post but I didn't know whether people didn't know the answer or didn't bother reading my previous post; so I decided to ask it again.

Suppose you have found the top-left corner of a word in the rich-edit's current-view. Now you want to draw a line below the word to mark it as an error for example like in Microsoft Word. I am pulling a trick to calculate this length which will result in a really static calculation. It does work however but I need to know exactly how we can calculate the height and width of a font selected in a control, in device units perhaps.

Posted on 2007-12-15 08:02:49 by XCHG
Like I said in that thread, get the X:Y position of "c", and same for the char after "zz".
For height, get Y position of first char in first line, get same for second line.
Posted on 2007-12-15 11:13:37 by Ultrano
This seems a bit time consuming, since you have no idea what font is selected into the control you would have to calculate the exact size each time since the control may be using kerning so "the quick brown" may have different spacing each time and therefore a different length. Kerning or variable spacing will definitely throw off any calculations that you might think are applicable across the whole document or even for simply a particular sentence since the user may change the text behind the sentence and the spacing will be altered. I don't use RichEdit at all so I am not completely certain whether it supports kerning but I suspect it probably will. Such a situation must have been anticipated by the makers of the control and a solution would be built in, at least that's what I would assume.
Posted on 2007-12-15 11:26:23 by donkey

Like I said in that thread, get the X:Y position of "c", and same for the char after "zz".

There is a CRLF after "zz", does that really help finding the width?

For height, get Y position of first char in first line, get same for second line.

What if the user has entered only a single line of text and there is no line after or before the current line?
Posted on 2007-12-15 11:27:43 by XCHG
I found the answer to this :lol: Check out what the EM_SETCHARFORMAT message can do :lol: It is all I wanted to do all this time and yet I was trying to pull tricks for it. Thanks guys. By the way, what is kerneling, Homer?

Oh by the way, I could use the EN_PROTECTED notification message with this structure so that I will get notified when the user is trying to change the currently-marked word. So when I draw the underline for a word and the user changes the word, I will get a chance to remove the underline and search for the new word in the dictionary again.

Another advantage is that I can get notified when the user clicks on the word. I could then display a pop-up menu or something to allow them to add the current word to the dictionary. This is COOLZORZ.
Posted on 2007-12-16 06:21:27 by XCHG
Don't you mean Kerning?

Kerning is the manipulation of horizontal spacing of a (usually vector-based) font such as a TrueType font.
There is no standard width for the characters in these fonts, rather each character has its own width.
Posted on 2007-12-16 22:34:42 by Homer
Ah Kerning! Alright! to me, every term starting with the four letters "kern" is a Kernel :lol: I read about Kerning in Rich Edits and it turns out Rich Edit 2.0 and later do support that. I am going to read more about it. Thanks for all the information ;)
Posted on 2007-12-18 09:32:34 by XCHG
Okay another problem. I used the EM_SETCHARFORMAT message to mark words as underlined, colored and protected. Now I want to reverse this effect on a word. For example, a character or a word, as shown below, is already colored and underlined with the EM_SETCHARFORMAT message. Now I want to reverse this effect. MSDN states, about this message

If this message is sent more than once with the same parameters, the effect on the text is toggled. That is, sending the message once produces the effect, sending the message twice cancels the effect, and so forth.

The problem is that it doesn't work:

        /* --------------------------------- */
        else if (MessageFilter->msg == WM_LBUTTONUP) {
          if (RichEdit_IsCurrentWordProtected(RichEdit1)) {
            CHARFORMATA CharacterFormat;
            memset(&CharacterFormat, 0, sizeof(CharacterFormat));
            CharacterFormat.cbSize = sizeof(CharacterFormat);
            SendMessage(SenderInfo->hwndFrom, EM_GETCHARFORMAT, (WPARAM)(SCF_SELECTION | SCF_WORD), (LPARAM)&CharacterFormat);
            SendMessage(SenderInfo->hwndFrom, EM_SETCHARFORMAT, (WPARAM)(SCF_SELECTION | SCF_WORD), (LPARAM)&CharacterFormat);
        } /* if (MessageFilter->msg == WM_LBUTTONUP) { */
        /* --------------------------------- */

The first SendMessage() is retrieving the character format and the second one is setting it again which is what MSDN states. Does anybody know why it is not working? :(
Posted on 2007-12-19 04:21:28 by XCHG