1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
void bitmap(image imgImage)
{
//assignment imgImage to imgMenu
imgMenu=imgImage;
//change the image backcolor for menu backcolor
imgMenu.Backcolor=GetSysColor(COLOR_MENU);
//deleting the GDI objects before change them
SelectObject(hMemDC, hBmp2);
DeleteDC(hMemDC);
DeleteBitmap(hBmp);
//do a double buffer from imgMenu and draw it's image
BITMAP bm;
hMemDC = CreateCompatibleDC((HDC)imgMenu);
GetObject((HBITMAP) imgMenu,sizeof(bm),&bm);
hBmp = CreateCompatibleBitmap((HDC)imgMenu, bm.bmWidth,bm.bmHeight);
hBmp2 = (HBITMAP)SelectObject(hMemDC, hBmp);
//BitBlt(hMemDC,0,0,imgMenu.width(),imgMenu.height(),imgMenu,0,0,SRCCOPY);
TransparentBlt(hMemDC,0,0,imgMenu.width(),imgMenu.height(),imgMenu,0,0,imgMenu.width(),imgMenu.height(),imgMenu.Backcolor);
//change the image on menus
SetMenuItemBitmaps(MenuHandle,ID,MF_BYCOMMAND,(HBITMAP)hBmp ,(HBITMAP)hBmp);
//delete the GDI objects... except the hBmp for not lose the image
SelectObject(hMemDC, hBmp2);
DeleteDC(hMemDC);
//my own timer for do the animation
tmrimgmenu.Interval=imgMenu.FrameDelay;
tmrimgmenu.timerprocedure=[this]()
{
//change imgMenu frame
intFrame++;
if(intFrame==imgMenu.FrameCount)
intFrame=0;
imgMenu.SelectFrame=intFrame;
//delete the GDI objects
//the hBmp will be updated, so we must delete it
SelectObject(hMemDC, hBmp2);
DeleteDC(hMemDC);
DeleteBitmap(hBmp);
//do a double buffering from imgMenu and draw it's image
BITMAP bm;
hMemDC = CreateCompatibleDC((HDC)imgMenu);
GetObject((HBITMAP) imgMenu,sizeof(bm),&bm);
hBmp = CreateCompatibleBitmap((HDC)imgMenu, bm.bmWidth,bm.bmHeight);
hBmp2 = (HBITMAP)SelectObject(hMemDC, hBmp);
//RECT f={0,0,imgMenu.width(),imgMenu.height()};
//FillRect(hMemDC,&f,GetSysColor(COLOR_MENU));
BitBlt(hMemDC,0,0,imgMenu.width(),imgMenu.height(),imgMenu,0,0,SRCCOPY);
//change the menu image
SetMenuItemBitmaps(MenuHandle,ID,MF_BYCOMMAND,(HBITMAP)hBmp ,(HBITMAP)hBmp);
//delete the GDI objects
//the hBmp can't be delete, only, before be updated for don't lose them image
SelectObject(hMemDC, hBmp2);
DeleteDC(hMemDC);
//refresh the menu
//just change the menu state and put on original state
Refresh();
};
//start the timer
tmrimgmenu.Start();
}
|