.
A sample code to change the fonts in your web browser using webbrowser control.
void CMyBrowser::SetFont(int nFontSize)
{ m_pDisp = NULL; // IDISPATCH pointer
LPOLECOMMANDTARGET pCmdTarg = NULL;
m_pDisp = m_WebBrowser2.GetDocument(); // get the idispatch pointer from webbrowser control
ASSERT(m_pDisp); //check for validity
m_pDisp->QueryInterface(IID_IOleCommandTarget, (LPVOID*)&pCmdTarg); //query for IID_IOleCommandTarget interface
ASSERT(pCmdTarg); // check for validity
VARIANT vaFontSize; // input argumentsVariantInit(&vaFontSize);
V_VT(&vaFontSize) = VT_I4;
V_I4(&vaFontSize) = nFontSize; //size of the font you want
VARIANT vaFontOutput;
pCmdTarg->Exec(NULL, // execute just change the font
OLECMDID_ZOOM,
OLECMDEXECOPT_PROMPTUSER,
&vaFontSize,
&vaFontOutput);
VariantClear(&vaFontSize); //clear the variant variable before freeing its memory
if (pCmdTarg) pCmdTarg->Release(); // release document's command target
if (m_pDisp) m_pDisp->Release(); // release document's dispatch interface
}
Updated on May 18 1998