Hi,
Can RichEdit use the built-in Windows API for spell checking ?
Hi,
Can RichEdit use the built-in Windows API for spell checking ?
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.
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.
#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 NILSaludos,
Carlos Gallego
*** FWH-25.12, xHarbour 1.3.1 Build 20241008, Borland C++7.70, PellesC, ADS 11.1***
Natter wrote: Hi,https://forums.fivetechsupport.com/viewtopic.php?p=260179#p260179
Can RichEdit use the built-in Windows API for spell checking ?
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 nOldSetMETHOD 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 nOldSetThank you all! I'll try !