EDN Admin
Well-known member
I have a Win32 native program in C++ (running in Windows CE), and the basic idea is to set a timer in InitializeWindow and then in the WinProc, everytime the WM_TIMER message comes in, fire the timer again and increment a frame index and call UpdateWindow().
In WM_PAINT I paint a logo on screen and then use the frame count to draw a bitmap selected by the index.
Thats the theory, but in practice, it draws once and then never refreshes the image. Ive put message boxes through out the code and I know that the timer is working as expected, and the frame index increments normally, but the different frames just dont
repaint. Ill paste the code below and any help would be much appreciated.
Matt
<pre class="prettyprint case WM_TIMER:
SetTimer( hWnd , ID_5SECONDS , 3000 , (TIMERPROC) NULL);
if (AnimationIndex >= 5)
AnimationIndex = 0;
else
AnimationIndex = AnimationIndex + 1;
UpdateWindow(hWnd);
break;
case WM_PAINT:
RECT rt;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
SelectObject(ps.hdc, GetStockObject(BLACK_BRUSH));
Rectangle(hdc, rt.left, rt.top, rt.right, rt.bottom);
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_STARTUP_BITMAP));
imageDC = CreateCompatibleDC(hdc);
SelectObject(imageDC, image);
if (rt.right == 640)
BitBlt(hdc, 160, 120, 320, 240, imageDC, 0, 0, BLACKNESS | SRCCOPY);
else
BitBlt(hdc, 0, 0, 320, 240, imageDC, 0, 0, BLACKNESS | SRCCOPY);
SelectObject(imageDC, (HGDIOBJ)NULL);
DeleteObject(image);
switch (AnimationIndex)
{
case 0:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME1));
break;
case 1:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME2));
break;
case 2:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME3));
break;
case 3:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME4));
break;
case 4:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME5));
break;
case 5:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME6));
break;
}
SelectObject(imageDC, image);
if (rt.right == 640)
BitBlt(hdc, 160 + (20 * AnimationIndex), 120, 55, 55, imageDC, 0, 0, BLACKNESS | SRCCOPY);
else
BitBlt(hdc, 0, 0, 55, 55, imageDC, 0, 0, BLACKNESS | SRCCOPY);
SelectObject(imageDC, (HGDIOBJ)NULL);
DeleteObject(image);
DeleteDC(imageDC);
EndPaint(hWnd, &ps);[/code]
<br/>
View the full article
In WM_PAINT I paint a logo on screen and then use the frame count to draw a bitmap selected by the index.
Thats the theory, but in practice, it draws once and then never refreshes the image. Ive put message boxes through out the code and I know that the timer is working as expected, and the frame index increments normally, but the different frames just dont
repaint. Ill paste the code below and any help would be much appreciated.
Matt
<pre class="prettyprint case WM_TIMER:
SetTimer( hWnd , ID_5SECONDS , 3000 , (TIMERPROC) NULL);
if (AnimationIndex >= 5)
AnimationIndex = 0;
else
AnimationIndex = AnimationIndex + 1;
UpdateWindow(hWnd);
break;
case WM_PAINT:
RECT rt;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
SelectObject(ps.hdc, GetStockObject(BLACK_BRUSH));
Rectangle(hdc, rt.left, rt.top, rt.right, rt.bottom);
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_STARTUP_BITMAP));
imageDC = CreateCompatibleDC(hdc);
SelectObject(imageDC, image);
if (rt.right == 640)
BitBlt(hdc, 160, 120, 320, 240, imageDC, 0, 0, BLACKNESS | SRCCOPY);
else
BitBlt(hdc, 0, 0, 320, 240, imageDC, 0, 0, BLACKNESS | SRCCOPY);
SelectObject(imageDC, (HGDIOBJ)NULL);
DeleteObject(image);
switch (AnimationIndex)
{
case 0:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME1));
break;
case 1:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME2));
break;
case 2:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME3));
break;
case 3:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME4));
break;
case 4:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME5));
break;
case 5:
image = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BUSYICON_FRAME6));
break;
}
SelectObject(imageDC, image);
if (rt.right == 640)
BitBlt(hdc, 160 + (20 * AnimationIndex), 120, 55, 55, imageDC, 0, 0, BLACKNESS | SRCCOPY);
else
BitBlt(hdc, 0, 0, 55, 55, imageDC, 0, 0, BLACKNESS | SRCCOPY);
SelectObject(imageDC, (HGDIOBJ)NULL);
DeleteObject(image);
DeleteDC(imageDC);
EndPaint(hWnd, &ps);[/code]
<br/>
View the full article