Help and Support
 

powered byLive Search

SAMPLE: IEZoom.exe Changes the Font Size of the WebBrowser Control

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:156693
Last Review:August 9, 2004
Revision:4.2
This article was previously published under Q156693
On This Page

SUMMARY

IEZoom.exe demonstrates how to change the font size of the text displayed in a Web Browser control embedded in an MFC container application.

Back to the top

MORE INFORMATION

The following file is available for download from the Microsoft Download Center:
IEZoom.exe (http://download.microsoft.com/download/ie4095/iezoom/1/w95/en-us/iezoom.exe)
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 (http://support.microsoft.com/kb/119591/EN-US/) How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

Microsoft Internet Explorer obtains much of its functionality from COM objects implemented in Shdocvw.dll, Mshtml.dll, and Urlmon.dll. The Internet Explorer application itself is a thin wrapper that aggregates the functionality of these components. Developers who wish to tap directly into the functionality of these underlying components are frequently interested in mimicking the functionality of Internet Explorer. While many Internet Explorer features are exposed through the Web Browser (SHDOCVW) control's automation model, other features available on the Internet Explorer menus, including changing the font size of the text of the current page, are not exposed this way. This sample demonstrates how to use the IOleCommandTarget interface to change the font size of the text of the current page displayed by a WebBrowser control.

The IOleCommandTarget interface consists of two methods, QueryStatus and Exec, in addition to the IUnknown methods. QueryStatus allows the client to determine if an object supports a particular command. If QueryStatus indicates that the specified command is enabled, the client can call Exec to execute or show Help for the command. The list of standard command identifiers is defined in the OLECMDID enumeration in the header file DOCOBJ.H. For more information on the IOleCommandTarget interface, see the Internet Client SDK online documentation. The sample is a Microsoft Foundation Classes (MFC) 4.2 SDI application that mimics the functionality of the Fonts pop-up under Internet Explorer's View menu. Both the sample and Internet Explorer provide the user with five scaling factors: largest, large, medium, small, smallest. While a page is displayed in medium by default, choosing any of the other options scales the text of the page up and down respectively. The following code taken from the sample shows how to accomplish this using the IOleCommandTarget interface:

   void CIezoomView::ChangeScale(IEScaleSize scaleSize)
   {
      HRESULT hr;

      LPDISPATCH pDisp = NULL;
      LPOLECOMMANDTARGET pCmdTarg = NULL;

      if (!m_wb.m_hWnd)
      {
         TRACE("Web Browser Control not yet created.\n")
         return;
      }

      pDisp = m_wb.GetDocument();

      if (!pDisp)
      {
         TRACE("Unable to get document from Web Browser.\n");
         return;
      }

      // The document controls the availability of commands items,
      // so get the OLE command target interface from the document
      hr = pDisp->QueryInterface(IID_IOleCommandTarget,
   (LPVOID*)&pCmdTarg);
      if (pCmdTarg)
      {
         // Now use the command target to do something useful
         // like (un-)zoom the page
         OLECMD rgCmd[1] = {{OLECMDID_ZOOM, 0}};
         // Is the command available for execution?
         hr = pCmdTarg->QueryStatus(NULL, 1, rgCmd, NULL);
         if (SUCCEEDED(hr) && OLECMDF_ENABLED == rgCmd[0].cmdf)
         {
            TRACE("Zoom enabled.\n");
            VARIANT vaZoomFactor;   // Input arguments
            VariantInit(&vaZoomFactor);
            V_VT(&vaZoomFactor) = VT_I4;
            V_I4(&vaZoomFactor) = fontSize;
            hr = pCmdTarg->Exec(NULL, OLECMDID_ZOOM,
                     OLECMDEXECOPT_DONTPROMPTUSER,
                     &vaZoomFactor, NULL);
            VariantClear(&vaZoomFactor);
         }
         else
         {
            TRACE("Unable to query for status of command ;
            (OLECMDID_ZOOM).\n");
         }
      }
      else
      {
         TRACE("Unable to get command target from Web Browser ;
         document.\n");
      }

      if (pCmdTarg) pCmdTarg->Release(); // release document's command
                                            target

      if (pDisp) pDisp->Release(); // release document's dispatch interface
   }
				

Back to the top

Steps To Run

1.Build the IEZoom sample.
2.Run the IEZoom sample. If you are connected to the Internet, the ActiveX page on www.microsoft.com will be displayed. If you do not have an Internet connection, modify the Navigate() call in CIezoomView::OnCreate() by passing a different URL.

3.From the View Menu, choose a different font selection.

Back to the top


APPLIES TO
Microsoft Internet Explorer 4.01 128-Bit Edition
Microsoft Internet Explorer 4.0 128-Bit Edition
Microsoft Internet Explorer 3.02
Microsoft Internet Explorer 3.01
Microsoft Internet Explorer 3.0

Back to the top

Keywords: 
kbdownload kbfile kbgraphic kbinfo kbsample KB156693

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.