Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Webbrowser Control - Button coordinates


Hi,

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?

Karl
0
gammae
Asked:
gammae
1 Solution
 
keydCommented:
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;

CComBSTR bsID;

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 );
                        break;
                  }
            }
      }
}

and a link about elements measuring and positioning:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/om/measuring.asp

Good luck,
keyd.
0
 
gammaeAuthor Commented:
Thanks a lot ofr the solution, I'll try to implement that in my project. The points were well deserved.

Karl
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now