關於無窗口豐富編輯控制件

無視窗豐富的編輯控件,也稱為文字服務物件,是一個 物件,提供豐富編輯控件 的功能,而不提供視窗。 若要提供視窗的功能,例如能夠接收訊息和可繪製的裝置內容,無視窗豐富的編輯控件會使用一對接口:ITextServicesITextHost

若要建立無視窗豐富的編輯控件,請使用 ITextHost 介面實作的指標呼叫 CreateTextServices 函式。 CreateTextServices傳回 IUnknown 指標,您可以查詢以擷取無視窗控件之 ITextServices 實作的指標

Msftedit.dll導出稱為 IID_ITextServices 的介面標識碼 (IID),以用來查詢 ITextServices 介面的 IUnknown 指標。 下列範例示範如何擷取IID_ITextServices,並用它來取得 ITextServices 介面。

    .
    .
    .
    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. The hmodRichEdit parameter is a handle to the 
    // Msftedit.dll module retrieved by a previous call to the 
    // GetModuleHandle function.
    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;
     .
     . 
     .   
     

Msftedit.dll也會導出稱為 IID_ITextHost的介面標識碼(IID),其可用來查詢 ITextHost 介面。

ITextHost 介面有無視窗控制項呼叫以擷取視窗相關信息的方法。 例如,文字服務物件會呼叫 TxGetDC 方法,以擷取可繪製的裝置內容。 無視窗控制項會 呼叫 TxNotify 方法,將豐富的編輯通知訊息等通知傳送至文字主機。 文字服務物件會呼叫其他 ITextHost 方法來要求文字主機執行其他窗口相關服務。 例如, TxInvalidateRect 方法會要求文字主機將矩形新增至視窗的更新區域。

標準的豐富編輯控制件有一個視窗程式,可處理來自您應用程式的系統訊息和訊息。 您可以使用控制元件的視窗句柄來傳送訊息來執行文字編輯和其他作業。 但是無視窗豐富的編輯控制件沒有用來接收和處理訊息的視窗程式。 相反地,它會提供 ITextServices 介面。 若要將訊息傳送至無視窗豐富的編輯控件,請呼叫 TxSendMessage 方法。 您可以使用此方法傳送任何豐富的編輯訊息,或傳遞其他會影響控件的訊息,例如滑鼠或鍵盤輸入的系統訊息。

您也可以建立文字服務物件做為 COM 匯總物件的部分。 這可讓您輕鬆地使用無視窗元件物件模型 (COM) 對象來匯總文字服務物件。