Get the Extent of the CContainerItem Object from the Server

To get the extent of the CContainerItem object from the server, and update the m_rect of the container item, implement the helper function CContainerItem::UpdateFromServerExtent.

To get the extent of a CContainerItem object

  1. In ClassView, right-click the class CContainerItem.

  2. From the pop-up menu, click Add Member Function.

  3. Fill in the Add Member Function dialog box as follows:
    • In the Function Type box, type void.

    • In the Function Declaration box, type the following:
      UpdateFromServerExtent()
      
    • Under Access, select Public.

    • Click OK.
  4. In ContainerItem.cpp, implement the helper function by entering the following code:
    CSize size;
    if (GetCachedExtent(&size))
    {
    // OLE returns the extent in HIMETRIC units -- we need pixels
    CClientDC dc(NULL);
    dc.HIMETRICtoDP(&size);
    
    // only invalidate if it has actually changed and also only
    // if it is not in-place active.
    if (size != m_rect.Size() && !IsInPlaceActive())
    {
    // invalidate old, update, invalidate new
    InvalidateItem();
    m_rect.bottom = m_rect.top + size.cy;
    m_rect.right = m_rect.left + size.cx;
    InvalidateItem();
    
    // mark document as modified
    GetDocument()->SetModifiedFlag();
    }
    }