IHTMLDocument2接口的简单操作
这几天写的程序中要用到这方面的东西,写了个很简单的例子.
- //必须包含的头文件
- #include <atlbase.h>
- #include "atlconv.h"
- #include "Mshtml.h"
- /*********************************************************************
- * 函数名称:int CErrKbaseDHtmlView::MM_FAULTKBASE& refKBaseInfo
- * 说明:刷新HTMLVIEW页面内容
- * 入口参数:
- * 空
- * 返回值:
- * int --
- * 作者: socrates
- * 时间 : 2008-08-01 15:37:39
- * 备注 :
- *********************************************************************/
- int CErrKbaseDHtmlView::RefreshPage(MM_FAULTKBASE& refKBaseInfo)
- {
- USES_CONVERSION;
- CComPtr<IHTMLDocument2>pDoc;
- CComPtr<IDispatch>spDisp;
- spDisp = GetHtmlDocument();
- CString strHtml= "<html><head><title>kcmm_errkbase</title>/
- <style type= 'text/css'><!--/
- body,td,th {font-size: 12px; color: #990000;} .style5 {color: #000099}/
- --></style></head>/
- <body><table width='732' height='490' border='1' bordercolor='#999999' bgcolor='#FFFFFF'>/
- <tr><td width='73' height='28'><span class='style5'>故障名称:</td><td width='643'>";
- strHtml += refKBaseInfo.strFaultName;
- strHtml += "</td></tr><tr><td height='27'><span class='style5'>故障类型:</td><td>";
- strHtml += refKBaseInfo.strFaultType;
- strHtml += "</td></tr><tr><td height='31'><span class='style5'>故障级别:</td><td>严重级</td></tr>/
- <tr><td height='31'><span class='style5'>影响范围:</td><td>";
- strHtml += refKBaseInfo.strFaultIncidence;
- strHtml += "</td></tr><tr><td height='62'><span class='style5'>故障来源:</td><td>1.运行复杂业务查询;2.病毒</td></tr>/
- <tr><td height='68'><span class='style5'>产生原因:</td><td>";
- strHtml += refKBaseInfo.strFaultReason;
- strHtml += "</td></tr><tr><td height='68'><span class='style5'>处理流程:</td><td>关机->重启</td></tr>/
- <tr><td height='80'><span class='style5'>处理方法:</td><td>";
- strHtml += refKBaseInfo.strHandleMethod;
- strHtml += "</td></tr><tr><td height='73'><span class='style5'>备注信息:</td><td>略</td></tr>/
- </table><marquee direction='up' align='middle' scrolldelay='120'>此知识库仅提供参考信息,并非是最全威信息<br>/
- 如有其他问题,请联系金证工程师<br>联系方式:dyx1024@gmail.com</marquee></body></html>";
- CRect rc;
- GetClientRect(&rc);
- CString strIn;
- strIn = strHtml;
- CComQIPtr<IPersistStreamInit> spPersistStream(spDisp);
- if(spPersistStream==NULL)
- return 0;
- LPTSTR lpMem = (LPTSTR)::GlobalAlloc(GPTR,strIn.GetLength()+1);
- lstrcpy(lpMem,strIn.GetBuffer(strIn.GetLength()));
- CComPtr<IStream>spStream;
- CreateStreamOnHGlobal( lpMem, TRUE, &spStream );
- // 初始化后,装载显示
- spPersistStream->InitNew();
- spPersistStream->Load(spStream );
- return 0;
- }
- /*********************************************************************
- * 函数名称:BOOL PreTranslateMessage(MSG* pMsg)
- * 说明:屏蔽HTMLVIEW页面的右键功能
- * 入口参数:
- * 空
- * 返回值:
- * int --
- * 作者: socrates
- * 时间 : 2008-08-01 15:37:39
- * 备注 :
- *********************************************************************/
- BOOL CErrKbaseDHtmlView::PreTranslateMessage(MSG* pMsg)
- {
- if(!m_bDisplay)//屏蔽与否的开关
- {
- switch(pMsg->message)
- {
- case WM_CONTEXTMENU:
- case WM_RBUTTONUP:
- case WM_RBUTTONDOWN:
- case WM_RBUTTONDBLCLK:
- if(IsWindow(pMsg->hwnd))
- {
- if(pMsg->wParam == WM_RBUTTONUP)
- {
- GetParent()->SendMessage(WM_CONTEXTMENU, pMsg->wParam, pMsg->lParam);
- }
- return TRUE;
- }
- }
- }
- return CHtmlView::PreTranslateMessage(pMsg);
- }
不积跬步,无以至千里;不积小流,无以成江海。