SAMPLE: Insert OLE Object Capabilities to the RichEdit Control

Last reviewed: June 6, 1996
Article ID: Q141549
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT version 3.51
        - Microsoft Windows 95 version 4.0
        - Microsoft Win32s version 1.3
    

SUMMARY

RichEdit control supports embedding and inplace-activating OLE Objects. To add these capabilities to a RichEdit control in your application, an independent service vendor (ISV) must implement certain OLE interfaces. The RichEdit sample shows how these interfaces are implemented and other implementation details that are required in conjunction with the OLE interfaces to embed and inplace-activate OLE objects.

MORE INFORMATION

An ISV must implement the following OLE interfaces to add the embedding and inplace-activating capabilities to the RichEdit control in their application:

  • IRichEditOleCallback, which is used by a RichEdit control to retrieve OLE-related information from its client. This interface is passed by the client application to the RichEdit control via EM_SETOLEINTERFACE message. This is a RichEdit control's custom interface.
  • IOleInPlaceFrame, which is used to control the container's top-level frame window. In addition, implementing this interface involves implementing IOleWindow and IOleInPlaceUIWindow interfaces also, because IOleInPlaceFrame is inherited from IOleInPlaceUIWindow, which in turn inherits IOleWindow.

There are a few caveats that are important to enable this feature work to properly:
  • The Frame window, which will be the parent of the tool bar and status bar, needs to be created with the WS_CLIPCHILDREN style. If this style is not present, your applications will exhibit some painting problems when an object is inplace-active in your RichEdit control.
  • The RichEdit control itself should be created with WS_CLIPSIBLING style. Here too, if the style is not present, RichEdit control will exhibit painting problems when the Object creates child windows during inplace- active.
  • When destroying the RichEdit control, your application should deactivate any inplace-active Object and call IOleObject->Close() on all the embedded objects in the RichEdit control. If this is not done, some object applications may not close down, thus causing them to stay in memory, even after the RichEdit control is destroyed. Here is a code snippet that demonstrates how to handle closing of OLE Objects:

          if (m_pRichEditOle)
          {
    
             HRESULT hr = 0;
    
             //
             // Start by getting the total number of objects in the control.
             //
             int objectCount = m_pRichEditOle->GetObjectCount();
    
             //
             // Loop through each object in the control and if active
             // deactivate, and if open, close.
             //
             for (int i = 0; i < objectCount; i++)
             {
                REOBJECT reObj;
                 ZeroMemory(&reObj, sizeof(REOBJECT));
                reObj.cbStruct  = sizeof(REOBJECT);
    
                //
                // Get the Nth object
                //
                hr = m_pRichEditOle->GetObject(i,&reObj,REO_GETOBJ_POLEOBJ);
                if(SUCCEEDED(hr))
                {
                   //
                   // If active, deactivate.
                   //
                   if (reObj.dwFlags && REO_INPLACEACTIVE)
                      m_pRichEditOle->InPlaceDeactivate();
    
                   //
                   // If the object is open, close it.
                   //
                   if(reObj.dwFlags&&REO_OPEN)
                      hr = reObj.poleobj->Close(OLECLOSE_NOSAVE);
    
                      reObj.poleobj->Release();
                }
             }
             m_pRichEditOle->Release();
          }
    
    
Download Richedit.exe, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
  • The Microsoft Network

          On the Edit menu, click Go To, and then click Other Location
          Type mssupport
          Double-click the MS Software Library icon
          Find the appropriate product area
          Download Richedit.exe (size: 91225 bytes) 
    
  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download Richedit.exe (size: 91225 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the Softlib\Mslfiles directory
          Get Richedit.exe (size: 91225 bytes) 
    


Additional reference words: 4.00 1.30 softlib
KBCategory: kbui kbole kbhowto kbfile
KBSubcategory:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 6, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.