次の方法で共有


Changing Fonts with the WebBrowser Control (Windows Embedded CE 6.0)

1/6/2010

The WebBrowser automation model does not support a method that allows you to change the font of the text of the currently displayed page. However, the WebBrowser control exposes this functionality through the IOleCommandTarget interface. As shown in the following example, you can call the IOleCommandTarget::Exec method with OLECMDID_ZOOM, using the pvaIn input argument to pass a value in the range of 0 to 5, to indicate the desired scale of the font. This mimics the functionality available through the Internet Explorer Fonts command on the View menu.

LPDISPATCH pDisp = NULL;
LPOLECOMMANDTARGET pCmdTarg = NULL;
pDisp = m_pBrowser.get_Document();
ASSERT(pDisp);
pDisp->QueryInterface(IID_IOleCommandTarget, (LPVOID*)&pCmdTarg);
ASSERT(pCmdTarg);
VARIANT vaZoomFactor;   // input arguments
VariantInit(&vaZoomFactor);
V_VT(&vaZoomFactor) = VT_I4;
V_I4(&vaZoomFactor) = fontSize;
pCmdTarg->Exec(NULL,
            OLECMDID_ZOOM,
            OLECMDEXECOPT_DONTPROMPTUSER,
            &vaZoomFactor,
            NULL);
VariantClear(&vaZoomFactor);
if (pCmdTarg)
   pCmdTarg->Release(); // release document's command target
if (pDisp)
   pDisp->Release();    // release document's dispatch interface

See Also

Other Resources

Internet Explorer Browser Control Host Application Development