The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Jimg on March 20, 2007, 01:48:21 PM

Title: Trailing blanks in single line edit
Post by: Jimg on March 20, 2007, 01:48:21 PM
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]
Title: Re: Trailing blanks in single line edit
Post by: Jimg on March 20, 2007, 01:53:50 PM
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.
Title: Re: Trailing blanks in single line edit
Post by: MichaelW on March 20, 2007, 02:37:30 PM
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.
Title: Re: Trailing blanks in single line edit
Post by: PBrennick on March 20, 2007, 04:57:06 PM
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
Title: Re: Trailing blanks in single line edit
Post by: Jimg on March 20, 2007, 06:04:58 PM
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
Title: Re: Trailing blanks in single line edit
Post by: Jimg on March 20, 2007, 07:24:55 PM
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?
Title: Re: Trailing blanks in single line edit
Post by: Jimg on March 20, 2007, 09:32:15 PM
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)?
Title: Re: Trailing blanks in single line edit
Post by: Jimg on March 20, 2007, 09:43:47 PM
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 ......
Title: Re: Trailing blanks in single line edit
Post by: PBrennick on March 20, 2007, 10:13:04 PM
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
Title: Re: Trailing blanks in single line edit
Post by: Jimg on March 20, 2007, 10:31:06 PM
Thanks Paul, it works exactly as I wanted.
Title: Re: Trailing blanks in single line edit
Post by: Jimg on March 20, 2007, 10:35:34 PM
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.
Title: Re: Trailing blanks in single line edit
Post by: PBrennick on March 20, 2007, 10:43:03 PM
If you need help with that, just ask.

Paul
Title: Re: Trailing blanks in single line edit
Post by: Jimg on April 03, 2007, 07:02:21 PM
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????
Title: Re: Trailing blanks in single line edit
Post by: Jimg on April 03, 2007, 10:19:05 PM
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.
Title: Re: Trailing blanks in single line edit
Post by: PBrennick on April 03, 2007, 10:21:12 PM
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
Title: Re: Trailing blanks in single line edit
Post by: Jimg on April 03, 2007, 11:24:33 PM
Hi Paul-
I'm not doing anything so complicated or exciting (boring? hah!).  I'm just getting variable length lines from the user, so I'm relying on the control to feed me the lines one at a time.  As the whole subject of this thread, the trailing blanks are significant.  I'm just upset when I can't find documentation and I have to guess what's going on with windows now.

As a little preview of what I'm doing, it's a program to search files for strings.  I use it primarily to search the many megabytes of code examples I have collected to see how an api is used or to find something I've done in the past.  You put the strings you want to search for in the top rich edit, one string per line, blanks are significant.  In the bottom richedit, you can enter strings that will disqualify a line.  eg. I want all lines that contain abc but not if it's abcd.

I've got a ton of things to still do to it, but it's functional.  Just not for files over 4GB at the moment.



[attachment deleted by admin]