How to force a refresh of the whole device screen context? RRS feed

  • Question

  • Hi everybody,

    I'm working on a simple application that draws an alpha-blended picture on the screen's Device Context every 2 secs, I want to refresh the screen contents before the drawing operation (To erase the old drawn pic),

    I have used many many tricks but unfortunately, the screen won't refresh correctly, some regions still keep portions of the drawn pic

    I'm really frustrated from this issue :(

    These are the sources codes I have used, I'm using C#

    SendMessage(HWND_BROADCAST, WM_SYSCOLORCHANGE, IntPtr.Zero, IntPtr.Zero); // wasted time in the refreshing process is enough to keep this.
    UpdateWindow(HWND_BROADCAST);// does not work at all!
    InvalidateRect(IntPtr.Zero,IntPtr.Zero,true); // the same goes here.
    SendMessage(HWND_BROADCAST, WM_PAINT, IntPtr.Zero, IntPtr.Zero); // pfffff !
    SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, new IntPtr(SPI_SETNONCLIENTMETRICS), IntPtr.Zero); // trying to refresh the explorer, no resutl

    I used also EnumWindows and call back , very slow and does not fit my case.

    I wanna refresh the whole screen.



    Monday, March 22, 2010 7:23 PM

All replies

  • You can take a look at my post below:

    Transparency and Alpha-Blending

    The code is native (C++) but you should be able to get the concept, and maybe use P/Invoke. In my sample I clear the screen using,

    RECT rect = {0, 0, 240, 200};
    FillRect(hdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));

    This might work for you too.


    Tuesday, March 23, 2010 2:39 AM
  • @Prabhu

    Thanks for your reply

    But I'm not willing to clear the screen's contents, I want to refresh the screen contents before drawing the pic, I mean by that letting the displayed windows update their contents.

    Monday, March 29, 2010 1:59 PM
  • Have you put the actual drawing code which draws or alpha-blends the images under the WM_PAINT event handler?

    Not sure but I am guessing that the problem you are facing is somewhat similar to what I faced a while back, here . Go to the end of the post, I faced a problem where regions in the client area would not be re-drawn. To solve it I just had to re-draw the frame myself under the WM_PAINT message.

    If your problem is different than this, could you provide more details?



    Tuesday, March 30, 2010 2:15 AM
  • Thanks again

    I know, I was not clear in my description

    The idea is to draw a transparent picture on the device screen directly, this is done by getting a the HDC of the device's screen and drawing into it directly,

    To draw a transparent picture, I need to get the snapshot of the screen and then cutting the region on which I will draw then blending it with my pic and paint the result on the device context.

    This process is repeated each 1 sec and on different locations on the screen, for example drawing the pic in location (15,15) then after 1sec in location (160,0) for example, to repeat that I need to refresh the screen (invalidate contents) to clear the early drawn pic.

    The problem that I faced when i've used those code snippets is the wasted time of the refreshing process. sometimes the code does not work at all.

    I used also a special trick, I copy a snapshot of the screen and draw it on the DC before I draw my pic but as you may guess, the screen's contents might change and the snapshot will be obsolete.

    Please if you can give me a trick to let the shown windows update their contents quickly I will be gratefull

    And thanks again



    Tuesday, March 30, 2010 10:14 AM
  • Okay, I think I understand the problem better now. Correct me if I am wrong, basically, your application has a screen and you want to alpha-blend few images on it. You alpha-blend your first image on screen, and then the next one and so on. When you alpha-blend you want the previous image to disappear (or refresh and show original screen contents). And this original screen contents can change over time so you cannot store it somewhere before hand.

    I'll try to look into this when I have time. I have one question though, what does your original application screen contain? Does it have normal Windows Controls or some other user drawn images as background?



    Wednesday, March 31, 2010 3:10 AM
  • Exactly friend

    For your question, I'm not drawing on the application's screen(window), I'm painting on the device's screen :)

    Thanks a lot 

    Wednesday, March 31, 2010 5:52 AM