Wintertree Software Inc.

Sentry Spelling Checker Engine - Support

Home Site index Contact us Catalog Shopping Cart Products Support Search

You are here: Home > Support > WSpell > Using WSpell with PowerBuilder


Using WSpell with PowerBuilder


Figure 1: Inserting WSpell as a control.



Figure 2: Displaying WSpell property page.



Figure 3: The WSpell properties page.


NOTE: Although WSpell works with 32-bit PowerBuilder applications, Wintertree Software recommends using Sentry Spelling Checker Engine Windows SDK with most PowerBuilder applications. Sentry provides more flexibility and easier deployment options than does WSpell.

The following information may help customers who need to integrate WSpell into a PowerBuilder application.

Inserting WSpell into a PowerBuilder Form

The WSpell ActiveX Control must be inserted onto the PowerBuilder form as an OLE custom control using the "Insert Control" tab of the "Insert Object" dialog (see Figure 1) displayed by

   Insert | Control | OLE...

in the PowerBuilder IDE. If inserted properly, there should be buttons for "OLE Control Properties" and "OLE Control Help" at the bottom of the property page for the control (see Figure 2). The "OLE Control Properties" button displays the WSpell property page (see Figure 3).

Do NOT insert WSpell as an "object" using the "Insert New" tab. It will appear to work properly when run in the PowerBuilder IDE, but it will fail when deployed to another machine.

Interactively Checking Text

To interactively spell check the content of a DataWindow or other control, you need to extract the text from the PowerBuilder control and set the WSpell Text property to the extracted text, then call the WSpell Start method to start the checking. When the corrected text is returned after being processed by the enduser, use the corrected text to replace the text in the PowerBuilder control.

Checking PowerBuilder Controls in the Background ("As You Type")

Many customers want to do background ("as you type") checking of text in PowerBuilder controls. As with interactive checking, you cannot do this kind of spell checking with DataWindows.

You can do background spell checking with both multi-line edit controls and Rich Text Edit controls, although because a standard edit control can only change the font or color for all of the text in the control, you have to do something else such as highlight an image or a label on the screen outside of the screen when a spelling error is detected. (Please see the Programmer's Guide or the sample PowerBuilder demo application for more information.)

The Rich Text Edit control in PowerBuilder allows Sentry to do background spell checking. There is one quirk: you cannot have misspelled text "marked" with a color, but should just use the option to indicate that misspelled words are to be underlined, which will cause a wavy red line to appear under the word. (If you try to specify a color, regardless of what color code you provide, misspelled words will be shown in green text, and the API call to show the context menu will not be able to find the misspelled words in the RTE control.)

For both types of control, the primary event to trap is the Key (or KeyDown) event. (This may need to be added as a new event to an MLE control as it is not shown by default in the PowerBuilder IDE.) Then in the event handler, call the API to check what was just typed into the control. For an RTE control you need to obtain the handle of the "real" RTE control (see below) while for an MLE control you can just use the standard Handle(mle_controlname).

   ll_rc = WSpell1.CheckBackgroundNotify(hWin_control, False, False, False, True, ll_Red)
   

The second event to trap is the RButtonDown event to handle when the user right-clicks on a misspelled word in the control. Convert the coordinates of where the mouse was clicked into pixels and then call the Sentry API to display the context menu. A menu will only be displayed if the cursor was over a misspelled word when it was clicked.

   Call WSpell1.CheckBackgroundMenu(hWin_control, xPos, yPos, 0, False, False, False, False, ll_Red)
   

Background checking a Rich Text Edit control

Doing background checking on a Rich Text Edit (RTE) control requires some extra steps to get the correct handle value for the control. In PowerBuilder, using Handle(rte) actually gets you a handle to a higher-level PowerBuilder "wrapper" around the actual RTE control. So to get the RTE handle for use with WSpell requires some additional steps.

First, declare the following local (or global) external functions:

Protected Function ulong FindWindowEx(ulong hwndParent, ulong hwndChildAfter, string lpszClass, long lpszWindow)
             Library "user32.dll" ALIAS FOR "FindWindowExW"

Then insert statements similar to the following in an event handler (or better, create a local function)

   ulong hWin_wrapper
   ulong hWin_control

   hWin_wrapper = Handle( RTEcontrol )
   IF hWin_wrapper > 0 THEN
    hWin_wrapper = FindWindowEx(hWin_wrapper,0, "PBTxTextControl", 0)
	IF hWin_wrapper > 0 THEN
     hWin_wrapper = FindWindowEx(hWin_wrapper,0, "AfxOleControl42u", 0)
     IF hWin_wrapper > 0 THEN
      hWin_control = FindWindowEx(hWin_wrapper,0, "TX16P", 0)
      IF hWin_control = 0 THEN
       hWin_control = FindWindowEx(hWin_wrapper,0, "TX15P", 0)
       IF hWin_control = 0 THEN
        hWin_control = FindWindowEx(hWin_wrapper,0, "TX14P", 0)
        IF hWin_control = 0 THEN
         hWin_control = FindWindowEx(hWin_wrapper,0, "TX13P", 0)
         IF hWin_control = 0 THEN
          hWin_control = FindWindowEx(hWin_wrapper,0, "TX12P", 0)
          IF hWin_control = 0 THEN
           hWin_control = FindWindowEx(hWin_wrapper,0, "TX11P", 0)
          END IF
         END IF
        END IF
       END IF
      END IF
     END IF
    END IF
   END IF
   

(Different versions of PowerBuilder use different versions of the RTE control with different TXnnP class names.) Then use it in the call to check spelling in the background.

   ll_rc = WSpell1.CheckBackgroundNotify(hWin_control, False, False, False, True, ll_Red)
   


Home Site index Contact us Catalog Shopping Cart Products Support Search


Copyright © 2015 Wintertree Software Inc.