Webbrowser Control - Button coordinates


I have a dialog that contain a webbrowser control. The html loaded in the control display a button (<input type=button id=mybutton>).

I can get the coordinate of the webbrowser control using GetWindowRect, however I can't figure any way to find the coordinate of the button.

Can anyone suggest a way to accomplish that?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hello Karl,

You need something like this,
the code is not final and not tested, but i believe you can change it for your needs.

// replace with your WebBrowser pointer
CComPtr<IWebBrowser2> spBrowser;

long top = 0;
long left = 0;

CComPtr<IDispatch> spDocDisp;
spBrowser->get_Document( &spDocDisp );
if( !spDocDisp )
      return false;

CComQIPtr<IHTMLDocument2> spDoc( spDocDisp );
if( !spDoc )
      return false;

CComPtr<IHTMLElementCollection> spElements;
spDoc->get_all( &spElements );
if( !spElements )
      return false;

CComBSTR bsTagName( "button" );
CComVariant vtButton( bsTagName );
CComPtr<IDispatch> spButtonsDisp;
spElements->tags( vtButton, &spButtonsDisp );
if( !spButtonsDisp )
      return false;
CComQIPtr<IHTMLElementCollection> spButtonElements( spButtonsDisp );
if( !spButtonElements )
      return false;


long count = 0;
spButtonElements->get_length( &count );
for( int i = 0; i < count; ++i )
      CComVariant vtIndex( i );
      CComPtr<IDispatch> spButtonDisp;
      if( SUCCEEDED( spButtonElements->item( vtIndex, vtIndex, &spButtonDisp ) ) )
            CComQIPtr<IHTMLButtonElement> spButton( spButtonDisp );
            if( spButton )
                  CComQIPtr<IHTMLElement> spButtonEl1( spButtonDisp );
                  spButtonEl1->get_id( &bsID );
                  if( bsID == "mybutton" )
                        CComQIPtr<IHTMLElement2> spButtonEl2( spButtonDisp );
                        spButtonEl2->get_clientTop( &top );
                        spButtonEl2->get_clientLeft( &left );

and a link about elements measuring and positioning:

Good luck,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gammaeAuthor Commented:
Thanks a lot ofr the solution, I'll try to implement that in my project. The points were well deserved.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.