I am using IOleInPlaceSiteWindowless::AdjustRect to properly capture and release the mouse in a windowless ActiveX control hosted in IE:
LRESULT CD3DControl::OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
CRect rc(CPoint(lParam), CSize(0, 0));
HRESULT hr = m_spInPlaceSite->AdjustRect(rc);
bool isInside = hr == S_OK;
TRACE("AdjustRect 0x%X, isInside=%d %d %d %d %d\n",
hr, isInside, rc.top, rc.left, rc.bottom, rc.right);
if (m_spInPlaceSite->GetCapture() == S_FALSE)
{
if (isInside)
{
hr = m_spInPlaceSite->SetCapture(TRUE);
TRACE("SetCapture(TRUE) 0x%X\n", hr);
}
}
else if (!isInside)
{
hr = m_spInPlaceSite->SetCapture(FALSE);
TRACE("SetCapture(FALSE) 0x%X\n", hr);
}
return 0;
}
When the mouse enters my control's rect things work great and the control captures the mouse. However, when my mouse leaves the control's area, AdjustRect still returns S_OK. It also returns S_OK if the mouse hovers over a div that covers part of my control.
These results are not consistent with the AdjustRect documentation.
To debug this further, I re-wrote OnMouseMove:
LRESULT CD3DControl::OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
CRect rc(0, 0, 2000, 2000);
HRESULT hr = m_spInPlaceSite->AdjustRect(&rc);
bool isInside = hr == S_OK;
TRACE("AdjustRect 0x%X, isInside=%d %d %d %d %d\n",
hr, isInside, rc.top, rc.left, rc.bottom, rc.right);
return 0;
}
In this case, AdjustRect also returns S_OK, but the rectangle isn't adjusted at all! It is still (0,0)x(2000,2000).