精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>C/C++>>WINDOWS界面设计>>HTML界面>>Sample:Add Your Content to An Exist HT

主题:Sample:Add Your Content to An Exist HT
发信人: jiangsheng()
整理人: wenbobo(2002-12-27 16:00:21), 站内信件
void CAddHtmlDlg::OnAddmorehtml() 
{
IHTMLDocument2* pHTMLDocument2;
LPDISPATCH lpDispatch;
m_iFunCounter++;

// 1.
// We get a dispatch pointer to the Document
lpDispatch = m_theBrowser.GetDocument();

if (lpDispatch)
{
HRESULT hr;
hr = lpDispatch->QueryInterface(IID_IHTMLDocument2,
                            (LPVOID*)
&pHTMLDocument2);
lpDispatch->Release();
ASSERT(SUCCEEDED(hr));


IHTMLElement*  pBody;

/// 2
/// We get a pointer to the body
HRESULT nhr = pHTMLDocument2 -> get_body(&pBody);

if (FAILED(hr)) return;

CString strTexTToBeAdded;

strTexTToBeAdded += "<CENTER><H2>";
strTexTToBeAdded += "This is the added HTML</H2><BR> Note the Tags m
ust be closed within the String<BR>";
strTexTToBeAdded.Format("%<H3><FONT COLOR = BLUE>%i</H3>",str
TexTToBeAdded,m_iFunCounter);
strTexTToBeAdded +=  "</CENTER></P>";

BSTR BstrTexTToBeAdded;    // for some reason 2 piece
                            // creation of BSTR s is preferable.
BstrTexTToBeAdded =  CString(strTexTToBeAdded).AllocSysString();

/// 3.
/// We insert a string of HTML to the end of the document
      pBody->insertAdjacentHTML(L"BeforeEnd",
                           BstrTexTToBeAdded);

   SysFreeString(BstrTexTToBeAdded);

   /// 4. Release the pointer to the body
   pBody->Release();
}

/// 5. Release the pointer to the document
pHTMLDocument2->Release();

/// 6. We are now going to find the length of the page in the DOM
////    and scroll to the end of it
UINT wparam = 0l;  //Dummy Value
long lPara = 0l;   //Dummy Value
ScrollTheBrowser( wparam, lPara);
}

--
HE WHO CONTROLS THE PAST, COMMANDS THE FUTURE.
HE WHO CONTROLS THE FUTURE CONQUERS THE PAST.

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.96.44.196]

[关闭][返回]