Thread: Window Flicker

  1. #1
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972

    Window Flicker

    I was trying to make my own tab control so I can open several files in my program. I was trying to do this by creating a richedit control for each tab and then hiding and showing those when a user clicks on a different tab. Maybe it isn't the best way, but it seems to work ok, except the edit controls flicker when switching back and forth.

    If I handle the WM_ERASEBKGND message and just return 0, there is no flicker. Problem is, I need to erase the background except where the edit control is. So what is the easiest way to erase the entire background except for a certain rect?

    According to this page, I should be able to call InvalidateRect with the last parameter as false, but that doesn't seem to work:
    Code:
    case WM_PAINT:
    {
          RECT rc;
          GetWindowRect(hRiched[currentEdit],&rc);
          InvalidateRect(hwnd,&rc,0);
          tab.RedrawTabs();      
          
    }
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    Call UpdateWindow immediately following InvalidateRect.

    Also, You can do all your background erasing in WM_PAINT. That's what I do most of the times.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Calling UpdateWindow doesn't seem to have any effect...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    UpdateWindow() just bypasses the OS msg que and posts directly to your apps callback.

    InvalidateRect() sends a WM_PAINT msg.

    So not a good idea to call either from within WM_PAINT.

    Call both only when the TAB changes.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    Post some code so we can take a look if you dont mind.

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Hm well with a bit of messing around I came up with this code to handle the WM_ERASEBKGND message:
    Code:
          RECT rc;
          HDC hdc = GetDC(hwnd);
          GetWindowRect(hRiched[currentEdit],&rc);
          ExcludeClipRect(hdc,rc.left,rc.top-1-GetSystemMetrics(SM_CYMENUSIZE)-GetSystemMetrics(SM_CYCAPTION),rc.right,rc.bottom-GetSystemMetrics(SM_CYMENUSIZE)-GetSystemMetrics(SM_CYCAPTION));
          GetClientRect(hwnd,&rc);
          HBRUSH hbr = CreateSolidBrush(RGB(88,87,104));
          FillRect(hdc,&rc,hbr);
          DeleteBrush(hbr);
          ReleaseDC(hwnd,hdc);
          return 0;
    Although I'm not sure how to be sure the rect that I get for the rich edit window lines up properly...

    Which kind of ties in to a weird problem. When I create my main window I create it with the following styles:
    Code:
    WS_POPUP|WS_CAPTION|WS_MAXIMIZE|WS_SYSMENU|WS_MINIMIZEBOX|WS_CLIPCHILDREN
    And it looks the way I want when I run it from VS, but when I don't run it from VS, it isn't maximized (still takes up the whole screen,but has a border). So you can move it around, which I don't want.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    I was trying to make my own tab control so I can open several files in my program. I was trying to do this by creating a richedit control for each tab and then hiding and showing those when a user clicks on a different tab. Maybe it isn't the best way, but it seems to work ok, except the edit controls flicker when switching back and forth.
    You're probably are getting flicker because when you hide the rich text window you draw what's behind the rich text window(the erase background event) and when you show the other rich text you replace the background. What you want to do is hide one rich text window, but not invalide the control's rectangle, and then replace with the other rich text window. It might be better to somehow change the each rich text window's zorder so that one window appears above the other. I don't know enough of the win32 API to help you with the specifics.
    Last edited by okinrus; 09-20-2005 at 10:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM