DEFINE VARIABLE chText AS CHARACTER NO-UNDO.
DEFINE VARIABLE chrestext AS CHARACTER NO-UNDO.
DEFINE VARIABLE intHwnd AS INTEGER NO-UNDO.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.
chText = "Testimg my programm".
RUN ipSpellCheck(INPUT chtext,OUTPUT chresText).
MESSAGE chresText
VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
PROCEDURE FindWindowA EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER intClassName AS LONG.
DEFINE INPUT PARAMETER chrCaption AS CHARACTER.
DEFINE RETURN PARAMETER intHandle AS LONG.
END PROCEDURE.
PROCEDURE BringWindowToTop EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER intClassName AS LONG.
DEFINE RETURN PARAMETER intHandle AS LONG.
END PROCEDURE.
PROCEDURE ipSpellCheck:
DEFINE INPUT PARAMETER ipchText AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER opchtext AS CHARACTER NO-UNDO.
DEFINE VARIABLE wordAppl AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chDocument AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE cTitle AS CHARACTER NO-UNDO.
CREATE "Word.Application" wordAppl.
chDocument = wordAppl:Documents:ADD().
wordAppl:Documents:ITEM(1):range(0,0):insertAfter(ipchText).
wordAppl:OPTIONS:CheckGrammarWithSpelling = TRUE.
wordAppl:VISIBLE = TRUE.
cTitle = chDocument:NAME + " - " + wordAppl:NAME.
RUN FindWindowA(0,cTitle,OUTPUT intHwnd).
IF intHwnd <> 0 THEN
RUN BringWindowToTop(INTHwnd, OUTPUT intResult).
wordAppl:VISIBLE = FALSE.
wordAppl:documents:ITEM(1):checkGrammar().
wordAppl:VISIBLE = FALSE.
opchText = wordAppl:documents:ITEM(1):range(0,wordAppl:Documents:ITEM(1):characters:COUNT):TEXT.
wordAppl:QUIT(0).
RELEASE OBJECT wordAppl.
opchText = REPLACE(opchText,CHR(146),CHR(39)).
opchText = REPLACE(opchText,CHR(145),CHR(39)).
opchText = REPLACE(opchText,CHR(147),CHR(34)).
opchText = REPLACE(opchText,CHR(148),CHR(34)).
END PROCEDURE.