UpdateLayeredWindow()失败,GetLastError()返回0
来源:互联网 发布:tomcat项目多域名访问 编辑:程序博客网 时间:2024/05/22 10:47
在绘制分层窗口时,使用了如下代码段绘制分层窗口:
HDC hdcMem = ::CreateCompatibleDC();
HBITMAP hbmpMem = ::CreateCompatibleBitmap();
::SelectObject(hdcMem, hbmpMem);
/***** paint on memory dc hdcMem ****/
UpdateLayeredWindow();
使用一段时间后,发现在有一台电脑上面没有绘制出分层窗口。调试发现是因为UpdateLayeredWindow失败了。
在网上查了一下,没有找到出错的具体原因是为什么(一说是windows xp 的一个bug)。但是找到了一个替代方案:
不使用CreateCompatibleBitmap创建兼容位图,而是使用CreateDIBSection创建。
// 老的方法
// 此方法不能保证后续的UpdateLayeredWindow方法在所有系统上都生效
HBITMAP hBitMap =
::CreateCompatibleBitmap(
hdcTemp,
rcWindow.Width(),
rcWindow.Height());
#else
// 新的方法
BITMAPINFO stBmpInfo = {0};
stBmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); // the number of bytes required by the structure
stBmpInfo.bmiHeader.biWidth = rcWindow.Width(); // the width of the bitmap, in pixels
stBmpInfo.bmiHeader.biHeight = rcWindow.Height(); // the height of the bitmap, in pixels
stBmpInfo.bmiHeader.biPlanes = 1; // The count of color planes is always 1
stBmpInfo.bmiHeader.biBitCount = 32; // the number of bits-per-pixel,必须是32位,才能有透明效果
stBmpInfo.bmiHeader.biCompression = BI_RGB; // An uncompressed format
stBmpInfo.bmiHeader.biClrUsed = 0; // the number of color indexes in the color table
// that are actually used by the bitmap
stBmpInfo.bmiHeader.biSizeImage = 0; // the size, in bytes, of the image
// This may be set to zero for BI_RGB bitmaps.
HBITMAP hBitMap =
::CreateDIBSection(
hdcTemp,
&stBmpInfo,
DIB_RGB_COLORS,
NULL,
NULL,
0);
HDC hdcMem = ::CreateCompatibleDC();
HBITMAP hbmpMem = ::CreateCompatibleBitmap();
::SelectObject(hdcMem, hbmpMem);
/***** paint on memory dc hdcMem ****/
UpdateLayeredWindow();
使用一段时间后,发现在有一台电脑上面没有绘制出分层窗口。调试发现是因为UpdateLayeredWindow失败了。
在网上查了一下,没有找到出错的具体原因是为什么(一说是windows xp 的一个bug)。但是找到了一个替代方案:
不使用CreateCompatibleBitmap创建兼容位图,而是使用CreateDIBSection创建。
代码如下:
// 老的方法
// 此方法不能保证后续的UpdateLayeredWindow方法在所有系统上都生效
HBITMAP hBitMap =
::CreateCompatibleBitmap(
hdcTemp,
rcWindow.Width(),
rcWindow.Height());
#else
// 新的方法
BITMAPINFO stBmpInfo = {0};
stBmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); // the number of bytes required by the structure
stBmpInfo.bmiHeader.biWidth = rcWindow.Width(); // the width of the bitmap, in pixels
stBmpInfo.bmiHeader.biHeight = rcWindow.Height(); // the height of the bitmap, in pixels
stBmpInfo.bmiHeader.biPlanes = 1; // The count of color planes is always 1
stBmpInfo.bmiHeader.biBitCount = 32; // the number of bits-per-pixel,必须是32位,才能有透明效果
stBmpInfo.bmiHeader.biCompression = BI_RGB; // An uncompressed format
stBmpInfo.bmiHeader.biClrUsed = 0; // the number of color indexes in the color table
// that are actually used by the bitmap
stBmpInfo.bmiHeader.biSizeImage = 0; // the size, in bytes, of the image
// This may be set to zero for BI_RGB bitmaps.
HBITMAP hBitMap =
::CreateDIBSection(
hdcTemp,
&stBmpInfo,
DIB_RGB_COLORS,
NULL,
NULL,
0);
#endif
参考: UpdateLayeredWindow()失败,GetLastError()返回0
- UpdateLayeredWindow()失败,GetLastError()返回0
- 关于UpdateLayeredWindow调用失败返回0但是Getlasterror为0的问题
- WIN7上UpdateLayeredWindow执行失败,getlasterror返回307的问题解决方法
- GDI+ / PNG 实现半透明窗口,正常情况下没有问题 将系统设置为16位色后UpdateLayeredWindow函数失败,GetLastError返回8(ERROR_NOT_ENOUGH_MEMORY)
- Creat 失败,getlasterror返回10093
- LoadLibrary失败,getlasterror返回126的心得
- OpenProcess调用失败,GetLastError返回5
- CreateCompatibleBitmap返回NULL,GetLastError却返回0
- GetLastError返回
- CreateBitmapIndirect() GetLastError() 返回 错误的参数 创建失败原因
- CreateFileMapping调用失败,GetLastError返回值为1006
- CreateDirectory(…)执行失败,GetLastError()返回错误码5
- 打开虚拟串口COM18失败,GetLastError返回2
- dll之loadbitmap失败 getlasterror返回1813 1814的解决
- 打开虚拟串口COM18失败,GetLastError返回2
- [GDI+]16位色下UpdateLayeredWindow失败
- CreateWindowEx返回句柄为0, GetLastError却返回0
- getlasterror返回值大全
- 上GOOGLE搜资料的好方法
- Ubuntu 12.04 下安装MySQL 5.5
- 关于Resource temporarily unavailable in tsStartJavaThread
- Android 使activity以模式对话框的形式弹出
- 在mac上使用github--设置git
- UpdateLayeredWindow()失败,GetLastError()返回0
- 亿能测试视频教程 - QTP自动化测试视频系列
- JM8.6配置文件中参数的解释
- Android学习 StateMachine与State模式
- 黑白界面下去的小游戏
- 比较级
- __bridge,__bridge_retained和__bridge_transfer的意思,区别与使用 20 三
- hdu 3507 斜率优化dp 入门学习
- 1000个苹果放到10个相同的箱子里(不可以有空箱子) 有多少种方法