lemming999
Programmer
I really need help on this, i'm using the InvalidateRect function with a timer to update the screen but its slow redrawing and is causing a flicker effect. Is there any way of improving this function to emulate the below
case WM_TIMER:
InvalidateRect (hWnd,NULL,FALSE);
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
m.drawMap(hdc,cxClient,cyClient);
if (sim != NULL)
{
//do this update vehicles and draw them
}
EndPaint(hWnd, &ps);
break;
/*****************************************************/
from a previous project this worked quite efficiently instead
/*****************************************************/
while( WM_QUIT != msg.message )
{
if( g_bActive )
bGotMsg = PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE );
else
bGotMsg = GetMessage( &msg, NULL, 0U, 0U );
if( bGotMsg )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
m.drawMap(d.getHdc(),cxClient,cyClient);
if (sim != NULL)
{
sim->update();
sim->drawVehicles(d.getHdc(),cxClient,cyClient);
}
d.pageFlip(cxClient,cyClient);
}
}
/*******************************************************/
/ but because my project has different function layouts such as /
int APIENTRY WinMain(HINSTANCE hInstanc, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
/******************** rather than **********************/
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
i get errors trying to emulate the above in my code such as hdc used without first being initialised
Any help or explanation would be greatly appreciated
case WM_TIMER:
InvalidateRect (hWnd,NULL,FALSE);
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
m.drawMap(hdc,cxClient,cyClient);
if (sim != NULL)
{
//do this update vehicles and draw them
}
EndPaint(hWnd, &ps);
break;
/*****************************************************/
from a previous project this worked quite efficiently instead
/*****************************************************/
while( WM_QUIT != msg.message )
{
if( g_bActive )
bGotMsg = PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE );
else
bGotMsg = GetMessage( &msg, NULL, 0U, 0U );
if( bGotMsg )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
m.drawMap(d.getHdc(),cxClient,cyClient);
if (sim != NULL)
{
sim->update();
sim->drawVehicles(d.getHdc(),cxClient,cyClient);
}
d.pageFlip(cxClient,cyClient);
}
}
/*******************************************************/
/ but because my project has different function layouts such as /
int APIENTRY WinMain(HINSTANCE hInstanc, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
/******************** rather than **********************/
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
i get errors trying to emulate the above in my code such as hdc used without first being initialised
Any help or explanation would be greatly appreciated