透明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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值