Using an ActiveX spell checking control

ActiveX controls can be used to spell check text in a RichTextEdit control. The supported ActiveX spell checking controls include VSSpell from ComponentOne and WSpell from Wintertree Software.

You can use the SelectedStartPos and SelectedTextLength properties of the RichTextEdit control to highlight the current position of a misspelled word in a text string that you are parsing with a supported ActiveX spell checking control. The following procedure uses an ActiveX control to spell check the entire text of the current band of a RichTextEdit control.

StepsTo spell check selected text in a RichTextEdit control:

  1. On a window with a RichTextEdit control, select Insert>Control>OLE from the window menu.

  2. Click the Insert Control tab of the Insert Object dialog box, select the installed ActiveX spell checking control, and click OK.

  3. Click inside the window in the Window painter to insert the ActiveX control.

    By default, the name of the inserted control is ole_n, where n = 1 when there are no other OLE controls on the window.

  4. Add a menu item to a menu that you associate with the current window and change its Text label to Check Spelling.

  5. Add the following code the the Clicked event of the menu item, where windowName is the name of the window containing the RichTextEdit and ActiveX controls:

    string ls_selected
    
    //get the current band context, and leave select mode
    
    windowName.rte_1.selecttext(0,0,0,0)
    
    windowName.rte_1.SelectTextAll()
    
    ls_selected = windowName.rte_1.SelectedText()
    
    windowName.rte_1.SelectedTextLength = 0
    
    //assign the string content to the ActiveX control
    
    windowName.ole_1.object.text = ls_selected
    
    windowName.ole_1.object.start()
    
  6. Select the ActiveX control in the Window painter and select ReplaceWord from the event list for the control.

  7. Add the following code to the ReplaceWord event script:

    string str
    
    str = this.object.MisspelledWord
    
    rte_1.SelectedStartPos = this.object.WordOffset 
    
    rte_1.SelectedTextLength  = Len(str) 
    
    rte_1.ReplaceText(this.object.ReplacementWord)
    
    messagebox("misspelled word", "replaced")
    

    The next time you run the application, you can click the Check Spelling menu item to spell check the entire contents of the current band of the RichTextEdit control.