开发者

Why CreateDIBSection returns NULL while GetLastError returns 0 when the screen solution is changed?

开发者 https://www.devze.com 2023-02-05 15:38 出处:网络
Following is my code: void Fun(int nScreenWidth, int nScreenHeight) { ... int nMemSize = nScreenWidth*nScreenHeight*3*7

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, 开发者_Python百科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 ?

0

精彩评论

暂无评论...
验证码 换一张
取 消