| |

VerySource

 Forgot password?
 Register
Search
View: 928|Reply: 7

How do I capture the scroll event of a WebBrowser page? (anxious!)

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-4 12:30:01
| Show all posts |Read mode
How do I capture the scroll event of a WebBrowser page? (anxious!)
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-24 08:00:01
| Show all posts
"I used AfxConnectionAdvise's method in OnDocumentComplete to connect to IHTMLWindow2 and got the event function DISPID_HTMLWINDOWEVENTS2_ONSCROLL. But this function can only get the message of the scroll event, but not the direction and distance of the scroll."

My situation is just the opposite of him. I can get the direction and distance of the scroll. I don't know how to get the event function of DISPID_HTMLWINDOWEVENTS2_ONSCROLL.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-27 12:00:02
| Show all posts
HRESULT IHTMLElement2 :: get_scrollTop (long * p);
HRESULT IHTMLElement2 :: get_scrollLeft (long * p);
HRESULT IHTMLElement2 :: get_scrollWidth (long * p);
HRESULT IHTMLElement2 :: get_scrollHeight (long * p);
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-28 15:15:01
| Show all posts
This is already available, what I want is to get the event function of DISPID_HTMLWINDOWEVENTS2_ONSCROLL
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-16 19:15:01
| Show all posts
tosiegfried008
I used your method, but got:
get_scrollTop(long *p)p is 0
get_scrollTop(long *p) p is zero
get_scrollWidth(long *p)p is the page width of the entire webpage
get_scrollHeight(long *p)p is the page height of the entire webpage
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-21 21:00:01
| Show all posts
I also want to get the DISPID_HTMLWINDOWEVENTS2_ONSCROLL time function, host, have you solved it
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-31 20:00:01
| Show all posts
RESULT hr;
IDispatch *pDisp = m_cMyWebBrowser.GetDocument();
ASSERT( pDisp ); //if NULL, we failed
To
// Get Html document pointer
IHTMLDocument2 *pDocument = NULL;
hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
ASSERT( SUCCEEDED( hr) );
ASSERT( pDocument );
To
IHTMLElement *pBody = NULL;
hr = pDocument->get_body(&pBody );
ASSERT( SUCCEEDED( hr) );
ASSERT( pBody );
To
// Obtain the IHTMLElement2 interface pointer from the body to access the scroll bar
IHTMLElement2 *pElement = NULL;
hr = pBody->QueryInterface(IID_IHTMLElement,(void**)&pElement);
ASSERT(SUCCEEDED(hr));
ASSERT( pElement );
To
IHTMLTextContainer *pCont;
pBody->QueryInterface(IID_IHTMLTextContainer, (LPVOID *)(&pCont));
ASSERT(pCont);
To
To
// scroll down 100 pixels
// pElement->put_scrollTop( 100 );
To
To
// Get the height of the scroll bar
long scroll_height;
pCont->get_scrollHeight(&scroll_height );
To
// Get the width of the scroll bar
long scroll_width;
if(FAILED(pCont->get_scrollWidth(&scroll_width )))
AfxMessageBox("get scrollWidth failed.");
To
// Get the scroll bar position, starting from the top
long scroll_top;
if(FAILED(pCont->get_scrollTop(&scroll_top )))
AfxMessageBox("get scrollWidth failed.");
// Get the scroll bar position, starting from the left end
long scroll_left;
if(FAILED(pCont->get_scrollLeft(&scroll_left )))
AfxMessageBox("get scrollWidth failed.");
To
CString str;
str.Format("%d,%d,%d,%d",scroll_height,scroll_width,scroll_top,scroll_left);
AfxMessageBox(str);
To
pCont->Release();
pElement->Release();
pBody->Release();
pDocument->Release();
pDisp->Release();



Ps: If used in the page
WEB standards will invalidate ScrollTop and ScrollLeft properties! ! ! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-1 11:15:01
| Show all posts
This is an unsolved problem that I have been unsolved. The masters are making moves.
I use the CWebBrowser2 control, so there is no ready scroll event
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list