我用WebBrower控件,用IPersistStreamInit结构获取了当前网页的源文件,但是如果该网页是框架结构,就拿不到正确的源文件了,还有表单之类的,请教有什么解决方法吗??另一个就是如何将页面上的文字信息全部得到,比如CTRA+A复制下来粘贴到记事本里的。
等..............................待
等..............................待
解决方案 »
- 控件的OnPaint不停刷新?加CPaintDC dc就没事?
- 大家为什么还用VC啊?
- 在这种情况下如何在VC中使用Word??
- 一个简单的dll问题
- 如何在 win XP 中添加自己做的输入法?
- KL变换的疑问,自相关矩阵和协方差矩阵
- 听说MsFlexGrid可以处理Dao类型,请教如何显示出access数据库中的内容?===UP UP UP===
- 我请教各位计算机事业上的老大哥,为了与你们一样,我得如何学喃?按照啥顺序学?学那些??
- xhtwtpdc来拿分
- 谁告诉我如何在NT中隐藏自身进程?答对给全分(CB,VC都行)
- 急问一个截屏的问题,用Direct3D如何捉取指定窗口的屏幕?(注意可不是桌面啊!)
- **************彩票中奖50,庆贺之~*****************
http://weborama.blogspot.com/2004/09/mshtml-hosting-odds-ends.html
If you want to limit the HTML to just what a user has selected, instead of the entire document, we can use the IHTMLXxx COM interfaces. The first thing you need to do is get access to the IHTMLDocument interface for the current document. IWebBrowser2 gives you access using it's Document property. The Document property returns an IDispatch interface, so we need to QueryInterface the IDispatch interface for an IHTMLDocument interface, like so (raw C++):
IDispatch* pDocDisp = 0;
HRESULT hr = pWebBrowser->get_Document(&pDocDisp);IHTMLDocument2* pDoc = 0;
hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
if (SUCCEEDED(hr)) { //... pDoc->Release();
}pDocDisp->Release();The IHTMLXxx interfaces follow the W3C DOM specification used for JavaScript very closely. If your familiar with those objects, the IHTMLXxx interface will be easy to grasp. In fact, if you know how to do something using JavaScript, you can duplicate it your compiled code using the IHTMLXxx interfaces. That said, you can get the current selection as a IHTMLTxtRange from the document element. Once you have a text range, you can retrieve the plain text or HTML text as shown below:
IHTMLDocument2* pDoc = ...;IHTMLSelectionObject* pSelection = 0;
HRESULT hr = pDoc->get_selection(&pSelection);
if (SUCCEEDED(hr)) {
IDispatch* pDispRange = 0;
hr = pSelection->createRange(&pDispRange);
if (SUCCEEDED(hr)) {
IHTMLTxtRange* pTextRange = 0;
hr = pDispRange->QueryInterface(IID_IHTMLTxtRange, (void**)&pTextRange);
if (SUCCEEDED(hr)) {
CComBSTR sText;
pTextRange->get_text(&sText);
// or
pTextRange->get_htmlText(&sText);
//...
pTextRange->Release();
}
pDispRange->Release();
}
pSelection->Release();
}pDoc->Release();