Thread: Repaint a window

  1. #1

    Repaint a window

    How can I repaint a window? I've tried update window but it never works for some reason.

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    UpdateWindow just forces a WM_PAINT message. You have to answer that WM_PAINT message by redrawing anything you drew before. Using the HDC given from BeginPaint() you need to redraw.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    you can also use Invalidate

  4. #4
    I gathered I was handling the WM_PAINT message...
    Code:
    case WM_PAINT:
      {
        EnumChildWindows(hwnd,EnumProc,0);
        PAINTSTRUCT ps;
        HDC dc = BeginPaint(hwnd,&ps);
        DrawMCB(hwnd,dc,status);
        EndPaint(hwnd,&ps);
        ReleaseDC(hwnd,dc);
        return 0;
      }

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    easiest way is to use your debugger. break inside the WM_PAINT handler. See what happens. If it doesn't get there, you aren't InvalidateRect()-ing in the right place.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Ok, well I have to learn to use the debugger first so I'll go off to read the relevant stuff on that and then try.

    Thanks so far.

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You must use InvalidateRect() then UpdateWindow()

    that is tell the app
    InvalidateRect();//this is the area I want updated
    UpdateWindow()//do it NOW by bypassing the msg que

    If the rect invalidated is empty the paint msg will not be sent/responded to.

    if using MSVC, highlight a line in your code. Press F9 to place a break point (a red dot appears). Run the app and it will stop at the break point. Drag a variable to teh 'watch' window or highlight to see the contents.

    PS Normally you have to ReleaseDC() but seeing you use the one BeginPaint() created (and will be cleaned up by EndPaint() ) you don't need the ReleaseDC(). (as you did not GetDC() it)
    Last edited by novacain; 12-19-2003 at 01:15 AM.
    "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

  8. #8
    I've tried and tried but still can't get it to update!

    Code:
            rc.left = p1.x;
            rc.top = p1.y;
            rc.right-=rc.left;
            rc.bottom-=rc.top;
            InvalidateRect(hwnd,&rc,TRUE);
            UpdateWindow(hwnd);
    I gathered that was right. Or should I be using the windows parent there?

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    The parent hwnd, as it is the dialogs callback that will get the msg to paint.
    "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

  10. #10
    Yeah I figured that out when I read the MSDN stuff again . ...

    Cheers anyways!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 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