LRESULT CPolyCtl::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // a toggle value used to toggle control size. static int iToggleVal = 10; HRGN hRgn; WORD xPos = LOWORD(lParam); // horizontal position of cursor WORD yPos = HIWORD(lParam); // vertical position of cursor CalcPoints(m_rcPos); // Create a region from our list of points hRgn = CreatePolygonRgn(&m_arrPoint[0], m_nSides, WINDING); // If the clicked point is in our polygon then fire the ClickIn // event otherwise we fire the ClickOut event if (PtInRegion(hRgn, xPos, yPos)) Fire_ClickIn(xPos, yPos); else Fire_ClickOut(xPos, yPos); // Delete the region that we created DeleteObject(hRgn); // Toggle control size here. RECT newPos; newPos = m_rcPos; newPos.right -= iToggleVal; newPos.bottom -= iToggleVal; iToggleVal = -iToggleVal;
HRESULT hRet; CComPtr<IOleInPlaceSite> spCtlSite; hRet = InternalGetSite(IID_IOleInPlaceSite, (void**)&spCtlSite); if (SUCCEEDED(hRet)) { if (spCtlSite != NULL) { // (Try) to change control size, // provided the container cooperates. hRet = spCtlSite->OnPosRectChange (&newPos); } } return 0; } As can be seen earlier, the Polygon control attempts to resize its window every time you click the left mouse button. Accordingly, on a left button click, the control does the following:Calculates a new rectangle. Calls IOleInPlaceSite::OnPosRectChange() with that new rectangle. Resizes itself (by calling SetWindowPos() in CComControlBase::IOleInPlaceObject_SetObjectRects()) only when the container in turn calls the control's implementation of IOleInPlaceObject::SetObjectRects. The last bullet is crucial: Well behaved controls resize themselves only at the behest of the container. So, if the container doesn't cooperate, the control won't resize. ActiveX controls hosted in an Microsoft Active Template Library (ATL) 3.0 container are unable to resize themselves dynamically. The container could be a composite control or any window using ATL containment as described in the following Knowledge Base article: 192560 HOWTO: Adding ATL Control Containment Support to Any Window
{ // a toggle value used to toggle control size.
static int iToggleVal = 10; HRGN hRgn;
WORD xPos = LOWORD(lParam); // horizontal position of cursor
WORD yPos = HIWORD(lParam); // vertical position of cursor
CalcPoints(m_rcPos); // Create a region from our list of points
hRgn = CreatePolygonRgn(&m_arrPoint[0], m_nSides, WINDING); // If the clicked point is in our polygon then fire the ClickIn
// event otherwise we fire the ClickOut event
if (PtInRegion(hRgn, xPos, yPos))
Fire_ClickIn(xPos, yPos);
else
Fire_ClickOut(xPos, yPos); // Delete the region that we created
DeleteObject(hRgn);
// Toggle control size here.
RECT newPos;
newPos = m_rcPos;
newPos.right -= iToggleVal;
newPos.bottom -= iToggleVal;
iToggleVal = -iToggleVal;
HRESULT hRet;
CComPtr<IOleInPlaceSite> spCtlSite;
hRet = InternalGetSite(IID_IOleInPlaceSite, (void**)&spCtlSite);
if (SUCCEEDED(hRet))
{
if (spCtlSite != NULL)
{
// (Try) to change control size,
// provided the container cooperates.
hRet = spCtlSite->OnPosRectChange (&newPos);
}
} return 0;
}
As can be seen earlier, the Polygon control attempts to resize its window every time you click the left mouse button. Accordingly, on a left button click, the control does the following:Calculates a new rectangle.
Calls IOleInPlaceSite::OnPosRectChange() with that new rectangle.
Resizes itself (by calling SetWindowPos() in CComControlBase::IOleInPlaceObject_SetObjectRects()) only when the container in turn calls the control's implementation of IOleInPlaceObject::SetObjectRects.
The last bullet is crucial: Well behaved controls resize themselves only at the behest of the container. So, if the container doesn't cooperate, the control won't resize. ActiveX controls hosted in an Microsoft Active Template Library (ATL) 3.0 container are unable to resize themselves dynamically. The container could be a composite control or any window using ATL containment as described in the following Knowledge Base article:
192560 HOWTO: Adding ATL Control Containment Support to Any Window