August 2004 - Posts

In my work with the RichTextBox control, I've often run into this bug in the RichEdit control. You can read more about this bug by looking at Microsoft's knowledge base article - 812943. If you are unable to get the latest Riched20.dll then you can get around the problem using the following code …
 
 
using System; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace TextUndoBuffer { /// <summary> /// Work around for KB 812943, The RichEdit Control Undo /// Information May Be Lost When the Control Retrieves Text. /// </summary> public class RichTextBoxEx : RichTextBox { [DllImport("user32.dll", EntryPoint="SendMessage", CharSet=CharSet.Auto )] static extern int SendMessage(IntPtr hWnd, int msg,
ref GETTEXTEX wParam, System.Text.StringBuilder lParam); [DllImport("user32.dll", EntryPoint="SendMessage", CharSet=CharSet.Auto )] static extern int SendMessage(IntPtr hWnd, int msg,
ref GETTEXTLENGTHEX wParam, int lParam); [StructLayout(LayoutKind.Sequential)] struct GETTEXTEX { public Int32 cb; public Int32 flags; public Int32 codepage; public IntPtr lpDefaultChar; public IntPtr lpUsedDefChar; } [StructLayout(LayoutKind.Sequential)] struct GETTEXTLENGTHEX { public Int32 flags; public Int32 codepage; } const int WM_USER = 0x0400; // RichEdit messages (Richedit.h) const int EM_GETTEXTEX =(WM_USER + 94); const int EM_GETTEXTLENGTHEX =(WM_USER + 95); // Flags for the GETEXTEX data structure const int GT_DEFAULT = 0; // Flags for the GETTEXTLENGTHEX data structure const int GTL_DEFAULT = 0; // Do default (return # of chars) const int GTL_CLOSE = 4; // Fast computation of a "close" answer public RichTextBoxEx() { } public override string Text { get { GETTEXTLENGTHEX getLength = new GETTEXTLENGTHEX(); getLength.flags = GTL_CLOSE; //get buffer size getLength.codepage = 1200; //Unicode int textLength = SendMessage(base.Handle, EM_GETTEXTLENGTHEX, ref getLength, 0); GETTEXTEX getText = new GETTEXTEX(); getText.cb = textLength+2; //add space for null terminator getText.flags = GT_DEFAULT; getText.codepage = 1200; //Unicode StringBuilder sb = new StringBuilder(getText.cb); SendMessage(base.Handle, EM_GETTEXTEX, ref getText, sb); return sb.ToString(); } set { base.Text = value; } } public override int TextLength { get { GETTEXTLENGTHEX getLength = new GETTEXTLENGTHEX(); getLength.flags = GTL_DEFAULT; //Returns the number of characters getLength.codepage = 1200; //Unicode return SendMessage(base.Handle, EM_GETTEXTLENGTHEX, ref getLength, 0); } } } }
 
~ Paul
with 7 comment(s)
Filed under:
I've used this really great tool to highlight syntax for html output.  The page allows you to paste text code into a textbox and syntax highlight it.  Great for bloging, check it out. 
 
 
~ Paul

Hello Everyone.  I decided I'd join the bandwagon and start bloging.   This blog will be mostly about software development in the .net framework.  Over the years I've come up with some interesting ideas and solutions. I hope share them though this medium.

The biggest thing I might be known for is the spell checker I've developed called NetSpell.  I've really enjoyed this project because it has challenged me in many ways.  I’ve written an article on code project that talks more about it.  While the current version works well, I have big plans for improvement.  Want to help?

I'm currently in the final stretch on development of version 3.0.  The one big thing that this version will have is As You Type spell checking in a RichTextBox.  Implementing this actually proved to be much more difficult then I had expected.  But, I believe I finally have it working.  I'm still getting a bit of flicker in the RichTextBox though.  

My long term plans are to make NetSpell more modular so its technologies can be used in other ways.   Things like phonetic coding and edit distance have uses other then in a spell checker.  I also what to find a better dictionary structure for the word list. I'm hoping to implant a Trie structure or maybe a b-tree.  Has anyone implemented a trie structure in .net?  Another big thing I'd like to add to the NetSpell project is a language lexer that supports Unicode, breaks the text into words, sentences and paragraphs. 

Well, this is just an introduction.  I plan to blog a lot about my spell checker.  I've also become an expert on the RichTextBox so I will be sharing things I've learned about that.

~ Paul

with 4 comment(s)
Filed under:
More Posts