Thanks friends! Everything worked out! Special thanks to the programmer mega, your example helped me a lot! I will lay out a code sample, in case who faces a similar task. This code displays an animation with a transparent background on the screen, sequentially going through the images:
//ΠΎΠ±ΡΡΠ²ΠΈΠΌ ΠΈΠ΄Π΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΎΡΡ Π΄Π»Ρ ΠΊΠ°ΡΡΠΈΠ½ΠΎΠΊ ΡΠ°ΠΉΠ»: *.rc IDC_KISS01 RCDATA "cat\kiss_01.bmpx" IDC_KISS02 RCDATA "cat\kiss_02.bmpx" ... IDC_KISS22 RCDATA "cat\kiss_22.bmpx" ΡΠ°ΠΉΠ»: Resource.h #define IDC_KISS01 111 #define IDC_KISS02 112 ... #define IDC_KISS22 132 //ΠΊΠ»Π°ΡΡ, ΠΎΡΠ²Π΅ΡΠ°ΡΡΠΈΠΉ Π·Π° Π°Π½ΠΈΠΌΠ°ΡΠΈΡ class CAT{ public: CAT(){ STATE = "kiss"; ptSrc.x = 0; ptSrc.y = 0; } void loadAnimations(HWND hwnd, HINSTANCE hInstance, std::string nameAmim, int nCount, float sp) {//Π·Π°Π³ΡΡΠ·ΠΈΠΌ ΠΊΠ°ΠΆΠ΄ΡΡ ΠΊΠ°ΡΡΠΈΠ½ΠΊΡ-ΠΎΠ±ΡΠ΅ΠΊΡ Π² ΡΡΡΡΠΊΡΡΡΡ Π΄Π°Π½Π½ΡΡ
Π΄Π»Ρ ΡΠ°Π±ΠΎΡΡ Ρ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡΠΌΠΈ hwndAnim = hwnd; speed = sp; HGDIOBJ hBitmap; HRSRC hRSrc; HGLOBAL hRes; BITMAPFILEHEADER *pRes; BITMAPINFOHEADER *bi; void *bits, *premultiply; std::vector<alpha> v; int id; if (nameAmim == "kiss") id = 111; for (int i = 0; i < nCount; i++){ // load resource hRSrc = FindResource(hInstance, MAKEINTRESOURCE(id++), RT_RCDATA); hRes = LoadResource(hInstance, hRSrc); pRes = (BITMAPFILEHEADER*)LockResource(hRes); bi = (BITMAPINFOHEADER*)(pRes + 1); bits = ((char*)pRes) + pRes->bfOffBits; // premultiply premultiply = malloc(bi->biHeight * bi->biWidth * sizeof(RGBQUAD)); for (int c = bi->biHeight * bi->biWidth; c--;) { RGBQUAD &src = ((LPRGBQUAD)bits)[c]; RGBQUAD &dst = ((LPRGBQUAD)premultiply)[c]; dst.rgbRed = (BYTE)MulDiv(src.rgbRed, src.rgbReserved, 255); dst.rgbGreen = (BYTE)MulDiv(src.rgbGreen, src.rgbReserved, 255); dst.rgbBlue = (BYTE)MulDiv(src.rgbBlue, src.rgbReserved, 255); dst.rgbReserved = src.rgbReserved; } a.hdcScreen = GetDC(HWND_DESKTOP); // prepare bitmap hBitmap = CreateCompatibleBitmap(a.hdcScreen, bi->biWidth, bi->biHeight); a.hdcMem = CreateCompatibleDC(a.hdcScreen); hBitmap = SelectObject(a.hdcMem, hBitmap); SetDIBitsToDevice( a.hdcMem, 0, 0, bi->biWidth, bi->biHeight, 0, 0, 0, bi->biHeight, premultiply, (BITMAPINFO*)bi, DIB_RGB_COLORS ); a.sizeWnd.cx = bi->biWidth; a.sizeWnd.cy = bi->biHeight; free(premultiply); // prepare window memset(&a.blend, 0, sizeof(a.blend)); a.blend.BlendOp = AC_SRC_OVER; a.blend.SourceConstantAlpha = 255; a.blend.AlphaFormat = AC_SRC_ALPHA; v.push_back(a); }//for //cleanup ReleaseDC(HWND_DESKTOP, a.hdcScreen); //hBitmap = SelectObject(a.hdcMem, hBitmap); DeleteDC(a.hdcMem); //DeleteObject(hBitmap); //Π² Π½Π΅ΠΊΠΎΡΠΎΡΡΡ
ΡΠ»ΡΡΠ°ΡΡ
ΠΌΠΎΠ³ΡΡ Π±ΡΡΡ Π½Π΅ ΡΠΎΡΠ½ΡΠ΅ ΡΠ°ΡΡΠ΅ΡΡ, Ρ.ΠΊ. ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ ΡΠ°Π·ΠΌΠ΅ΡΡ ΠΏΠΎΡΠ»Π΅Π΄Π½Π΅ΠΉ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ width = a.sizeWnd.cx; heigth = a.sizeWnd.cy; animations.insert(std::pair<std::string, std::vector<alpha>>(nameAmim, v)); } void playAnim() {//ΠΏΡΠΎΠΈΠ³ΡΡΠ²Π°Π΅ΠΌ Π°Π½ΠΈΠΌΠ°ΡΠΈΡ ΠΈΠ· ΡΠ°ΠΉΠΌΠ΅ΡΠ° currAnim += 1 * speed; //!!! Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ ΠΏΠ΅ΡΠ΅Π½Π΅ΡΡΠΈ Π² ΡΡΠ°ΡΡΠΎΠΊ, Π³Π΄Π΅ ΠΏΡΠΎΠΈΡΡ
ΠΎΠ΄ΠΈΡ ΡΠΌΠ΅Π½Π° ΡΠΎΡΡΠΎΡΠ½ΠΈΡ int cout = animations[STATE].size(); a = animations[STATE][(int)currAnim]; UpdateLayeredWindow(hwndAnim, a.hdcScreen, &ptPos, &a.sizeWnd, a.hdcMem, &ptSrc, 0, &a.blend, ULW_ALPHA); if ((int)currAnim >= cout - 1) currAnim = 0; } void setPos(int &x, int &y) { ptPos.x = x; ptPos.y = y; } private: struct alpha {//ΡΡΡΡΠΊΡΡΡΠ° Π΄Π°Π½Π½ΡΡ
Π·Π°Π³ΡΡΠΆΠ°Π΅ΠΌΡΡ
ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠ΅ BLENDFUNCTION blend; HDC hdcScreen, hdcMem; SIZE sizeWnd; }a; float speed, currAnim; std::map<std::string, std::vector<alpha>> animations; std::string STATE;//stand, kiss HWND hwndAnim; POINT ptPos, ptSrc; int width, heigth;//w\h img };
PS This example uses the loadAnimations () function which is taken from the example: How to load an image with an alpha channel into the background of the window
png/giftobmpxformat. And how to downloadbmpx- described in detail in the answer (with a working exe and project) - mega