生活随笔
收集整理的這篇文章主要介紹了
透明GIF图片显示控件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
透明窗體參見:
https://msdn.microsoft.com/en-us/library/ms997507.aspx
CreateWindowEx是需要設置屬性
WS_EX_LAYERED | WS_EX_TRANSPARENT
這兩個屬性很重要.
繪制操作可以參照此函數做:
OnPaint函數中響應:
void GIFStatic::DrawPNG(HWND hWnd, HDC hdc, int width, int height)
{TCHAR *pngFile = L"C:\\Users\\dyh\\Desktop\\文檔\\ico.ooopic.com.png";/********************************************* step 1.* Using Gdiplus to load the image********************************************/RECT wndRect;::GetWindowRect(hWnd, &wndRect);SIZE wndSize = { wndRect.right - wndRect.left, wndRect.bottom - wndRect.top };if (hdc == NULL) hdc = ::GetWindowDC(hWnd);HDC memDC = ::CreateCompatibleDC(hdc);HBITMAP memBitmap = ::CreateCompatibleBitmap(hdc, wndSize.cx, wndSize.cy);::SelectObject(memDC, memBitmap);Gdiplus::Image image(pngFile);Gdiplus::Graphics graphics(memDC);graphics.DrawImage(&image, 0, 0, wndSize.cx, wndSize.cy);// get screen dc HDC screenDC = hdc;POINT ptSrc = { 0, 0 };/********************************************** step 3.* Use UpdateLayeredWindow to Draw the Window**********************************************/BLENDFUNCTION blendFunction;blendFunction.AlphaFormat = AC_SRC_ALPHA;blendFunction.BlendFlags = 0;blendFunction.BlendOp = AC_SRC_OVER;blendFunction.SourceConstantAlpha = 255;UpdateLayeredWindow(hWnd, screenDC, &ptSrc, &wndSize, memDC, &ptSrc, 0, &blendFunction, 2);::DeleteDC(screenDC);::DeleteDC(memDC);::DeleteObject(memBitmap);
}完成此函數后需要使用MoveWindow函數將窗體移動回去.
否則窗體會移動至左上角落.
代碼目錄請見下面:
http://download.csdn.net/detail/ab7936573/9496109
總結
以上是生活随笔為你收集整理的透明GIF图片显示控件的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。