Please help with my frustration. Basically, I change the color of the font whenever the mouse hovers over the static text, however, I noticed that depending on the "Effect" set in the display properties, i.e. standard type or clear type, I get different behavior. Standard type works fine, the text changes color when the mouse hovers it, however, for clear type, it is overlapped with the old color and hence producing a mixture of the two colors, very unpleasant, but I don't have an idea of how to look this up or fix this.
Please explain in simple terms.
Thanks,
Jiac
Marc G
May 27th, 2004, 03:15 AM
you should erase the previous text and completely redraw the new text for cleartype to work correctly. Of course, you should use some a memory DC to prevent flickering.
jiac
May 27th, 2004, 10:39 AM
Can you or somebody please point to me to a code segment or article for me to undertsand because I don't have a clue exactly of how to do this. Btw, why is it that for clear type it doesn't work but for standard type it is ok?
Thanks,
Jiac
Marc G
May 27th, 2004, 11:56 AM
Cleartype doesn't work the way you want to use it, because Cleartype uses the colors already on the screen to calculate the anti-aliased version of your text.
So if you draw text over the previous text, the Cleartype will use the previous text to calculate the colors of the new text. If you keep repeating this, the text will become bold and ugly.
You can take a look at http://www.codeguru.com/Cpp/controls/staticctrl/scrollingtext/article.php/c5809/ . That article uses a memory dc to prevent flickering.
jiac
May 31st, 2004, 06:45 PM
Thanks. After some thinking and trying out, it seems my problem has to do w/ erasebkgnd? I included this API and it is fine in terms of changing the color, meaning there is no overlapped text, however, here is the BIG problem that I can't figure out.
I got a brush for my dialog, but if I try to pass in the brush from the dialog, the color is off.
Question: How to ONLY erase the text and change the text color but not the background color given from the parent dialog? I want to leave the background color untouched, but I don't know how.
Please please help.
Jiac
Marc G
June 1st, 2004, 02:27 AM
That should be
pDC->FillRect(rect, &CurrentBrush);
You can't only clear the text and leaving the background intact when cleartype is activated. You have to redraw the background in the correct color.
jiac
June 1st, 2004, 10:48 AM
Thank you Marc G. Here is the problem. When I get the brush to which the one used for the dialog, because the RGB is not a constant value, subtract a value across the field, how to perserve this?
Is this a possible scenario?
1. clear the bakcground of the CStatic
2. have parent paints CStatic background
3. CStatic draws the necessary text
If so, can you tell me how, i.e. first do what in erasebkgnd of the parent, of the cstatic...? I guess you could tell that I am not familiar with the concept.
Please help.
Jiac
Marc G
June 1st, 2004, 12:25 PM
What do you mean with 'RGB is not a constant value'?
jiac
June 1st, 2004, 04:51 PM
Like a rainbow effect. Color blends in by manipulating the RBG values.
Marc G
June 2nd, 2004, 02:41 AM
Then let the parent repaint the background.
If this is a little test-project, you can post your project and i can take a look at it?
jiac
June 2nd, 2004, 10:52 AM
Sorry, I can't. For the moment, can you tell me how to have the parent do the repaint? So the call to EraseBkgnd() from the child control is omitted entirely. And please be as detailed as possible?
Thank you for your big help Marc G
Marc G
June 2nd, 2004, 12:10 PM
It's difficult to say without some source code.
Is the parent drawing that rainbow thing?
If so, try the following:
- get the coordinates of your static control relative to the parent.
- Use InvalidateRect on the parent window with the above rectangle.
That should do it I guess.
jiac
June 2nd, 2004, 12:15 PM
Hi Marc G,
I got side tracked and started playing with this posting
http://www.codeproject.com/staticctrl/cmyhyperlink.asp
The reason why I care about this one is because in the static control, it didn't use any OnEraseBkgnd(). I noticed under ClearType it is fine as long as I didn't mess with the dialog property. Once I change the Use System Font to true, despite if I reset it back to False, the overlapped text would still apear.
Can you take a look and comment/explain, maybe this holds the key to my problem?
Question, where do I call the InvalidRect in the parent dialog? I have placed this in the derived static control class, I guess that was wrong.
Thanks alot.
Jiac
Marc G
June 2nd, 2004, 01:30 PM
Try something like the following custom static control derived from CStatic:
MyStatic.h:
Sweet.... Thanks alot Marc G, I hope you know you have made someone really relieved today as a result of your help.
The OnEraseBkgnd() is the one I need. I noticed you didn't use InvalidRect. If you feel like explaining, can you tell me why what you did what you did?
Thanks again.
Jiac
Marc G
June 3rd, 2004, 02:14 AM
InvalidateRect doesn't nescessarily update the background immediately, that's why i used RedrawWindow with RDW_ERASENOW and RDW_UPDATENOW.
jiac
June 4th, 2004, 10:42 AM
Hi Marc G, what is a good book you would recommand for someone like me to read?
Thanks for your help again.
Jiac
Marc G
June 4th, 2004, 10:47 AM
Sorry, I can't recommend any book, because I never really read any book myself. I did once had a look at "teach yourself visual c++ in 21 days for VC 4", but that was it.
I learned everything by examining samples from and browsing through MSDN, codeguru, codeproject.
jiac
June 9th, 2004, 11:12 AM
Hi Marc G,
(If you are around) or anyone, can you help? Basically with Marc G's code for OnEraseBkgnd, if I have the app open, and have another window overlapped on top of it, I would see the text being fregmented, meaning the text to where the overlapped window was would not get painted when the app becomes the active window. It will repaint itself if I hide/reappear the window.
// Draw our text
CPaintDC dc(this); // device context for painting
if (m_bMouseHover)
dc.SetTextColor(RGB(255,0,0));
else
dc.SetTextColor(RGB(0,0,0));
dc.SetBkMode(TRANSPARENT);
CFont font;
DWORD dwVersion = GetVersion();
if (dwVersion < 0x80000000) // Windows NT or later
font.CreateStockObject(DEFAULT_GUI_FONT);
else
font.CreateStockObject(ANSI_VAR_FONT);
CFont* pOldFont = dc.SelectObject(&font);
dc.TextOut(0,0,"Test string");
dc.SelectObject(pOldFont);
// Do not call CStatic::OnPaint() for painting messages
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.