Implementing the "Font" feature like the one in INTERNET EXPLORER

.

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



Comments

  • How to set face name ...

    Posted by Legacy on 05/04/2002 12:00am

    Originally posted by: anhthu

    It just set text size. Do you know how to set font face name ???

    Reply
  • How to intercept the contents of Homepage before showing in the IE browser without proxy?

    Posted by Legacy on 02/20/2001 12:00am

    Originally posted by: Yung-Ming Kuo

    Dear friends:

    I want to intercept and get the contents(including text and image) of homepage from Web server ,before it shows the IE browser(version 5.0).But it is not through proxy.

    And i have ability to prevent HTML document from showing the browser.

    Could you offer some suggestion or source code sample to solve my question?

    Thank you ^_^

    email:ymkuo@neural.ee.ncku.edu.tw

    by Kuo

    Reply
  • doubt

    Posted by Legacy on 01/28/2000 12:00am

    Originally posted by: shri

    In which language is the above code put up in??
    shri.

    Reply
  • request

    Posted by Legacy on 07/31/1999 12:00am

    Originally posted by: manoj


    thanking you

    Manoj@mca.vec.ac.in
    Manoj+

    Reply
  • how to make it with vb5 ?

    Posted by Legacy on 06/28/1999 12:00am

    Originally posted by: Luca

    how to make it with vb5 ? :)

    Reply
  • How to do menu ticks!

    Posted by Legacy on 05/06/1999 12:00am

    Originally posted by: uniken

    Here's how I got the ticks on the menu to work (using CHtmlView from VC6):
    
    

    in resource.h:

    #define ID_BROWSE_FONT_SMALLEST 32769
    #define ID_BROWSE_FONT_SMALL 32770
    #define ID_BROWSE_FONT_MEDIUM 32771
    #define ID_BROWSE_FONT_LARGE 32772
    #define ID_BROWSE_FONT_LARGEST 32773

    in message map:

    ON_COMMAND_RANGE(ID_BROWSE_FONT_SMALLEST, ID_BROWSE_FONT_LARGEST, OnChangeFont)
    ON_UPDATE_COMMAND_UI_RANGE(ID_BROWSE_FONT_SMALLEST, ID_BROWSE_FONT_LARGEST, OnUpdateChangeFont)

    in cpp file:

    void CBrowserView::OnUpdateChangeFont( CCmdUI* pCmdUI )
    {
    VARIANT vaZoomFactor; // input arguments
    VariantInit(&vaZoomFactor);
    ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, NULL, &vaZoomFactor);
    pCmdUI->SetCheck((int)pCmdUI->m_nID - ID_BROWSE_FONT_SMALLEST == V_I4(&vaZoomFactor));
    }
    void CBrowserView::OnChangeFont( UINT nID )
    {
    int fontSize = nID - ID_BROWSE_FONT_SMALLEST;
    VARIANT vaZoomFactor; // input arguments
    VariantInit(&vaZoomFactor);
    V_VT(&vaZoomFactor) = VT_I4;
    V_I4(&vaZoomFactor) = fontSize;
    ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, &vaZoomFactor, NULL);
    }


    Reply
  • Dots?

    Posted by Legacy on 03/09/1999 12:00am

    Originally posted by: Chris

    How do you get the radio buttons to show on the menu which shows the current selected size like in IE?

    Reply
  • Good

    Posted by Legacy on 09/30/1998 12:00am

    Originally posted by: Sriram

    Its a good article.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds