News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Trailing blanks in single line edit

Started by Jimg, March 20, 2007, 01:48:21 PM

Previous topic - Next topic

Jimg

Do you see trailing blanks in the top single line edit when you run the attached program?  Out of two computers, one shows the blanks, and one doesn't.  Strange for a standard common controls object.


p.s.  I couldn't figure out how to embed a image in this post, so an image of what happens on my computer is also attached.


[attachment deleted by admin]

Jimg

By the way, this is for a program I am working on where the user can specify strings with leading/trailing blanks so I would like to get the multi-line edit working also without so much subclassing rewrite that it would be simpler to write a whole control from scratch.

MichaelW

#2
Under Windows XP and Windows 2000 the results looked like your image. Under Windows 98 FE there was no background color visible, but the trailing blanks were present. Have you considered providing a view-whitespace option that would temporarily replace spaces with ASCII character 250? I'm not sure if the character will display correctly on all or even most systems, but it appears to be what SciTE displays when the option is enabled.
eschew obfuscation

PBrennick

Jim,
If you use a RichEdit Control, you can control the background color of the text so that it is not the same as the background color of the control. This will solve your problem and you do not need to subclass the control. A space IS text. Even though it is a blank it shares the same attributes as text.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Jimg

Michael -  Thanks for the ideas.  I'll keep them in reserve.

Paul- Ok, I'll give it a try.  I'm sure I'll be back with more questions :wink

Jimg

Ok, now I remember why I never use a RichEdit.

I tried the following:

        ;chrf CHARFORMAT2 <?>
        inv SendMessage, hRich, EM_GETCHARFORMAT, 0, addr chrf
        ;mov chrf.crBackColor, rgb(235,220,189)
        mov chrf.crTextColor, 00ffff00h
        mov chrf.crBackColor, 00000000h
        mov chrf.dwMask,CFM_COLOR
        ;mov chrf.dwEffects,CFE_AUTOCOLOR
        inv SendMessage, hRich, EM_SETCHARFORMAT, SCF_ALL, addr chrf

No luck.  What's the secret to coloring this thing?

Jimg

Ok, I left out cbSize.  Then it worked.  But when I tried to change the back color of the text, no luck again.


mov cf.cbSize,sizeof cf
        mov cf.crBackColor, 00ffff00h
        mov cf.crTextColor, 00000000h
        mov cf.dwMask,CFM_COLOR
        inv SendMessage, hRich, EM_SETCHARFORMAT, SCF_ALL, addr cf


What's the secret to setting the backcolor of the text (not the background of the richedit, white is fine)?

Jimg

Well you dummy, you forgot to set a bit in the mask--

mov cf.cbSize,sizeof cf
        mov cf.crBackColor, 00ffff00h
        mov cf.crTextColor, 00000000h
        mov cf.dwMask,CFM_COLOR or CFM_BACKCOLOR
        inv SendMessage, hRich, EM_SETCHARFORMAT, SCF_ALL, addr cf


Too bad win32.hlp doesn't have this info in it.

Onwards and upwards ......

PBrennick

Jim,
Also, remember, when you are setting the color choice it is '00bbggrr' where you can change the two zeroes to various numbers. That is the intensity byte. Most people do not know this. When you want to change text to bold, it is a very simple way to do it now that you know how to use the structure. If you already know these things, sorry. Just trying to add some knowledge even if you will not use it in this case. Remember, also, that in a RichEdit Control you can have as many text foreground and background colors in the same control as you want.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Jimg

Thanks Paul, it works exactly as I wanted.

Jimg

Oops, spoke too soon.  There's no right click context menu in a richedit.  Oh well, I vaguely remember how to create a popup menu.  Later.

PBrennick

If you need help with that, just ask.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Jimg

Ok, I finally got back to this.

When I use EM_GETLINE in an edit control, I get the number of characters.
When I use it in a RichEdit control, I get an extra character, a 13 or carriage return.
I'm using ES_WANTRETURN and ES_MULTILINE in both.  The only documentation I could find said the RichEdit would return a zerobyte terminator, but I could find no mention of a carriage return.  Is this normal?  Can I rely on it????

Jimg

For now I'm just using-
inv SendMessage,hRText,EM_GETLINE,RowNum,addr Buff
.if byte ptr [Buff+eax-1]==13
sub eax,1
.endif

unless anyone has a better suggestion.

PBrennick

Jim,
It is normal for a richedit multiline control. The documentation you are referring to is probably referring to the zerobyte terminator that is at the end of the paragraph, not the end of a line. What you are seeing is called a line break. If you grab the entire paragraph the linebreaks will not be there.

I do not know what you are trying to do so the next paragraph may be a waste of your time:

I am curious as to why you would want to grab a single line from a multiline control. What I would do is grab the entire paragraph and use a calculation to determine where the linebreaks were. It can be done, the amount of pixels in the width of the control divided by the amount of pixels in a character will tell you how many characters will fit on a line. Next you add the character width to the string start to update the pointer. Then you test if it is a space, if not you back up and test one character at a time until you find the space. All the time you are counting up the amount of character positions you have moved forward and then down as you go back. The string start to that space is the first line. Copy that line to its own string using the length. Move your pointer to the start of the next word and copy the rest of the string to itself thereby removing the line already saved and start the stepping all over again. You proceed through the paragraph in this manner until you reach the zerobyte at which point you break out of the loop after saving the last line. This is easier to do than it is to say. It is a brute force method but will need no head scratching.

If I guessed wrong, I am sorry I bored you.

Paul
The GeneSys Project is available from:
The Repository or My crappy website