Question : How to scroll Microsoft Web Brwoser ActiveX contorl in MFC

I have inserted Microsoft Browser ActiveX control on my dialog box. I am using it as a status window to show logs. I wanted to show pass in green and fails in red, so decided to use it as color coding is simple with html tags.
I need to show the user the latest data always, so it should scroll to the latest log i.e. end of the file every time a new log is rcvd. How can I do that?

I have a member variable in dlg class from CExplorer. Using Navigate2(...) to open the html file.

Thanks in advance...

Answer : How to scroll Microsoft Web Brwoser ActiveX contorl in MFC

I wanted to do the same thing.  I found the following code a while back, it still works.  It assumes your browser object is m_wndBrowser.  Source:http://www.fruitfruit.com/vc/ie/iehtml.cpp

HTH
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
HRESULT hr = S_OK;
LPDISPATCH pDispatch = m_wndBrowser.get_Document();
if( pDispatch != NULL )
{
	IHTMLDocument2* pHtmlDoc=NULL;
	hr = pDispatch->QueryInterface( __uuidof( IHTMLDocument2 ),(void**)&pHtmlDoc );
	IHTMLWindow2*  pWindow;
	if(pHtmlDoc!=NULL)
	{
		hr = pHtmlDoc->get_parentWindow(&pWindow);
		pHtmlDoc->Release();
	}

	ASSERT( SUCCEEDED( hr ) );
	long docheight=0;
	IHTMLElement* pe=NULL;
	pHtmlDoc->get_body(&pe);
	IHTMLTextContainer* pe2=NULL;
	if(pe!=NULL)
	{
		pe->QueryInterface(&pe2);
		pe->Release();
	}
	if(pe2!=NULL)
	{
		pe2->get_scrollHeight(&docheight);
		pe2->Release();
	}
	if(pWindow!=NULL&&docheight>0)
	{
		pWindow->scrollTo(0,docheight);
		pWindow->Release();
	}
	pDispatch->Release();
}
Random Solutions  
 
programming4us programming4us