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

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

Most Popular Programming Stories

More for Developers

RSS Feeds