Archived

This topic is now archived and is closed to further replies.

acematti

Game Painting

Recommended Posts

acematti    122
Hi, Im still trying to fine tune my little 2D games engine. However i was wondering... Does the drawing of images have to happen in the WM_PAINT message. I was trying to make my engine work by calling an image to be drawn like so: ball->Draw(hDCBuffer,ballX,ballY) In the main game loop of the game. Then at the end of the loop I will flip the buffer and everything will get drawn to screen. Hope you can somehow understand my rubbish description All the attempts at making it work like this have ended in flames or rather a blank white window. That is why I am asking if everything has to be drawn in the WM_PAINT as it used to work using this method. Many thanks to anyone who helps Matt

Share this post


Link to post
Share on other sites
kVandaele    138
from "Programming WIndows with MFC (2nd ed)" - Jeff Prosise:
quote:
A window receives a WM_PAINT message, for example, when its interior needs repainting.

Thought so but wasn't sure so i looked it up

So, anyway, the only time a WM_PAINT message is sent is when the window needs repainting (generally when it's moved, something was on top of it and now not anymore, ...).

This is more or less what your WndProc function might look like:

////

// WndProc()

////

LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
switch(msg){
case WM_CREATE:
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;

case WM_PAINT:
ValidateRect(g_hWnd,NULL);
return 0;

case WM_KEYDOWN:
HandleKeys(wParam);
return 0;
}
// let windows handle it, since we don't want it

return DefWindowProc(hWnd,msg,wParam,lParam);
}


then this would be the loop you call from WinMain after initializations and stuff:


////

// StartMessageLoop()

////

WPARAM StartMessageLoop(){
MSG msg;
while(1){
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}else{
// Use idle time here.

// AKA: draw your stuff here

ProcessGame();
}
}
return msg.wParam;
}


[edited by - kVandaele on January 23, 2004 9:25:59 AM]

Share this post


Link to post
Share on other sites