|
Good day..
I know it's quite a long shot, but I have this problem.. And I've ran out of places to ask for help for..
I am supposed to make my webbrowser control scroll depending on what scrollType I pass. Well, everything worked fine... that is, in IE6.
My code crashes in IE7 at get_parentWindow, get_scrollHeight (and perhaps also in scrollBy). They all return access violations.
Trying other solutions on the net didn't help, IE7 still crashes with calling functions (like get_scrollTop and etc)... I already tried scrolling using IHTMLElement2. But no luck... I also tried IHTMLDocument3->get_documentElement and used that for scrolling, still... no sunshine in sight.
well, it probably is an IE thing, but do u by chance know a way to work around this? it's really not good to just restrict users from using my scrolling functions if they don't use ie6.
i am kinda desperate now.
will be forever grateful for the help.
BOOL CBrowserControl::Scroll(LONG scrollType)
{
CComPtr<IDispatch> spDoc;
long scrollPos;
m_spWebBrowser->get_Document(&spDoc);
IHTMLDocument2 *pDocument = NULL;
HRESULT hresult = spDoc->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
IHTMLElement *pBody = NULL;
hresult = pDocument->get_body( &pBody );
IHTMLTextContainer *pElement = NULL;
hresult = pBody->QueryInterface(IID_IHTMLTextContainer,(void**)&pE lement);
IHTMLWindow2 *pWindow = NULL;
hresult = pDocument->get_parentWindow( &pWindow );
long scrollwidth, scrollheight;
pElement->get_scrollHeight(&scrollheight);
pElement->get_scrollWidth(&scrollwidth);
long page;
m_spWebBrowser->get_Height(&page);
switch(scrollType)
{
case StepDown:
scrollPos = page/5;
break;
case StepUp:
scrollPos = -page/5;
break;
case PageDown:
scrollPos = page;
break;
case PageUp:
scrollPos = -page;
break;
case ScrollBottom:
scrollPos = scrollheight;
break;
case ScrollTop:
scrollPos = -scrollheight;
break;
}
pWindow->scrollBy( 0, scrollPos );
return true;
}
modified on Friday, October 15, 2010 7:57 AM
|
|
|
|
|
When I download and install the psdk ,there is no this file.And add this file to the psdk's dir,confict with others,why?thx!
I am not a genius, but shed more sweat!
|
|
|
|
|
Has anyone used this code with IE 7 or 8? The IHTMLElement2 code given here is not working for me with newer versions of IE however the non-IHTMLElement2 code provided by a poster did work. However this version doesn't seem to support getting the current scroll position which is what I need. I'm trying to determine if the problem is with a change in newer versions of IE or somewhere else. If anyone has used this code with new versions of IE that would at least answer that question.
|
|
|
|
|
If anyone else has this problem this method worked for me. Using Java script:
var scrolltop = document.body.scrollTop + document.documentElement.scrollTop;
The body.scrollTop wasn't working either due to the version of IE or to elements on the page. One of these is guaranteed to be 0 and the other should return the proper value. Set scroll position using put_scrollTop also works.
In C++ it would be something like:
IDispatch *pDisp = m_Browser.GetDocument();
ASSERT( pDisp ); //if NULL, we failed
// get document interface
IHTMLDocument2 *pDocument = NULL;
hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
ASSERT( SUCCEEDED( hr ) );
ASSERT( pDocument );
// take the body element from document...
//
IHTMLElement *pBody = NULL;
hr = pDocument->get_body( &pBody );
ASSERT( SUCCEEDED( hr ) );
ASSERT( pBody );
// from body we can get element2 interface,
// which allows us to do scrolling
IHTMLElement2 *pElement = NULL;
hr = pBody->QueryInterface(IID_IHTMLElement2,(void**)&pElement);
ASSERT(SUCCEEDED(hr));
ASSERT( pElement );
IHTMLDocument3 *pDocument3 = NULL;
IHTMLElement2 *pElement2 = NULL;
hr = pDisp->QueryInterface( IID_IHTMLDocument3, (void**)&pDocument3 );
ASSERT( SUCCEEDED( hr ) );
ASSERT( pDocument3 );
IHTMLElement *docelmt = NULL;
hr = pDocument3->get_documentElement(&docelmt);
ASSERT( SUCCEEDED( hr ) );
ASSERT( docelmt );
hr = docelmt->QueryInterface(IID_IHTMLElement2,(void**)&pElement2);
ASSERT(SUCCEEDED(hr));
ASSERT( pElement2 );
// now we are ready to scroll
long crvsrollpos,crvsrollpos2,scrolltop;
hr = pElement->get_scrollTop( &crvsrollpos );
hr = pElement2->get_scrollTop( &crvsrollpos2 );
scrolltop=crvsrollpos+crvsrollpos2;
// scroll down to 100th pixel from top
hr = pElement->put_scrollTop( 100 );
hr = pElement2->put_scrollTop( 100 );
|
|
|
|
|
Hi, I'm having a similar problem with scrolling a html document in the CppWebBrowser component. Do you have some ideas how to do it in c++ builder 6?
Chriz
|
|
|
|
|
When I open a html ,which has a Applet, by the WebBrowser Control (the Control is hosted in a Dialog-based Application ) ,I got some error
("Free block 0x**** modified after it was freed")
What's the reason ?
colin
|
|
|
|
|
|
Thanks for saving me valuable time .
To scroll to the bottom with CDHtmlDialog, simply call the CDhtmlFunction GetInterface memberfunction
IHTMLElement2 *pElement = NULL;
if(SUCCEEDED(GetElementInterface(_T("SpanList"),IID_IHTMLElement2,(void**)&pElement)))
{
long lHeight;
pElement->get_scrollHeight(&lHeight);
pElement->put_scrollTop(lHeight);
pElement->Release();//It's not a smart pointer
}
Tout programme dont la fiabilité dépend de l'homme n'est pas fiable
|
|
|
|
|
Hi,
I need to change the size (width not the scroll range) of scroll bar shown in the Web Browser control.
Does any body have any idea how to do this ???
Thanx
Wasif
|
|
|
|
|
Unfortunately i had the same problem but it seems to be impossible, maybe you could make your own (either MFC control or Javascript)
Tout programme dont la fiabilité dépend de l'homme n'est pas fiable
|
|
|
|
|
My project is SDI. In MyProView, I use CDC pointer to TextOut string in multiline. So, I need use scrolling to view each page. Please, help me how to use Scrollbar or give me some same small application.
Thanks very much.
don't stop me now!!!
|
|
|
|
|
does any one know how to seperate pictures or any resource files from webbrowser control? i want to seperate and save them as seperate file. any idea?
hi,i am an engeneer and studieng now.meet me at talk_wert@yahoo.com
|
|
|
|
|
Hi,
I am trying to get it done using C#, but I am not going anywhere...
can anyone help me.
Any hints pls.
( I already have a simple WebBrowser Object, I need to get the position of the Scroll Bar)
|
|
|
|
|
IHTMLDocument2 htmlDoc = (IHTMLDocument2)m_browser.Document;
htmlDoc.parentWindow.scroll(100, 100);
|
|
|
|
|
With that code I'm getting a compilation error:
Cannot convert type 'System.Windows.Forms.HtmlDocument' to 'mshtml.IHTMLDocument2'.
Any ideas?
|
|
|
|
|
Scroll to absolute position [adapted from C# example]
webbrowser1.document.window.parent.scrollto(x,y)
But:
Anyone know how to get the current 'y', so one could scroll relative to the current position?
|
|
|
|
|
There is also a HtmlElement.ScrollIntoView Method in .NET 2.0, very useful .
|
|
|
|
|
This is how you do it in C# using VS 2005:
Add a COM reference in your project to mshtml (shows up as "Microsoft HTML Object Library" in the Add Reference dialog).
Add the following to your buttonDown Clicked handler:
private void buttonDown_Click(object sender, EventArgs e)
{
HtmlDocument doc = webBrowser1.Document;
if (doc == null)
return;
mshtml.IHTMLDocument2 htmlDoc = (mshtml.IHTMLDocument2)doc.DomDocument;
htmlDoc.parentWindow.scrollBy(0, 100);
}
|
|
|
|
|
1.As you know IE or Any browser use HTTP Connection they first download the main page and then links in them , our Internet connection is slow and i want to be be it fast browser so i want that HTML page text content is dowloaded and rendered and stop at that moment as gif's or Jpeg files eat the time to download , i am using IE ctrl in my application to atomate for some purpose, i tried to stop in OnNavigateComplete2WebBrowser but it not work , i found article in MSDN in (Reusing the WebBrowser Control) and found the following section i copied from MSDN
(Download Control:-
Hosts can control certain aspects of downloading, such as frames, images, Java, and so on, by implementing an ambient property defined as DISPID_AMBIENT_DLCTL. When the host'sIDispatch::Invoke method is called with dispidMember set to DISPID_AMBIENT_DLCTL, it should place zero or a combination of the following values in pvarResult...)
2.i am writing direct mailer, so it need MX record finding , that is done if you have you DNS Server address known , i hear that GetNetworkParam works but in online MSDN it is given to include "iphlpapi.h" and this and "iphlpapi.lib" but these i not find in our VC++ 6.0 Enterprise edition library.
3.How to scroll data in CScrolView window greater than 32k lines , i tried by bypassing the Scrollmsgs using hooks,it works but not smoothly , as VC++ binary editor|RichEdit scroll > 32k
|
|
|
|
|
Thank for your good work.It works well.
But now i have got a problem. can we get the whole height & width the scroll bar will scroll?
Does anybody could help me out?? thank you
|
|
|
|
|
Hi,
I want to be able switch on and off the execution of ActiveX controls in my code. Does anyone know how this is possible?
Thanks
|
|
|
|
|
I am facing a problem catching the scroll bar events in CHtmlView class. I have tried to use the OnScroll() method of the view class but it does not seems to work at all. If anyone know the way, please help me out of this problem.
regards
Humphrey Chakma
|
|
|
|
|
After the scroll bar is moved by clicking mouse manually, how to get scroll bar position information in program?
|
|
|
|
|
You can write the code below to get the scroll bar position....
HRESULT hr;
// get the document dispatch from browser
IDispatch *pDisp = GetHtmlDocument();
ASSERT( pDisp ); //if NULL, we failed
IHTMLDocument2 *pDocument = NULL;
hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
ASSERT( SUCCEEDED( hr ) );
ASSERT( pDocument );
IHTMLElement *pBody = NULL;
hr = pDocument->get_body( &pBody );
ASSERT( SUCCEEDED( hr ) );
ASSERT( pBody );
// from body we can get element2 interface,
// which allows us to do scrolling
IHTMLTextContainer *pContainer = NULL;
hr = pBody->QueryInterface(IID_IHTMLTextContainer,(void**)&pContainer);
ASSERT(SUCCEEDED(hr));
ASSERT( pContainer );
CPoint ScrollPos;
pContainer->get_scrollTop(&ScrollPos.x);
pContainer->get_scrollLeft(&ScrollPos.y);
CString str;
str.Format("Top: %ld, Left: %ld", ScrollPos.x, ScrollPos.y);
AfxMessageBox(str);
pDisp->Release();
Hope this will do for you.
Humphrey Chakma
|
|
|
|
|
Here is a version of the code that does not require the updated SDK. This version works with the default Visual C++ 6.0 installation.
HRESULT hr;
// get the document dispatch from browser
IDispatch *pDisp = wBrowser.GetDocument();
ASSERT( pDisp ); //if NULL, we failed
IHTMLDocument2 *pDocument = NULL;
hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
ASSERT( SUCCEEDED( hr ) );
ASSERT( pDocument );
IHTMLWindow2 *pWindow = NULL;
hr = pDocument->get_parentWindow( &pWindow );
ASSERT( SUCCEEDED( hr ) );
ASSERT( pWindow );
pWindow->scrollBy( 0, delta );
pDisp->Release();
|
|
|
|