FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Spell checking
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Spell checking
Posted: Thu Sep 18, 2025 01:26 PM

Hi,

Can RichEdit use the built-in Windows API for spell checking ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Spell checking
Posted: Thu Sep 18, 2025 04:12 PM
Yes, the RichEdit control can utilize the built-in Windows Spell Checking API, particularly in versions 8.0 and later starting from Windows 8, by enabling language options like spell checking and autocorrection through messages such as EM_SETLANGOPTIONS.

This API allows developers to integrate spell checking services into edit controls, including RichEdit, for features like underlining misspelled words and providing suggestions. For example, in VB6 with InkEdit (which wraps RichEdit), you can enable it using SendMessage with flags like IMF_SPELLCHECKING to activate built-in spell checking on Windows 8 and later. The spell checking is handled out-of-process under a restricted security context, and it supports user-specific dictionaries for added, excluded, and autocorrect words. Note that some implementations, like in older Windows versions or certain controls, may require programmatic refreshing of text to apply spell checking to preloaded content. Third-party libraries or components, such as those from DevExpress or Telerik, can extend this functionality but often build on or supplement the native Windows API rather than replacing it.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Spell checking
Posted: Thu Sep 18, 2025 06:28 PM

Yes, I read it. However, I did not understand how to implement this in FW. I decided it was easier to do it in WebView.

Posts: 514
Joined: Sun Oct 16, 2005 03:32 AM
Re: Spell checking
Posted: Thu Sep 18, 2025 10:45 PM
From ChatGPT:
#include "FiveWin.ch"
#include "RichEdi5.ch"  

#define WM_USER               0x0400
#define EM_SETLANGOPTIONS     ( WM_USER + 120 )   // establecer opciones de idioma
#define EM_GETLANGOPTIONS     ( WM_USER + 121 )   // leer opciones de idioma
#define IMF_SPELLCHECKING     0x0800              // activa spell-checking (Windows 8+)
#define IMF_TKBAUTOCORRECTION 0x2000              // autocorrect touch keyboard (opcional)

#define EM_SETEDITSTYLEEX     0x04CD
#define SES_EX_AUTOCORRECT    0x00000001
#define SES_EX_AUTOSPELLCHECK 0x00000002


FUNCTION Main()
   LOCAL oWnd, oRich, hLib, nLang, cRTF := "Digita aquí el texto a corregir/subrayar:"

   hLib := LoadLibrary( "msftedit.dll" )   // devuelve 0 si falla
   IF Empty(hLib)
      hLib := LoadLibrary( "riched20.dll" )
   ENDIF

   DEFINE WINDOW oWnd TITLE "TRichEdit5: SpellCheck (IMF_SPELLCHECKING)" ;
      SIZE 700,450 PIXEL

   @ 10,10 RICHEDIT5 oRich VAR cRTF SIZE 680,380 OF oWnd

   nLang := SendMessage( oRich:hWnd, EM_GETLANGOPTIONS, 0, 0 )
  // nLang := nLang | IMF_SPELLCHECKING | IMF_TKBAUTOCORRECTION  // This syntax works in xHarbour but does not work in Harbour.
   nLang := hb_bitOr( nLang, IMF_SPELLCHECKING, IMF_TKBAUTOCORRECTION )
   SendMessage( oRich:hWnd, EM_SETLANGOPTIONS, 0, nLang )

   SendMessage( oRich:hWnd, EM_SETEDITSTYLEEX, SES_EX_AUTOSPELLCHECK, SES_EX_AUTOSPELLCHECK )
   SendMessage( oRich:hWnd, EM_SETEDITSTYLEEX, SES_EX_AUTOCORRECT,    SES_EX_AUTOCORRECT )

   ACTIVATE WINDOW oWnd CENTERED

RETURN NIL

Saludos,



Carlos Gallego



*** FWH-25.12, xHarbour 1.3.1 Build 20241008, Borland C++7.70, PellesC, ADS 11.1***

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Spell checking
Posted: Fri Sep 19, 2025 03:14 AM
Natter wrote: Hi,

Can RichEdit use the built-in Windows API for spell checking ?
https://forums.fivetechsupport.com/viewtopic.php?p=260179#p260179
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Spell checking
Posted: Fri Sep 19, 2025 09:51 AM
METHOD SetLangOptions( lOnOff, nFlagSet ) CLASS TRichEdit

   local nOldSet
   DEFAULT lOnOff   := .T.
   DEFAULT nFlagSet := nOr( IMF_SPELLCHECKING, IMF_TKBPREDICTION, IMF_TKBAUTOCORRECTION )
   nOldSet          := ::GetLangOptions()
   if lOnOff
      SendMessage( ::hWnd, EM_SETLANGOPTIONS, 0, nFlagSet )
   else
      SendMessage( ::hWnd, EM_SETLANGOPTIONS, 0, 0 )
   endif

Return nOldSet
METHOD SetLangOptions( lOnOff, nFlagSet ) CLASS TRichEdit5

   local nOldSet

   DEFAULT lOnOff   := .T.
   //DEFAULT nFlagSet := nOr( IMF_SPELLCHECKING, IMF_TKBPREDICTION, IMF_TKBAUTOCORRECTION )  //hb_BitOr

   nOldSet          := ::GetLangOptions()
   if lOnOff
      DEFAULT nFlagSet := hb_BitOr( nOldSet, IMF_SPELLCHECKING, IMF_TKBPREDICTION, IMF_TKBAUTOCORRECTION )  //
      SendMessage( ::hWnd, EM_SETLANGOPTIONS, 0, nFlagSet )
      //::SendMsg( EM_SETEVENTMASK, 0, ENM_CHANGE)
      //SysRefresh()
   else
      SendMessage( ::hWnd, EM_SETLANGOPTIONS, 0, 0 )
   endif

Return nOldSet
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Spell checking
Posted: Fri Sep 19, 2025 11:44 AM

Thank you all! I'll try !

Continue the discussion