UpdateLayeredWindow 失败导致透明gdi+ 窗口没有被显示

来源:互联网 发布:詹姆斯历史赛季数据 编辑:程序博客网 时间:2024/06/16 11:56

在多屏幕应用的场景中。其中有一个屏幕启动全屏游戏应用,另一个屏幕有一个窗口调用UpdateLayeredWindow 更新窗口信息,当游戏应用为16位色时候失败。故需要修改设定参数。例子代码如下:

HDC hdctemp = ::GetDC (m_hWnd); //GetDC()->m_hDC;
HDC hdcMemory=CreateCompatibleDC(hdctemp);
HBITMAP hBitMap=CreateCompatibleBitmap(hdctemp,rect.Width(),rect.Height()/*m_BGHeight*/);


修改为

HDC hdctemp = ::GetDC (m_hWnd); //GetDC()->m_hDC;
HDC hdcMemory=CreateCompatibleDC(hdctemp);

BYTE * pBits ;
BITMAPINFOHEADER bmih;
ZeroMemory( &bmih, sizeof( BITMAPINFO ) );


bmih.biSize = sizeof (BITMAPINFOHEADER) ;
bmih.biWidth = rect.Width() ;
bmih.biHeight = rect.Height() ;
bmih.biPlanes = 1 ;
bmih.biBitCount = 32; //这里一定要是32 16位色没有alpha通道
bmih.biCompression = BI_RGB ;
bmih.biSizeImage = 0 ;
bmih.biXPelsPerMeter = 0 ;
bmih.biYPelsPerMeter = 0 ;
bmih.biClrUsed = 0 ;
bmih.biClrImportant = 0 ;


HBITMAP hBitMap = CreateDIBSection (NULL, (BITMAPINFO *) &bmih, 0, (VOID**)&pBits, NULL, 0) ;


即bitmap对象的创建不能以screen的dc来创建。

原创粉丝点击