Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3670
Number of posts: 9122

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to post a paint message Posted by miteshbvora on 1 Nov 2002 at 10:46 PM
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.
Report
Re: How to post a paint message Posted by AsmGuru62 on 2 Nov 2002 at 4:07 PM
: 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.
:
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);

Report
Re: How to post a paint message Posted by miteshbvora on 6 Nov 2002 at 4:51 AM
: : 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.
: :
: 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);
:

:


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.

Report
Re: How to post a paint message Posted by AsmGuru62 on 6 Nov 2002 at 7:40 AM
This message was edited by AsmGuru62 at 2002-11-6 7:41:12

: : : 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.
: : :
: : 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);
: :

: :
:
:
: 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.
:
:
Then, obviously, there is something wrong with the code. UpdateWindow() can fail for a lot of reasons:

1. HWND you sending is not HWND 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.


Post a small pieces of code where you do stuff...





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.