Author: mkupfer
Date: Sun Jul 6 07:05:17 2008
New Revision: 34325
URL:
http://svn.reactos.org/svn/reactos?rev=34325&view=rev
Log:
- avoid clock flicker in timedate.cpl
- TODO: limit repaint area to clock only (to avoid flicker of time adjusting control as
well)
Modified:
trunk/reactos/dll/cpl/timedate/clock.c
Modified: trunk/reactos/dll/cpl/timedate/clock.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/timedate/clock.c?r…
==============================================================================
--- trunk/reactos/dll/cpl/timedate/clock.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/timedate/clock.c [iso-8859-1] Sun Jul 6 07:05:17 2008
@@ -141,7 +141,8 @@
LPARAM lParam)
{
PCLOCKDATA pClockData;
- HDC hdc;
+ HDC hdc, dcMem;
+ HBITMAP bmMem, bmOld;
PAINTSTRUCT ps;
pClockData = (PCLOCKDATA)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
@@ -168,15 +169,38 @@
case WM_TIMER:
GetLocalTime(&pClockData->stCurrent);
- InvalidateRect(hwnd, NULL, TRUE);
+ //InvalidateRect(hwnd, NULL, TRUE);
+ InvalidateRect(hwnd, NULL, FALSE);
pClockData->stPrevious = pClockData->stCurrent;
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
- SetIsotropic(hdc, pClockData);
- DrawClock(hdc, pClockData);
- DrawHands(hdc, &pClockData->stPrevious, TRUE);
+
+ /* Use an offscreen dc to avoid flicker */
+
+ dcMem = CreateCompatibleDC(hdc);
+ bmMem = CreateCompatibleBitmap(hdc, ps.rcPaint.right - ps.rcPaint.left,
ps.rcPaint.bottom - ps.rcPaint.top);
+
+ bmOld = SelectObject(dcMem, bmMem);
+ SetViewportOrgEx(dcMem, -ps.rcPaint.left, -ps.rcPaint.top, NULL);
+ FillRect(dcMem, &ps.rcPaint, GetSysColorBrush(COLOR_BTNFACE));
+
+ SetIsotropic(dcMem, pClockData);
+ DrawClock(dcMem, pClockData);
+ DrawHands(dcMem, &pClockData->stPrevious, TRUE);
+
+ /* Blit the changes to the screen */
+ BitBlt(hdc,
+ ps.rcPaint.left, ps.rcPaint.top,
+ ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top,
+ dcMem,
+ ps.rcPaint.left, ps.rcPaint.top,
+ SRCCOPY);
+
+ SelectObject(dcMem, bmOld);
+ DeleteObject(bmMem);
+ DeleteObject(dcMem);
EndPaint(hwnd, &ps);
break;
@@ -202,7 +226,7 @@
CopyMemory(&pClockData->stPrevious, (LPSYSTEMTIME)lParam,
sizeof(SYSTEMTIME));
/* Redraw the clock */
- InvalidateRect(hwnd, NULL, TRUE);
+ InvalidateRect(hwnd, NULL, FALSE);
break;
default: