Microsoft KB Archive/273139

{|
 * width="100%"|

HOWTO: Implement an EditWordBreak Procedure in a RichEdit Control

 * }

Q273139

-

The information in this article applies to:


 * Microsoft Platform Software Development Kit (SDK), on platform(s):
 * the operating system: Microsoft Windows NT
 * Microsoft Windows 98
 * Microsoft Windows 95
 * Microsoft Windows 98 Second Edition
 * Microsoft Windows Millennium Edition

-

SUMMARY
This article provides some sample code that illustrates how to implement an EditWordBreak procedure in RichEdit controls. An EditWordBreak procedure is used by the control to determine whether a given character is to be considered a breakable character, and to find the beginning or end of a word in different situations.

MORE INFORMATION
EditWordBreak procedures respond to a set of commands to provide very straightforward word-break information. The following is a example of how to implement an EditWordBreak procedure:


 * 1) define WB_CLASS_WHITESPACE 0x00
 * 2) define WB_CLASS_LINEBREAK 0x01
 * 3) define WB_CLASS_DELIMITER 0x02
 * 4) define WB_CLASS_NORMALCHAR 0x03

TCHAR whitespace[]=TEXT(&quot; \t&quot;) ; TCHAR linebreakers[]=TEXT(&quot;\r\n&quot;) ; TCHAR delimiters[]=TEXT(&quot;[];:,.\&quot;'&quot;) ;

BOOL isInDelimiterList(TCHAR c) { return (_tcschr((LPCTSTR)delimiters,c) != NULL || _tcschr((LPCTSTR)whitespace,c) != NULL || _tcschr((LPCTSTR)linebreakers,c) != NULL) ; }

int CALLBACK EditWordBreakProcEx(LPTSTR pchText, int ichCurrent, int cch, int code) { int lRet = 0 ; int i=0 ; BOOL found = FALSE ; int initial_pos = ichCurrent ; switch (code) { case WB_LEFT: {//Finds the beginning of a word to the left of the specified position. while(!isInDelimiterList(pchText[ichCurrent]) && ichCurrent>0) ichCurrent-- ; if(ichCurrent>0) lRet = ichCurrent +1 ; else lRet = -1 ; }   break ; case WB_RIGHT: {     //Finds the beginning of a word to the right of the specified position. while(!isInDelimiterList(pchText[ichCurrent]) && ichCurrent0) lRet = ichCurrent -1 ; else lRet = -1 ; }   break ; case WB_ISDELIMITER: {//Checks whether the character at the specified position is a delimiter. if(_tcschr((LPCTSTR)delimiters,*pchText) != NULL) {       lRet = TRUE ; }   }    break ; case WB_CLASSIFY: { //Retrieves the character class and word break flags of the character at the specified position. if(_tcschr((LPCTSTR)whitespace,*pchText) != NULL) {       lRet = WBF_ISWHITE | WB_CLASS_WHITESPACE ; }     else if(_tcschr((LPCTSTR)delimiters,*pchText) != NULL) {       lRet = WBF_BREAKAFTER | WB_CLASS_DELIMITER ; }     else if(_tcschr((LPCTSTR)linebreakers,*pchText) != NULL) {       lRet = WBF_BREAKLINE | WB_CLASS_DELIMITER ; }     else {       lRet = WB_CLASS_NORMALCHAR ; }   }    break ; case WB_MOVEWORDLEFT: // Finds the next character that begins a word before the specified position. {     ichCurrent-- ; while(isInDelimiterList(pchText[ichCurrent])) ichCurrent-- ; while(ichCurrent=0) {        found = isInDelimiterList(pchText[ichCurrent]) ; if(found && ichCurrent>=0) {           lRet = ichCurrent+1 ; }        else {           lRet = -1 ;//This ensures failure unless something is found. //Thus, if the supplied string, is exhausted, //we will be called with the next bunch                                   //of characters. ichCurrent -- ; }     }      return lRet ; }   break ; case WB_MOVEWORDRIGHT: //Finds the next character that begins a word after the specified position. {     if(!isInDelimiterList(pchText[ichCurrent])) while(!isInDelimiterList(pchText[ichCurrent])&&ichCurrent 0) ichCurrent-- ; if(ichCurrent>0) lRet = ichCurrent ; else lRet = -1 ; }   break ; case WB_RIGHTBREAK: {//Finds the end-of-word delimiter to the left of the specified position. while(!isInDelimiterList(pchText[ichCurrent]) && ichCurrent0) lRet = ichCurrent ; else lRet = -1 ; }   break ; } return lRet ; } Additional query words:

Keywords : kbRichEdit kbSDKWin32 kbGrpDSUser kbDSupport

Issue type : kbhowto

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch