问题描述
亲爱的所有人,
我有一个问题:如何获得每个应用程序的表面......
这意味着我想获取每个应用程序窗口的内容。
我使用GDI函数获取窗口句柄并获得它的DC
我使用下面的代码并传递g_FGWnd到这个函数来获得DC。
但它是有线的,它在Win 7 32位操作系统上运行良好。
但是无法获得Win8 64位的操作系统,我构建32位应用程序和64位应用程序。
它仍然不能。
我无法在Win8下获得IE浏览器。
并且可以'在播放视频时使用Windows Media Player。它检索一个带有白色背景的黑色块。
Windows Media Player包含Win 7和Win 8.
有人知道为什么它是?
谢谢。
CPaintDC dc(g_FGWnd);
CRect rect;
g_FGWnd-> GetClientRect(& rect);
bmpWin.CreateCompatibleBitmap(& dc,rect.Width(),rect.Height());
memDC.CreateCompatibleDC(& dc);
memDC.SelectObject(& bmpWin);
memDC.BitBlt(0,0,rect.Width(),rect.Height(),& dc,0,0,SRCCOPY | CAPTUREBLT);
CFile文件;
CFileException e;
if(!file.Open(dlg.GetPathName(),CFile :: modeWrite | CFile :: modeCreate,& e))
{
e.ReportError() ;
返回;
}
BITMAP bmp;
bmpWin.GetBitmap(& bmp);
WORD wColorBits = bmp.bmBitsPixel * bmp.bmPlanes;
if(wColorBits == 1)
wColorBits = 1;
else if(wColorBits< = 4)
wColorBits = 4;
else if(wColorBits< = 8)
wColorBits = 8;
else if(wColorBits< = 16)
wColorBits = 16;
else if(wColorBits< = 24)
wColorBits = 24;
其他wColorBits = 32;
PBITMAPINFO pBitmapInfo;
pBitmapInfo =(PBITMAPINFO)_alloca(sizeof(BITMAPINFOHEADER)+ sizeof(RGBQUAD)*(1<< wColorBits));
memset(pBitmapInfo,0,sizeof(BITMAPINFOHEADER));
pBitmapInfo-> bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pBitmapInfo-> bmiHeader.biWidth = bmp.bmWidth;
pBitmapInfo-> bmiHeader.biHeight = bmp.bmHeight;
pBitmapInfo-> bmiHeader.biPlanes = bmp.bmPlanes;
pBitmapInfo-> bmiHeader.biBitCount = bmp.bmBitsPixel;
if(wColorBits< 24)
pBitmapInfo-> bmiHeader.biClrUsed =(1<<< wColorBits);
pBitmapInfo-> bmiHeader.biCompression = BI_RGB;
pBitmapInfo-> bmiHeader.biSizeImage =((pBitmapInfo-> bmiHeader.biWidth * wColorBits +31)& ~31)/ 8 * pBitmapInfo-> bmiHeader.biHeight;
pBitmapInfo-> bmiHeader.biClrImportant = 0;
LPBYTE pBits =(LPBYTE)malloc(pBitmapInfo-> bmiHeader.biSizeImage);
if(!GetDIBits(
memDC,
bmpWin,
0,
pBitmapInfo-> bmiHeader.biHeight,
pBits,
pBitmapInfo,
DIB_RGB_COLORS))
{
AfxMessageBox(Error al crear el Bitmap);
免费(pBits);
返回;
}
BITMAPFILEHEADER fileHeader;
fileHeader.bfType = 0x4d42;
fileHeader.bfSize =(DWORD)sizeof(BITMAPFILEHEADER)
+ pBitmapInfo-> bmiHeader.biSizeImage
+ pBitmapInfo-> bmiHeader.biClrUsed * sizeof(RGBQUAD)
+ pBitmapInfo - > bmiHeader.biSize;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER)
+ pBitmapInfo-> bmiHeader.biClrUsed * sizeof(RGBQUAD)
+ pBitmapInfo-> bmiHeader.biSize;
尝试
{
file.Write(
(LPVOID)& fileHeader,
sizeof(BITMAPFILEHEADER));
file.Write(
(LPVOID)pBitmapInfo,
sizeof(BITMAPINFOHEADER)+ pBitmapInfo-> bmiHeader.biClrUsed * sizeof(RGBQUAD));
file.Write(
(LPVOID)pBits,
(UINT)pBitmapInfo-> bmiHeader.biSizeImage);
file.Close();
}
catch(CFileException * e)
{
e-> ReportError();
e->删除();
file.SetLength(0);
}
免费(pBits);
Dear All,
I have a question that is : How can I get each application's surface..
That means I want to get each application windows' contents.
I use GDI function to get window handle and get it's DC
I use below code and pass g_FGWnd to this funtion to get DC.
But it is wired, it works fine at Win 7 32bit OS.
But can't get Win8 64 bit's OS, I build both 32bit app and 64bit app.
It still can't.
I can't get IE under Win8.
And can't get Windows Media Player when using it playing a video. it retrieve a black block with white background.
Windows Media Player is consist on both Win 7 and Win 8.
Could Someone know why it was?
Thanks.
CPaintDC dc(g_FGWnd); CRect rect; g_FGWnd->GetClientRect(&rect); bmpWin.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()); memDC.CreateCompatibleDC(&dc); memDC.SelectObject(&bmpWin); memDC.BitBlt(0, 0, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY|CAPTUREBLT); CFile file; CFileException e; if(!file.Open(dlg.GetPathName(), CFile::modeWrite | CFile::modeCreate, &e)) { e.ReportError(); return; } BITMAP bmp; bmpWin.GetBitmap(&bmp); WORD wColorBits = bmp.bmBitsPixel * bmp.bmPlanes; if (wColorBits == 1) wColorBits = 1; else if (wColorBits <= 4) wColorBits = 4; else if (wColorBits <= 8) wColorBits = 8; else if (wColorBits <= 16) wColorBits = 16; else if (wColorBits <= 24) wColorBits = 24; else wColorBits = 32; PBITMAPINFO pBitmapInfo; pBitmapInfo = (PBITMAPINFO) _alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (1 << wColorBits)); memset(pBitmapInfo, 0, sizeof(BITMAPINFOHEADER)); pBitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pBitmapInfo->bmiHeader.biWidth = bmp.bmWidth; pBitmapInfo->bmiHeader.biHeight = bmp.bmHeight; pBitmapInfo->bmiHeader.biPlanes = bmp.bmPlanes; pBitmapInfo->bmiHeader.biBitCount = bmp.bmBitsPixel; if (wColorBits < 24) pBitmapInfo->bmiHeader.biClrUsed = (1 << wColorBits); pBitmapInfo->bmiHeader.biCompression = BI_RGB; pBitmapInfo->bmiHeader.biSizeImage = ((pBitmapInfo->bmiHeader.biWidth * wColorBits +31) & ~31) / 8 * pBitmapInfo->bmiHeader.biHeight; pBitmapInfo->bmiHeader.biClrImportant = 0; LPBYTE pBits = (LPBYTE) malloc(pBitmapInfo->bmiHeader.biSizeImage); if(!GetDIBits( memDC, bmpWin, 0, pBitmapInfo->bmiHeader.biHeight, pBits, pBitmapInfo, DIB_RGB_COLORS)) { AfxMessageBox("Error al crear el Bitmap"); free(pBits); return; } BITMAPFILEHEADER fileHeader; fileHeader.bfType = 0x4d42; fileHeader.bfSize = (DWORD) sizeof(BITMAPFILEHEADER) + pBitmapInfo->bmiHeader.biSizeImage + pBitmapInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD) + pBitmapInfo->bmiHeader.biSize; fileHeader.bfReserved1 = 0; fileHeader.bfReserved2 = 0; fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + pBitmapInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD) + pBitmapInfo->bmiHeader.biSize; try { file.Write( (LPVOID) &fileHeader, sizeof(BITMAPFILEHEADER)); file.Write( (LPVOID) pBitmapInfo, sizeof(BITMAPINFOHEADER) + pBitmapInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD)); file.Write( (LPVOID) pBits, (UINT) pBitmapInfo->bmiHeader.biSizeImage); file.Close(); } catch(CFileException* e) { e->ReportError(); e->Delete(); file.SetLength(0); } free(pBits);
这篇关于如何获得每个应用程序的表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!