|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Cover Story Implementing the Microsoft Rich Edit Control
Part 1
Aug. 5, 2005 10:00 AM
What we needed to do was implement spell checking in the rich edit fields in our application (see Figures 1 and 2). To do that, we got a license for the Sentry Spelling Checker Engine from Wintertree Software (www.wintertree-software.com). The utility is easily implemented and works quite well on standard Rich Edit controls.
Our first approach to dealing with this was to extend the PowerBuilder Rich Edit control so that it mimicked the events and functions of the Microsoft Rich Edit control. However, we soon realized that the amount of work required to do this was rapidly approaching the same level of effort needed to replace the PowerBuilder Rich Edit control with the Microsoft version. We also realized that there were other potential advantages to implementing the Microsoft version instead, not the least of which would be support for a recent version of the RTF standard. Implementation - u_richedit You'll want to refer to the MSDN reference page on its Rich Edit control as we discuss the implementation. See http://msdn.microsoft.com/library/default.asp?url=/ The "About Rich Edit Controls" link on that page takes us to another page that indicates the DLL and class name we need to reference to implement the control. We've referenced the RICHED20.DLL file so we can support up through version 3.0 of the control. The most recent version of the control (as of this writing) is 4.1 and would require a reference to the MSFTEDIT.DLL file instead. However, that version of the control is only supported on Windows XP SP1 and later. Version 3.0 is supported on all operating systems since Window 98. Since we can't guarantee that all of our users will be on XP SP1 or later, we chose to implement a slightly older version of the control to ensure compatibility on all clients. Since version 2.0, the control offers two class names: one for Unicode and another for ANSI. Since our application is still PowerBuilder 9 (ANSI)-based, we're using the ANSI class (RichEdit20A). Finally, the "Rich Edit Control Styles" link on that page takes us to another page that indicates the various style settings available that we need to implement through the Style property of the visual user object. The styles we are particularly concerned about are:
The values for those and other constants we'll be using are provided in the include files (*.h) provided in the Windows SDK, particularly WinUser.H and RichEdit.H. The values in those files are provided in a hexadecimal format that we'll need to convert to decimal and combine (see Table 1). u_richedit Instance Variables u_richedit Local External Functions When working with Windows API function calls, we occasionally have to work with arguments that are pointers or structures used as arguments that contain pointers. That requires some memory manipulation before or after the call, and we've declared a number of Windows API functions as local external functions to assist us with that (LocalAlloc, LocalFree, RtlMoveMemory, GlobalAlloc, GlobalLock, GlobalUnlock, and GlobalFree). To do copy and paste operations with RTF data, we also declared a number of Windows API functions for working with the clipboard (OpenClipboard, RegisterClipboardFormat, GetClipboardData, SetClipboardData, and CloseClipboard). A few Windows API function declarations were added to support the use of the ChooseFont dialog (ChooseFont, GetDC, GetDeviceCaps, and MulDiv). One of the Windows messages we'll be sending to the control (EM_STREAMOUT - used to get the RTF formatted data out of the control) requires the address of a callback routine to return the data. Since PowerBuilder doesn't support callbacks, we've written a custom DLL (which we'll be discussing in Part 2) to provide that callback. We have to load the DLL and get the address of that callback, so we've declared a couple of Windows API function calls to help with that (LoadLibrary, GetProcAddress, and FreeLibrary). Finally, the callback needs to know how to send the data back to the control, so there's also a local external function declaration for that custom DLL to provide the handle to the control (SetControl). Reader Feedback: Page 1 of 1
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||