GDI+ and double buffering
Hi everyone! I've just started using GDI+, and I've got a program which updates the graphics whenever a timer ticks. It works fine, but it flickers annoyingly. I managed to use double buffering to solve this with GDI, but I don't know how to do this in GDI+.
Here's the structure of my program:
Code:
void update (HDC hdc)
{
Graphics graphics(hdc);
Pen black(Color(255, 0, 0, 0), 4);
SolidBrush red(Color(255, 255, 0, 0));
SolidBrush blue(Color(255, 0, 0, 255));
SolidBrush orange(Color(255, 200, 200, 0));
graphics.DrawLine(&black, 0, 530, GetSystemMetrics(SM_CXSCREEN), 530);
graphics.DrawLine(&black, orangex+170, 530, orangex+170, 450);
graphics.FillEllipse(&red, x, y, 50, 50);
graphics.FillEllipse(&blue, bluex, bluey, 10, 150);
graphics.FillEllipse(&orange, orangex, orangey, 150, 10);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch(msg)
{
case WM_TIMER:
//calculate new coordinates for the GDI objects.
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
update(hdc);
EndPaint(hwnd, &ps);
break;
Any help with getting rid of the flicker would be nice :) I appreciate it!