-
RedrawWindow()
I thought I had solved this problem but I was wrong....
I have a main window and its client area contains a bmp as a background image. I then have a number of transparent (WS_EX_TRANSPARENT) static child windows that display images or text over the top of that.
I want to update the text that is shown in one of these child windows but I cant seem to clear the original text, resulting in overlapping, unreadable text. (see attached jpg)
I have tried using:
--------------------------------------------------------------------------
RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE); // where hwnd is the static window
--------------------------------------------------------------------------
and for a while I thought it worked; but it doesn't and I am beginning to lose my hair!!
Any help would be very gratefully received!
dom (on the edge of breakdown)
-
This is only a suggestion as there are a number of ways to do this:
1. Create your back ground bitmap as normal.
2. Handle the WM_ERASEBKGND msg; the dc for the wnd is the
wParam passed to that msg.
3. Use InvalidateRect(hwnd,0,1); to force an erase and redraw of the whole background.
4. Use SetWindowText ( or whatever) to set the text of your static controls.
This may result in some flicker as the controls are redrawn - I don't know without looking at your code. The same result could be achieved by using the WM_PAINT handler instead of WM_ERASBKGND.
An alternative might be to use TextOut, DrawText etc to output the labels directly to the displayed bitmap instead of using the static controls.
-
Thanks. I've tried InvalidateRgn and handling ERASEBKGRND but nothing seems to work; as a solution I have a function to redraw the entire screen (redrawing the main window bitmap succeeds in clearing everything else) drawing different parts depending on what needs to be done. This seems to work and without flicker, it just seems somewhat innefficient and annoying!
I think I may be handling ERASEBKGRND incorrectly though; what do you do with it? I saw some examples but couldn't figure it out?
Thanks again
dt
-
I probably wouldn't use static controls - i'd draw everything onto the bitmap.
For this I might keep a small array of RECT structures for each text field, use InvalidateRect(hwnd,&rcTextField[i],1); to clear the background of the specific text field and then use TextOut to write the text to the required RECT.
Again, that's only one possible way of doing it....
As for the WM_ERASE.., I would probably use it in the 'inefficient' way you describe - to just flatten the background and give me a plain surface to add all the other information to.
-
OK thanks, I'll give it a try (my temporary fix is really starting to flicker now and something needs doing!)
-
If you are just trying to update the text why not call SetWindowText? That will clear whatever was there and replace it with what you want it to.
-
I thought that but I couldn't get it to work so I gave up and took the harder option(??!). Can you set fonts and colours to work with SetWindowText? Also, the problem was not just with text, but with bitmaps and so I wanted an all round solution.
Anyways, I've now got rid of the statics and have arays of RECTs and it is a lot simpler (thanks Ken), twas a nightmare rewriting it all though!
dt