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

  • You probably have several goals for your patient portal of choice. Is "community" one of them? With a bevy of vendors offering portal solutions, it can be challenging for a hospital to know where to start. Fortunately, YourCareCommunity helps ease the decision-making process. Read this white paper to learn more. "3 Ways Clinicians can Leverage a Patient Portal to Craft a Healthcare Community" is a published document owned by www.medhost.com

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds