分类:
CxImage
2013-03-16 00:18
1389人阅读
收藏
举报
类似于快照功能,前提是将需要抓图的窗口移到视区之外实现隐藏,并不是将窗口属性设为不可见,我的模块是在对话框子窗体中打开ie控件,浏览到指定网站并截图。 因此主窗体生成非模态对话框,该子对话框内嵌ie控件,并将该子对话框移到可视区域之外,环境依然是VC6.0。 创建子对话框的代码: - pShowBrowser=new CShowBrowser();
- pShowBrowser->Create(IDD_SHOWBROWSER,this);
- pShowBrowser->MoveWindow(2000,1500,1024,768);
- pShowBrowser->ShowWindow(SW_SHOW);
- pShowBrowser->Navigate(www.baidu.com);
-
-
-
-
-
- void CNetTestVDlg::SaveImagetoBinary(xsd__base64Binary* pBinary)
- {
-
-
- typedef BOOL ( __stdcall *pPrintWindow )(HWND hWnd,HDC hdcBlt,UINT nFlags);
- HMODULE h;
- h = LoadLibrary( _T("user32.dll") );
- pPrintWindow p;
- if( h )
- {
- p = ( pPrintWindow )::GetProcAddress( h, "PrintWindow");
- }
-
-
- HWND hWnd=pShowBrowser->GetSafeHwnd();
- HDC hDC = ::GetWindowDC(hWnd);
- ASSERT(hDC);
-
- HDC hMemDC = ::CreateCompatibleDC(hDC);
- ASSERT(hMemDC);
-
- RECT rc;
- ::GetWindowRect(hWnd, &rc);
-
- HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, rc.right - rc.left, rc.bottom - rc.top);
- ASSERT(hBitmap);
-
- HBITMAP hOldBmp = (HBITMAP)::SelectObject(hMemDC, hBitmap);
- p(hWnd, hMemDC, 0);
-
- 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;
- ::GetDIBits(hMemDC, hBitmap, 0, bitmap.bmHeight, (BYTE*)lpbi + sizeof(BITMAPINFOHEADER), (BITMAPINFO*)lpbi, DIB_RGB_COLORS);
-
- try
- {
- CxImage image((BYTE*)lpbi,dwSize,CXIMAGE_FORMAT_BMP);
- if (image.IsValid()){
- if(!image.IsGrayScale()) image.IncreaseBpp(24);
- image.SetJpegQuality(99);
- CxMemFile memfile;
- memfile.Open();
- image.Encode(&memfile,CXIMAGE_FORMAT_JPG);
- BYTE* buffer = memfile.GetBuffer();
- long size = memfile.Size();
- int result = -1;
-
-
- xsd__base64Binary imag1;
- pBinary->__ptr = (unsigned char *)soap_malloc(pServiceSoap->soap, size);
- pBinary->__size=size;
- memset(pBinary->__ptr, 0, size);
- memcpy(pBinary->__ptr, buffer, size);
- free(buffer);
- memfile.Close();
- }
- }
- catch(CFileException* e)
- {
- e->ReportError();
- e->Delete();
- }
-
- GlobalUnlock(hDib);
- GlobalFree(hDib);
-
- ::SelectObject(hMemDC, hOldBmp);
- ::DeleteObject(hBitmap);
- ::DeleteObject(hMemDC);
- ::ReleaseDC(hWnd, hDC);
- }
|