P
Philippe Roy
I need to know where some IHTMLElement are positioned in a browser
page. I have successfully positioned them with the algorithm below.
But, I can't get it to work when the IHTMLElement is within a frame!
Would soneone be kind enough to give me a hint on how to do that?
bool CIEHlprObj::GetElementLocation(IHTMLElement *pElement, RECT
*dRect)
{
dRect->top = 0;
dRect->bottom = 0;
dRect->right = 0;
dRect->left = 0;
long dValue = 0;
IHTMLElement *curElement = pElement;
do
{
if (SUCCEEDED(curElement->get_offsetTop(&dValue)))
{
dRect->top += dValue;
}
else
{
return false;
}
if (SUCCEEDED(curElement->get_offsetLeft(&dValue)))
{
dRect->left += dValue;
}
else
{
return false;
}
IHTMLElement *parentElement = NULL;
if (SUCCEEDED(curElement->get_offsetParent(&parentElement)))
{
curElement = parentElement;
}
else
{
return false;
}
}
while (curElement != NULL);
if (SUCCEEDED(pElement->get_offsetWidth(&dValue)))
{
dRect->right = dRect->left + dValue;
}
else
{
return false;
}
if (SUCCEEDED(pElement->get_offsetHeight(&dValue)))
{
dRect->bottom = dRect->top + dValue;
}
else
{
return false;
}
return ((dRect->bottom > dRect->top) && (dRect->right > dRect->left)
&& (dRect->left >= 0) && (dRect->top >= 0));
}
page. I have successfully positioned them with the algorithm below.
But, I can't get it to work when the IHTMLElement is within a frame!
Would soneone be kind enough to give me a hint on how to do that?
bool CIEHlprObj::GetElementLocation(IHTMLElement *pElement, RECT
*dRect)
{
dRect->top = 0;
dRect->bottom = 0;
dRect->right = 0;
dRect->left = 0;
long dValue = 0;
IHTMLElement *curElement = pElement;
do
{
if (SUCCEEDED(curElement->get_offsetTop(&dValue)))
{
dRect->top += dValue;
}
else
{
return false;
}
if (SUCCEEDED(curElement->get_offsetLeft(&dValue)))
{
dRect->left += dValue;
}
else
{
return false;
}
IHTMLElement *parentElement = NULL;
if (SUCCEEDED(curElement->get_offsetParent(&parentElement)))
{
curElement = parentElement;
}
else
{
return false;
}
}
while (curElement != NULL);
if (SUCCEEDED(pElement->get_offsetWidth(&dValue)))
{
dRect->right = dRect->left + dValue;
}
else
{
return false;
}
if (SUCCEEDED(pElement->get_offsetHeight(&dValue)))
{
dRect->bottom = dRect->top + dValue;
}
else
{
return false;
}
return ((dRect->bottom > dRect->top) && (dRect->right > dRect->left)
&& (dRect->left >= 0) && (dRect->top >= 0));
}