这个项目是win32程序,就一个目标文件。

class CEventSink :public CComObjectRootEx <CComSingleThreadModel>, public IDispatch 实现了网页接口的事件接收器。

class CMain :public CWindowImpl <CMain> 窗口主要界面,快照的实现(获得网页接口对象)。

快照实现部分:

//
// Implementation of CMain::SaveSnapshot
//
BOOL CMain::SaveSnapshot(void)
{
long bodyHeight, bodyWidth, rootHeight, rootWidth, height, width;CComPtr<IDispatch> pDispatch;// TODO: "If the document object type is not safe for scripting,
// this method returns successfully but sets ppDisp to NULL. For
// Internet Explorer 7 and later, the return code is S_FALSE..."//获得对象
HRESULT hr = m_pWebBrowser->get_Document(&pDispatch);if (FAILED(hr))
return true;//获得ihtml接口
CComPtr<IHTMLDocument2> spDocument;
hr = pDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&spDocument);if (FAILED(hr))
return true;//获得内容
CComPtr<IHTMLElement> spBody;
hr = spDocument->get_body(&spBody);// Apparently with MSHTML failing to get the body is not a failure,
// so if there is no HTML body to get, which may be the case with
// SVG images loaded directly, this succeeds but sets spBody to the
// NULL pointer, leading to a crash. I am not sure how to obtain
// the sizing information for SVG documents so this errors out here.
// A work around would be the make HTML host documents or wrapping
// the SVG code in a XHTML document, but that may break scripts.
if (FAILED(hr) || spBody == NULL)
return true;//查找相关接口
CComPtr<IHTMLElement2> spBody2;
hr = spBody->QueryInterface(IID_IHTMLElement2, (void**)&spBody2);if (FAILED(hr))
return true;hr = spBody2->get_scrollHeight(&bodyHeight);if (FAILED(hr))
return true;hr = spBody2->get_scrollWidth(&bodyWidth);if (FAILED(hr))
return true;CComPtr<IHTMLDocument3> spDocument3;
hr = pDispatch->QueryInterface(IID_IHTMLDocument3, (void**)&spDocument3);if (FAILED(hr))
return true;// We also need to get the dimensions from the <html> due to quirks
// and standards mode differences. Perhaps this should instead check
// whether we are in quirks mode? How does it work with IE8?
CComPtr<IHTMLElement> spHtml;
hr = spDocument3->get_documentElement(&spHtml);if (FAILED(hr))
return true;CComPtr<IHTMLElement2> spHtml2;
hr = spHtml->QueryInterface(IID_IHTMLElement2, (void**)&spHtml2);if (FAILED(hr))
return true;hr = spHtml2->get_scrollHeight(&rootHeight);if (FAILED(hr))
return true;hr = spHtml2->get_scrollWidth(&rootWidth);if (FAILED(hr))
return true;width = bodyWidth;
height = rootHeight > bodyHeight ? rootHeight : bodyHeight;// TODO: What if width or height exceeds 32767? It seems Windows limits
// the window size, and Internet Explorer does not draw what's not visible.
::MoveWindow(m_hwndWebBrowser, 0, 0, width, height, TRUE);CComPtr<IViewObject2> spViewObject;// This used to get the interface from the m_pWebBrowser but that seems
// to be an undocumented feature, so we get it from the Document instead.
hr = spDocument3->QueryInterface(IID_IViewObject2, (void**)&spViewObject);if (FAILED(hr))
return true;RECTL rcBounds = { 0, 0, width, height };_TCHAR* tcsExt = _tcsrchr(m_fileName, '.');
if (tcsExt && _tcscmp(_T(".emf"), tcsExt) == 0) {USES_CONVERSION;
HDC hdcMain = GetDC();
int iWidthMM = GetDeviceCaps(hdcMain, HORZSIZE);
int iHeightMM = GetDeviceCaps(hdcMain, VERTSIZE);
int iWidthPels = GetDeviceCaps(hdcMain, HORZRES);
int iHeightPels = GetDeviceCaps(hdcMain, VERTRES); Gdiplus::RectF rcBoundsX(0, 0,
(Gdiplus::REAL)width, (Gdiplus::REAL)height);rcBoundsX.Y      *= iHeightMM * 100 / iHeightPels;
rcBoundsX.X      *= iWidthMM  * 100 / iWidthPels;
rcBoundsX.Width  *= iWidthMM  * 100 / iWidthPels;
rcBoundsX.Height *= iHeightMM * 100 / iHeightPels; Gdiplus::Metafile emf(T2W(m_fileName), hdcMain, rcBoundsX,
Gdiplus::MetafileFrameUnitGdi, Gdiplus::EmfTypeEmfPlusDual,
L"[TODO: Description]");//获得图片
Gdiplus::Graphics g(&emf);
HDC imgDc = g.GetHDC();// For unknown reasons Internet Explorer will sometimes
// fail to draw glyphs for certain characters here even
// though they are rendered in Internet Explorer itself.
// On other pages, Internet Explorer will simply render
// a single bitmap into the emf which isn't really what
// this should do. I've no idea how to fix that however.hr = spViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, imgDc,
imgDc, &rcBounds, NULL, NULL, 0);g.ReleaseHDC(imgDc);
ReleaseDC(hdcMain);return false;
}CImage image;// TODO: check return value;
// TODO: somehow enable alpha
image.Create(width, height, 24);HDC imgDc = image.GetDC();
hr = spViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, imgDc,
imgDc, &rcBounds, NULL, NULL, 0);
image.ReleaseDC();//保存
if (SUCCEEDED(hr))
hr = image.Save(m_fileName);return false;
}

学习的目的是成熟!~

源码下载

开源项目之在线网页截图工具 IECapt相关推荐

  1. phantomjs实现免费在线网页截图工具-toolfk程序员在线工具网

    本文要推荐的[ToolFk]是一款程序员经常使用的线上免费测试工具箱,ToolFk 特色是专注于程序员日常的开发工具,不用安装任何软件,只要把内容贴上按一个执行按钮,就能获取到想要的内容结果.Tool ...

  2. html2canvas 一个强大的使用js开发的浏览器网页截图工具

    html2canvas是一个JavaScript类库,它使用了html5和css3的一些新功能特性,实现了在客户端对网页进行截图的功 能.html2canvas通过获取页面的DOM和元素的样式信息,并 ...

  3. Linux webkit截图,CutyCapt 跨平台使用 WebKit 内核网页截图工具 - 文章教程

    CutyCapt 是一个跨平台的命令行工具,用来捕获 WebKit 内核渲染的页面,可生成各种矢量图和位图格式,包括 PDF.SVG.PNG.JPEG.PS.TIFF.GIF.BMP 等.和 IECa ...

  4. 阿里好的开源项目有哪些(善用工具)

    阿里好的开源项目有哪些(善用工具) 一.总结 一句话总结:善用工具,可以极大的提升开发效率. 1.阿里好的开源项目自己目前可能用得上的有哪些(举两个)? JSON处理器 fastjson 开源数据库A ...

  5. 网页截图工具CutyCapt

    网页截图工具CutyCapt CuteCapt是Kali Linux提供的一款网页截图工具.该工具运行在命令行中,可以将WebKit引擎解析的网页保存为图片.它保存的文件支持矢量图和位图两大类型,共1 ...

  6. 网页截图工具WebThumb

    不要误解,我说的网页截图,是指把整个网页转化成jpg图片的形式,以往的网页截图工具有一个弊端就是只能截出浏览器窗口内的图片,这个小工具解决了这个问题 1.看一下由它生成的微软官网图片,右键下载下来查看 ...

  7. 网页截图工具 php+IECapt

    IECapt可以将捕获网页,生成BMP.JPEG 或 PNG格式的图片,包含C++和C#两种版本,不足是依赖于Internet Explorer,这就决定了它只能在Windows下使用.IECapt是 ...

  8. GitHub 开源的 MySQL 在线更改 Schema 工具【转】

    本文来自:https://segmentfault.com/a/1190000006158503 原文:gh-ost: GitHub's online schema migration tool fo ...

  9. Snipaste在线离线截图工具的安装!1

    在很多时候我们都需要在离线的情况下进行截图,今天来介绍一下比较有用的,功能强大的截图工具Snipaste! 首先,在官网https://zh.snipaste.com/下载Snipaste 然后,将压 ...

最新文章

  1. 第十四周项目二-两个成员的类模版(1)
  2. Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AV
  3. 她,既是一个风华绝代的演员,更是WiFi之母...
  4. 公式之美:打通复杂思维的任督二脉
  5. Django REST FRAMEWORK swagger(一)框架详解
  6. 【OpenCV应用】python处理行李图像匹配项目——图像特征点
  7. PyTorch搭建简单神经网络实现回归和分类
  8. mysql 索引长度解释及不使用索引的一种特殊情况
  9. 程序员面试金典——1.1确定字符互异
  10. CSS3渐变(Gradients)-线性渐变
  11. mysql的粒度_MySQL中权限的粒度和时效性
  12. 计算机抓取整个屏幕的按键,技术员搞定电脑截全屏快捷键【搞定方法】
  13. Firemonkey Control的TabStop处理
  14. 工厂智能化远程运营管理系统方案
  15. 电脑一启动吃鸡就重启计算机,玩吃鸡老是重启电脑
  16. windows桌面图标全部不见了怎么办
  17. 一种简单的PCB加温电路设计
  18. stm32f302实现斩波控制步进电机_电子产品装调与智能检测实训考核装置
  19. 【安卓学习积累】IntentService的源码分析
  20. 诸如i云保网络保险平台的内勤裁员之路在哪里?

热门文章

  1. 轧机是用计算机操作的吗,轧机生产操作流程及安全规程
  2. 如何回答面试官提问:如果你进入公司,会怎样开展工作?
  3. 苹果要求员工每周至少 3 天在公司办公,否则被开除!
  4. 校园二手平台——微信小程序
  5. 基于RHEL8的Linux基础入门学习总结笔记(附示例代码)
  6. ES文件浏览器 如何提取盒子已安装(内置)软件APK 教程
  7. Android打包混淆----APP加密防破解 + 重新签名
  8. 虹科案例丨修保时捷?戴上虹科AR眼镜,你也行!
  9. 寻迹小车驱动模块电路设计
  10. Python杨辉三角