Sizing OLE 2.0 Objects and OLEMISC_RECOMPOSEONRESIZE

ID: Q114014

The information in this article applies to:

SUMMARY

Some server applications want to have their presentation displayed differently based on the size of the object in the container application. For example, if version 6.0 of Microsoft Word For Windows is used as a server application, Word for Windows will rewrap the text of an object based on the object size in the container. This is accomplished in a server application by setting the OLEMISC_RECOMPOSEONRESIZE bit in the MiscStatus bits.

However, for setting the OLEMISC_RECOMPOSEONRESIZE bit to work, the container application must properly implement its sizing code by honoring the OLEMISC_RECOMPOSEONRESIZE bit returned by IOleObject::GetMiscStatus().

MORE INFORMATION

To properly honor the OLEMISC_RECOMPOSEONRESIZE bit, the container needs to check the MiscStatus bits by calling IOleObject::GetMiscStatus(). Once the status bits are retrieved, the container can then check to see if the OLEMISC_RECOMPOSEONRESIZE bit is set. If the bit is set, then the server wishes to be notified every time the object size changes in the container. To inform the server application the object has been resized, the container needs to call IOleObject::SetExtent() to set the new size of the object. However, IOleObject::SetExtent() only works while the object is in the running state. The container application should check if the object is already in a running state by calling the OleIsRunning() function. This is important because the container needs to restore the state of the object once the operation is complete. If the object was not in the running state, OleRun() needs to be called such that the IOleObject::SetExtent() call takes effect. At this point the IOleObject::SetExtent() method call can be made, and should be followed with a call to IOleObject::Update() to update the presentation of the object in the container. Finally, if this section of code ran the server, then it needs to transition the server back to the loaded state by calling IOleObject::Close().

NOTE: Some container applications may want to come up with a more elaborate scheme for keeping servers running. Starting and stopping servers is an expensive process, so the container application might come up with a way to keep the last X (X being application specific) servers held in the running state.

The following code is a simple implementation for the container:

// Pass this function a pointer to the object's IOleObject interface,
// the Aspect that has changed size, and the new size of the object.
// returns TRUE if the object had the Recompose on Resize bit set.

BOOL fChkResize(LPOLEOBJECT lpObject, DWASPECT dwAspect, LPSIZEL lpsizel) {
    DWORD dwStatus = 0; // For the status bits
    BOOL fShutdown = FALSE;  // don't shut the object down
    BOOL retval = FALSE;

    // Get the status bits.
    lpObject->GetMiscStatus(DVASPECT_CONTENT, &dwStatus);

    // is recompose on resize set?
    if ( dwStatus & OLEMISC_RECOMPOSEONRESIZE )
        {
        retval = TRUE;  // the bit was set

        // if the object isn't running, start the object and remember.
        if (!OleIsRunning(lpObject)
            {
            OleRun(lpObject);
            fShutdown = TRUE;
            }

        // set the extent
        lpObject->SetExtent(dwAspect, lpsizel);

        // update the cache
        lpObject->Update();

        // go back to the loaded state only if the object was in the
        // loaded state upon entry to this function.
        if (fShutdown)
            lpObject->Close(OLECLOSE_SAVEIFDIRTY);
        }
    return retval;
}

Additional reference words: 2.00 2.01 3.50 4.00 KBCategory: kbole kbprg KBSubcategory: LeTwoPrs

Last Reviewed: May 17, 1995