打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
抓窗口的图片
/*
void CVideoPlayerPropPage::OnBnClickedButtonCatchImg()
{
//初始化Buffer
CWnd* pImgWnd = FromHandle(m_ImgWnd->m_hWnd);

HWND hDesktop = ::GetDesktopWindow();
ASSERT(hDesktop);
if(NULL == m_ImgWnd->m_hWnd)
{
m_ImgWnd->m_hWnd = hDesktop;
}
RECT rect;
::GetWindowRect(m_ImgWnd->m_hWnd, &rect);

int nWidht = rect.right - rect.left;
int nHeight = rect.bottom - rect.top;

//修改截图宽度,字节对齐
int nNum = nWidht % 4;
if (nNum != 0)
{
nWidht += (4 - nNum);
}

InitBih(m_bih, nWidht, nHeight, 24);

BYTE* pBuffer = new BYTE[m_bih.biWidth * m_bih.biHeight * 3 + 10];
BITMAPINFOHEADER bih = m_bih;

HDC hSrcDC = ::GetWindowDC(m_ImgWnd->m_hWnd);
ASSERT(hSrcDC);
HDC hMemDC = ::CreateCompatibleDC(hSrcDC);
ASSERT(hMemDC);
HBITMAP hBitmap = ::CreateCompatibleBitmap(hSrcDC, nWidht, nHeight);
ASSERT(hBitmap);
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hMemDC, hBitmap);

::BitBlt(hMemDC, 0, 0, nWidht, nHeight, hSrcDC, 0, 0, SRCCOPY);

BITMAP bitmap = {0};
::GetObject(hBitmap, sizeof(BITMAP), &bitmap);
BITMAPINFOHEADER bi = {0};
BITMAPFILEHEADER bf = {0};

CONST int nBitCount = 24;
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bitmap.bmWidth;
bi.biHeight = bitmap.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = nBitCount;
bi.biCompression = BI_RGB;
DWORD dwSize = ((bitmap.bmWidth * nBitCount + 31) / 32) * 4 * bitmap.bmHeight;
HANDLE hDib = GlobalAlloc(GHND, dwSize + sizeof(BITMAPINFOHEADER));
LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
*lpbi = bi;

int nRet = ::GetDIBits(hMemDC, hBitmap, 0, bitmap.bmHeight, (BYTE*)lpbi + sizeof(BITMAPINFOHEADER), (BITMAPINFO*)lpbi, DIB_RGB_COLORS);

int nRes = GetLastError();

memcpy(pBuffer, (BYTE*)((BITMAPINFO*)lpbi)->bmiColors, ((BITMAPINFO*)lpbi)->bmiHeader.biSizeImage);

//memcpy(pBuffer,(BYTE*)((BITMAPINFO*)lpbi)->bmiColors,m_bih.biWidth * m_bih.biHeight * 3);
bih.biBitCount = 24;
bih.biSizeImage = m_bih.biWidth * m_bih.biHeight * 3;

CString strMpdulePath = GetModuleFileDirectory() + "\\CatchPic\\";
MakeSureDirExist(strMpdulePath);
CString strName = strMpdulePath +  GetCatchPicName();
WriteJpgFile(strName, bih, pBuffer);

::SelectObject(hMemDC, hOldBitmap);
::DeleteObject(hBitmap);
::DeleteDC(hMemDC);
::ReleaseDC(m_ImgWnd->m_hWnd, hSrcDC);

VARIANT arg[1];
arg[0].vt = VT_BSTR;
arg[0].bstrVal = _bstr_t(strName);
VARIANT pvarRet;
if (m_jsCallback)
{
m_jsCallback.InvokeN(static_cast<DISPID>(DISPID_VALUE), arg, 1, &pvarRet);
}
else
{
TTRACE("js 没设置回调函数 !!!! \r\n");
}
}
*/

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
窗口截图(二)
http://hi.baidu.com/chendeping/item/707721df3...
CreateCompatibleDC,CreateCompatibleBitmap,SelectObject详解
保存MFC的CBitmap对象中的图象到一个BMP文件中
vc 保存Bitmap到文件
将屏幕保存为图片 将当前MFC程序保存为图片
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服