Comment fournir des contrôles RichEdit sans fenêtre avec des fonctionnalités de fenêtre

La fonctionnalité de fenêtre offre la possibilité de recevoir des messages et la propriété d’un contexte de périphérique dans lequel dessiner. Les contrôles RichEdit sans fenêtre reçoivent cette fonctionnalité par le biais d’une paire d’interfaces : ITextServices et ITextHost.

Bon à savoir

Technologies

Prérequis

  • C/C++
  • Windows Programmation de l’interface utilisateur

Instructions

Établir les fonctionnalités de la fenêtre

L’exemple de code suivant montre comment créer l’hôte de texte et les services de texte.

    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;

Remarques

Le paramètre hmodRichEdit dans l’exemple de code est un handle vers le module Msftedit.dll, et il est supposé que ce descripteur a déjà été récupéré par un appel à la fonction GetModuleHandle .

Exemple complet

Utilisation de contrôles RichEdit sans fenêtre

Utilisation de contrôles RichEdit

Windows démonstration des contrôles communs (CppWindowsCommonControls)