int num=0,m=0;
int width,hight,w,h,w1,h1,firewidth,firehight,firew,fireh;
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HBITMAP hbitmap,hBkBmp;
BITMAP bitmap;
HDC hmenDC,hdc;
RECT rect;
HBRUSH hBrush;
GetClientRect(hWnd,&rect);
switch(message)
{
case WM_PAINT:
hdc=GetDC(hWnd);
if (!m)
{
Initialize(hbitmap,bitmap);
DeleteObject(hbitmap);
}
hmenDC = CreateCompatibleDC(hdc);
hbitmap = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
SelectObject(hmenDC, hbitmap);
hBkBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_PEOPLE));
hBrush = CreatePatternBrush(hBkBmp);
FillRect(hmenDC, &rect, hBrush);
DeleteObject(hBrush);
SelectObject(hmenDC,hbitmap);
TransparentBlt(hdc,rect.right/2-width/2,504-hight,width,hight,
hmenDC,(1)*width,0,width,hight,RGB(255,255,0));
DeleteObject(hbitmap);
DeleteObject(hmenDC);
DeleteObject(hBkBmp);
ReleaseDC(hWnd,hdc);
num++;
if (num>=8)
{
num=0;
}
Sleep(500);
InvalidateRect(hWnd,NULL,TRUE);
break;
case WM_SIZE:
InvalidateRect(hWnd,NULL,TRUE);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
break;
}
return 0;
}
void Initialize(HBITMAP hbitmap,BITMAP bitmap)
{
hbitmap=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_PEOPLE));
GetObject(hbitmap,sizeof(BITMAP),&bitmap);
w=bitmap.bmWidth;
h=bitmap.bmHeight;
width=w/8;
hight=h;
hbitmap=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_FIREWORK));
GetObject(hbitmap,sizeof(BITMAP),&bitmap);
firew=bitmap.bmWidth;
fireh=bitmap.bmHeight;
firewidth=firew/5;
firehight=fireh;
m++;
}
![圖片說明](http://img.ask.csdn.net/upload/201505/19/1432048653_550138.jpg)
想把這8個人依次顯示出來,可是只能顯示前兩個人頭,這是為什麼
已經被選入 DC 的 GDI 對象,如:hbitmap,直接 Delete 是不行的。雖然調用 Delete 顯示成功了!
你需要先將其選出 DC,即將以前的對象選入 DC 後,才能成功刪除它。