Edit

How to Provide Windowless Rich Edit Controls with Window Functionality

Window functionality includes the ability to receive messages and the ownership of a device context into which to draw. Windowless rich edit controls receive this functionality by way of a pair of interfaces: ITextServices and ITextHost.

What you need to know

Technologies

Prerequisites

  • C/C++
  • Windows User Interface Programming

Instructions

Establish the Window Functionality

The following example code demonstrates how to create the text host and text services.

    HRESULT hr;
    
    IUnknown* pUnk               = NULL;
    ITextServices* pTextServices = NULL;
    
    // Create an instance of the application-defined object that implements the ITextHost interface.
    TextHost* pTextHost = new TextHost();
    
    if (pTextHost == NULL) 
        goto errorHandler;

    // Create an instance of the text services object.
    hr = CreateTextServices(NULL, pTextHost, &pUnk);
    
    if (FAILED(hr))
        goto errorHandler;
        
    // Retrieve the IID_ITextServices interface identifier from Msftedit.dll. 
    IID* pIID_ITS = (IID*) (VOID*) GetProcAddress(hmodRichEdit, "IID_ITextServices");
               
    // Retrieve the ITextServices interface.    
    hr = pUnk->QueryInterface(*pIID_ITS, (void **)&pTextServices);
    
    if (FAILED(hr))
        goto errorHandler;

Remarks

The hmodRichEdit parameter in the code example is a handle to the Msftedit.dll module, and it is assumed that this handle has already been retrieved by a call to the GetModuleHandle function.

Complete example

Using Windowless Rich Edit Controls

Using Rich Edit Controls

Windows common controls demo (CppWindowsCommonControls)