GDI+ / PNG 实现半透明窗口,正常情况下没有问题 将系统设置为16位色后UpdateLayeredWindow函数失败,GetLastError返回8(ERROR_NOT_ENOUGH_MEMORY)
2009-07-24 15:25
639 查看
问题出在你创建的Bitmap上,一般情况下用CreateCompatibleBitmap来创建,但是这时候创建的Bitmap跟DC走了,是16位色的,这样就会丢失了Alpha通道。所以应该这样:
RECT rtWnd;
hWnd = GetSafeHwnd();
if(hWnd == NULL)
break;
if(!::GetWindowRect(hWnd, &rtWnd))
break;
hWndDC = ::GetDC(hWnd);
if(hWndDC == NULL)
break;
hMemDC = ::CreateCompatibleDC(hWndDC);
if(hMemDC == NULL)
break;
//hMemBitmap = ::CreateCompatibleBitmap(hWndDC, rtWnd.right - rtWnd.left, rtWnd.bottom - rtWnd.top); ////这样就会失败
BYTE* pBits = NULL;
BITMAPINFOHEADER bmih = { sizeof (BITMAPINFOHEADER) };
bmih.biWidth = rtWnd.right - rtWnd.left;
bmih.biHeight = rtWnd.bottom - rtWnd.top ;
bmih.biPlanes = 1 ;
bmih.biBitCount = 32; //这里一定要是32
bmih.biCompression = BI_RGB ;
bmih.biSizeImage = 0 ;
bmih.biXPelsPerMeter = 0 ;
bmih.biYPelsPerMeter = 0 ;
bmih.biClrUsed = 0 ;
bmih.biClrImportant = 0 ;
hMemBitmap = CreateDIBSection (NULL, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (VOID**)&pBits, NULL, 0) ;
if(hMemBitmap == NULL)
break;
RECT rtWnd;
hWnd = GetSafeHwnd();
if(hWnd == NULL)
break;
if(!::GetWindowRect(hWnd, &rtWnd))
break;
hWndDC = ::GetDC(hWnd);
if(hWndDC == NULL)
break;
hMemDC = ::CreateCompatibleDC(hWndDC);
if(hMemDC == NULL)
break;
//hMemBitmap = ::CreateCompatibleBitmap(hWndDC, rtWnd.right - rtWnd.left, rtWnd.bottom - rtWnd.top); ////这样就会失败
BYTE* pBits = NULL;
BITMAPINFOHEADER bmih = { sizeof (BITMAPINFOHEADER) };
bmih.biWidth = rtWnd.right - rtWnd.left;
bmih.biHeight = rtWnd.bottom - rtWnd.top ;
bmih.biPlanes = 1 ;
bmih.biBitCount = 32; //这里一定要是32
bmih.biCompression = BI_RGB ;
bmih.biSizeImage = 0 ;
bmih.biXPelsPerMeter = 0 ;
bmih.biYPelsPerMeter = 0 ;
bmih.biClrUsed = 0 ;
bmih.biClrImportant = 0 ;
hMemBitmap = CreateDIBSection (NULL, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (VOID**)&pBits, NULL, 0) ;
if(hMemBitmap == NULL)
break;
相关文章推荐
- WIN7上UpdateLayeredWindow执行失败,getlasterror返回307的问题解决方法
- 关于UpdateLayeredWindow调用失败返回0但是Getlasterror为0的问题
- UpdateLayeredWindow()失败,GetLastError()返回0
- TransactNamedPipe函数在切换线程时失败,GetLastError 返回 231。 再次 Read 成功。
- UpdateLayeredWindow实现半透明
- UpdateLayeredWindow 失败导致透明gdi+ 窗口没有被显示
- 打开虚拟串口COM18失败,GetLastError返回2
- 利用UpdateLayeredWindow函数制作透明窗口时BMP的Alpha通道的问题
- 使用UpdateLayeredWindow的窗口在某些系统上显示不出来的一个可能原因
- GetLastError函数返回值的含义
- UpdateLayeredWindow方式实现异型窗口
- WinSocket套接字关于Connect函数通过GetLastError 返回10038或者(在一个非套接字上尝试了一个操作)
- 如何解决加载动态链接库DLL失败,返回0,GetLastError返回错误码126
- CreateDirectory(…)执行失败,GetLastError()返回错误码5
- UpdateLayeredWindow实现自定义透明窗口
- 设置windows窗口半透明(使用SetLayeredWindowAttributes API函数)
- dll之loadbitmap失败 getlasterror返回1813 1814的解决
- (转)xp下实现窗体透明特效/异形窗口SetLayeredWindowAttributes函数
- [GDI+]16位色下UpdateLayeredWindow失败
- Windows 的GetLastError()函数返回值之含义