当屏幕解决方案更改时,为什么 CreateDIBSection 返回 NULL 而 GetLastError 返回 0?
以下是我的代码:
void Fun(int nScreenWidth, int nScreenHeight)
{
...
int nMemSize = nScreenWidth*nScreenHeight*3*7
HDC hdc = ::GetDC(hWnd);
int hBmpMapFile = ::CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, nMemSize, NULL);
BITMAPINFO bmpInfo = {0};
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = 7*nScreenWidth;
bmpInfo.bmiHeader.biHeight = nScreenHeight;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 24;
bmpInfo.bmiHeader.biCompression = 0;
bmpInfo.bmiHeader.biSizeImage = nMemSize;
bmpInfo.bmiHeader.biXPelsPerMeter = 0;
bmpInfo.bmiHeader.biYPelsPerMeter = 0;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
bmpInfo.bmiColors[0].rgbBlue = 204;
bmpInfo.bmiColors[0].rgbGreen = 204;
bmpInfo.bmiColors[0].rgbRed = 204;
bmpInfo.bmiColors[0].rgbReserved = 0;
PVOID pvBits = NULL;
HBITMAP hBmpWallpaper = ::CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, &pvBits, hBmpMapFile, 0);
DWORD dwErr = ::GetLastErr();
...
}
我的操作系统是windows xp,屏幕分辨率是1024*768,调用函数:
Fun(1024, 768);
我发现CreateDIBSection返回NULL,而GetLastErr()返回0。但是当屏幕分辨率是2048*1536时,调用函数:
Fun(2048, 1536);
我发现 CreateDIBSection 返回一个有效的句柄。
为什么 ?
似乎屏幕分辨率导致 CreateDIBSection 返回无效值,我不知道为什么。
但在某些 WINXP 中,无论屏幕分辨率如何,CreateDIBSection 总是成功。 从测试来看,我认为原因与HDC有关。 HDC与屏幕分辨率有关吗?
Following is my code:
void Fun(int nScreenWidth, int nScreenHeight)
{
...
int nMemSize = nScreenWidth*nScreenHeight*3*7
HDC hdc = ::GetDC(hWnd);
int hBmpMapFile = ::CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, nMemSize, NULL);
BITMAPINFO bmpInfo = {0};
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = 7*nScreenWidth;
bmpInfo.bmiHeader.biHeight = nScreenHeight;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 24;
bmpInfo.bmiHeader.biCompression = 0;
bmpInfo.bmiHeader.biSizeImage = nMemSize;
bmpInfo.bmiHeader.biXPelsPerMeter = 0;
bmpInfo.bmiHeader.biYPelsPerMeter = 0;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
bmpInfo.bmiColors[0].rgbBlue = 204;
bmpInfo.bmiColors[0].rgbGreen = 204;
bmpInfo.bmiColors[0].rgbRed = 204;
bmpInfo.bmiColors[0].rgbReserved = 0;
PVOID pvBits = NULL;
HBITMAP hBmpWallpaper = ::CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, &pvBits, hBmpMapFile, 0);
DWORD dwErr = ::GetLastErr();
...
}
My OS is windows xp, the screen resolution is 1024*768, call the function:
Fun(1024, 768);
I found that CreateDIBSection returns NULL while GetLastErr() reuturn 0. But when the screen resolution is 2048*1536, call the function:
Fun(2048, 1536);
I found that CreateDIBSection returns a valid handle.
Why ?
It seems that screen resolution causes that CreateDIBSection reuturn invalid value, I do not know why.
But in some WINXP, CreateDIBSection always successes whatever the screen resoultion is.
From the test, I think that the cause is about HDC. Is the HDC related with the screen resolution ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论