線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1587
推到 Plurk!
推到 Facebook!

GetDIBits 無法秀出浮動輸入法的視窗

尚未結案
rogan321
高階會員


發表:21
回覆:307
積分:200
註冊:2003-05-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-04-24 14:13:52 IP:61.219.xxx.xxx 訂閱
如下面的函式,所抓取的 螢幕圖像都無法秀出 浮動輸入法視窗.是什麼原因
有誰知道嗎?
[code cpp]
void CopyScreen(const char *pFilePath)
{
HDC hDisplay = CreateDC(("DISPLAY"), NULL, NULL, NULL);
int nScreenWidth = GetDeviceCaps(hDisplay, HORZRES);
int nScreenHeight = GetDeviceCaps(hDisplay, VERTRES);

HDC hMemDc = CreateCompatibleDC(hDisplay);
HBITMAP hBmp = CreateCompatibleBitmap(hDisplay, nScreenWidth, nScreenHeight);
HBITMAP hOldBmp = (HBITMAP)SelectObject(hMemDc, hBmp);

BOOL blnReturnValue = BitBlt(hMemDc, 0, 0, nScreenWidth, nScreenHeight, hDisplay, 0, 0, SRCCOPY);
hBmp = (HBITMAP)SelectObject(hMemDc, hOldBmp);
DeleteDC(hMemDc);
hMemDc = NULL;
int nBits = GetDeviceCaps(hDisplay, BITSPIXEL);
DWORD dwLineBits = 0;
switch (nBits)
{
case 16:
dwLineBits = nScreenWidth*2;
break;
case 24:
dwLineBits = (nScreenWidth 1)*3-((nScreenWidth 1)*3)%4;
break;
case 32:
dwLineBits = nScreenWidth*4;
break;
default:
;
break;
}
DWORD dwBitsCount = dwLineBits * nScreenHeight;
DWORD dwFileSize = sizeof(BITMAPFILEHEADER) sizeof(BITMAPINFOHEADER) dwBitsCount;
BYTE * pMem = (BYTE *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, dwFileSize);
if (NULL == pMem)
{
;
return;
}
BITMAPFILEHEADER* pBMPHeader = (BITMAPFILEHEADER*)pMem;
BITMAPINFOHEADER* pInfoHeader = (BITMAPINFOHEADER*)((BYTE *)pBMPHeader sizeof(BITMAPFILEHEADER));
BYTE* pBits = (BYTE*)pInfoHeader sizeof(BITMAPINFOHEADER);

pBMPHeader->bfType = ('M'<<8) | 'B';
pBMPHeader->bfSize = dwFileSize;
pBMPHeader->bfReserved1 = 0;
pBMPHeader->bfReserved2 = 0;
pBMPHeader->bfOffBits = sizeof(BITMAPFILEHEADER) sizeof(BITMAPINFOHEADER);

pInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
pInfoHeader->biWidth = nScreenWidth;
pInfoHeader->biHeight = nScreenHeight;
pInfoHeader->biPlanes = GetDeviceCaps(hDisplay, PLANES);
pInfoHeader->biBitCount = nBits;
pInfoHeader->biCompression = BI_RGB;
pInfoHeader->biSizeImage = dwBitsCount;
pInfoHeader->biXPelsPerMeter = GetDeviceCaps(hDisplay, LOGPIXELSX);
pInfoHeader->biYPelsPerMeter = GetDeviceCaps(hDisplay, LOGPIXELSY);
pInfoHeader->biClrUsed = 0;
pInfoHeader->biClrImportant = 0;

int nLines = GetDIBits(hDisplay, hBmp, 0, nScreenHeight,
pBits,
(BITMAPINFO *)pInfoHeader,
DIB_RGB_COLORS);
if (0 == nLines)
{
return;
}
DeleteDC(hDisplay);
hDisplay = NULL;
DeleteObject(hBmp);
hBmp = NULL;
DeleteObject(hOldBmp);
hOldBmp = NULL;
DeleteFile(pFilePath);
HANDLE hFile = CreateFile(pFilePath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if(NULL == hFile || INVALID_HANDLE_VALUE == hFile)
{
return;
}
DWORD dwWriteCount = 0;
if(!WriteFile(hFile, (void *)pBMPHeader, dwFileSize, &dwWriteCount, NULL))
{
CloseHandle(hFile);
return;
}
CloseHandle(hFile);
GlobalFree((void *)pBMPHeader);
}

[/code]
系統時間:2017-12-13 13:37:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!