Thread: RedrawWindow()

  1. #1
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120

    Angry 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)

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.

  3. #3
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    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

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.

  5. #5
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    OK thanks, I'll give it a try (my temporary fix is really starting to flicker now and something needs doing!)

  6. #6
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    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.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  7. #7
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    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

Popular pages Recent additions subscribe to a feed