How to post a paint message

hello,
i am writing my first game in VC++ SDK Snakes and ladders.

in the game every time a new player throws the dice and moves to the new position i have to load the bitmap of player token on the new position and remove it from the old for this purpose i am calling InvalidateRect() and invalidating the rectangle of the old position and set a flag so that in paint it will now load at a new position but when i pass Hwnd parameter as the handle to the window it does not Post a paint message immediately , but when i pass Null to it it does and the whole game board is refreshed and new position restored.

can anyone tell me how i can get the Paint message posted so that i can refresh immediately and only that portion which i hae Invalidated .

also i have to then right this entire code in class wrppaers so can anyone tell me from wher i can get class wrapper codes of any information on how wrap these window creatin etc code in class wrappers. i am not supposed to use MFC hence i have to wrap it in my own classes.

Comments

  • : hello,
    : i am writing my first game in VC++ SDK Snakes and ladders.
    :
    : in the game every time a new player throws the dice and moves to the new position i have to load the bitmap of player token on the new position and remove it from the old for this purpose i am calling InvalidateRect() and invalidating the rectangle of the old position and set a flag so that in paint it will now load at a new position but when i pass Hwnd parameter as the handle to the window it does not Post a paint message immediately , but when i pass Null to it it does and the whole game board is refreshed and new position restored.
    :
    : can anyone tell me how i can get the Paint message posted so that i can refresh immediately and only that portion which i hae Invalidated .
    :
    : also i have to then right this entire code in class wrppaers so can anyone tell me from wher i can get class wrapper codes of any information on how wrap these window creatin etc code in class wrappers. i am not supposed to use MFC hence i have to wrap it in my own classes.
    :
    [blue]In general your code will look like that:
    1. Remove player from the previous location - I mean coordinates - do not draw anything yet.

    2. Put a player to a new location - again - no drawing.

    3.
    InvalidateRect (hWnd, pRectOldLocation, TRUE);
    InvalidateRect (hWnd, pRectNewLocation, TRUE);

    // This is where your code inside WM_PAINT response
    // will draw the changes.
    UpdateWindow (hWnd);
    [/blue]
  • : : hello,
    : : i am writing my first game in VC++ SDK Snakes and ladders.
    : :
    : : in the game every time a new player throws the dice and moves to the new position i have to load the bitmap of player token on the new position and remove it from the old for this purpose i am calling InvalidateRect() and invalidating the rectangle of the old position and set a flag so that in paint it will now load at a new position but when i pass Hwnd parameter as the handle to the window it does not Post a paint message immediately , but when i pass Null to it it does and the whole game board is refreshed and new position restored.
    : :
    : : can anyone tell me how i can get the Paint message posted so that i can refresh immediately and only that portion which i hae Invalidated .
    : :
    : : also i have to then right this entire code in class wrppaers so can anyone tell me from wher i can get class wrapper codes of any information on how wrap these window creatin etc code in class wrappers. i am not supposed to use MFC hence i have to wrap it in my own classes.
    : :
    : [blue]In general your code will look like that:
    : 1. Remove player from the previous location - I mean coordinates - do not draw anything yet.
    :
    : 2. Put a player to a new location - again - no drawing.
    :
    : 3.
    : InvalidateRect (hWnd, pRectOldLocation, TRUE);
    : InvalidateRect (hWnd, pRectNewLocation, TRUE);
    :
    : // This is where your code inside WM_PAINT response
    : // will draw the changes.
    : UpdateWindow (hWnd);
    : [/blue]
    :


    thanks ,
    but i want to ask is where to call the UpdateWindow. i tried doing it immediately after InvalidateRect() but nothing changed i mean it did not call the WM_PAINT immediately .

    also is there any flag to be set or something like that which indicates that only this area is to be painted and then execute the code inside WM_PAINT only if that flag is set.

  • [b][red]This message was edited by AsmGuru62 at 2002-11-6 7:41:12[/red][/b][hr]
    : : : hello,
    : : : i am writing my first game in VC++ SDK Snakes and ladders.
    : : :
    : : : in the game every time a new player throws the dice and moves to the new position i have to load the bitmap of player token on the new position and remove it from the old for this purpose i am calling InvalidateRect() and invalidating the rectangle of the old position and set a flag so that in paint it will now load at a new position but when i pass Hwnd parameter as the handle to the window it does not Post a paint message immediately , but when i pass Null to it it does and the whole game board is refreshed and new position restored.
    : : :
    : : : can anyone tell me how i can get the Paint message posted so that i can refresh immediately and only that portion which i hae Invalidated .
    : : :
    : : : also i have to then right this entire code in class wrppaers so can anyone tell me from wher i can get class wrapper codes of any information on how wrap these window creatin etc code in class wrappers. i am not supposed to use MFC hence i have to wrap it in my own classes.
    : : :
    : : [blue]In general your code will look like that:
    : : 1. Remove player from the previous location - I mean coordinates - do not draw anything yet.
    : :
    : : 2. Put a player to a new location - again - no drawing.
    : :
    : : 3.
    : : InvalidateRect (hWnd, pRectOldLocation, TRUE);
    : : InvalidateRect (hWnd, pRectNewLocation, TRUE);
    : :
    : : // This is where your code inside WM_PAINT response
    : : // will draw the changes.
    : : UpdateWindow (hWnd);
    : : [/blue]
    : :
    :
    :
    : thanks ,
    : but i want to ask is where to call the UpdateWindow. i tried doing it immediately after InvalidateRect() but nothing changed i mean it did not call the WM_PAINT immediately .
    :
    : also is there any flag to be set or something like that which indicates that only this area is to be painted and then execute the code inside WM_PAINT only if that flag is set.
    :
    :
    [blue]Then, obviously, there is something wrong with the code. [b]UpdateWindow()[/b] can fail for a lot of reasons:

    1. [b]HWND[/b] you sending is not [b]HWND[/b] you expect it to update.
    2. The rectangle coordinates are incorrect/negative
    ... it can be anything...

    I never heard that problem before - usually you do not blame API which is tested good enough. The problem is in 99.999% in the client code.
    [/blue]

    [red]Post a small pieces of code where you do stuff...[/red]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories