Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I really need help on this, i'm usi

Status
Not open for further replies.

lemming999

Programmer
Mar 11, 2002
12
0
0
IE
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
 
generally, creating a copy of the hDC in your memory and do all the drawing in the memory DC then copy it back to the screen will make your program flicker free. Here is the sample,

HDC hdcBuffer = CreateCompatibleDC(hdc);
m.drawMap(hdcBuffer,cxClient,cyClient);
BitBlt(hdc, 0, 0, cxClient, cyClient, hdcBuffer, 0, 0, SRCCOPY);
DeleteDC(hdcBuffer);

The reason of the slow drawing, I think, is that you redraw the everything even if there is only a small update. So tune your program, only update the part which has to be updated.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top