Locale-based Text and Line Breaking (Windows CE 5.0)
Some languages differ in their rules for hyphenation, spacing, and breaking a line on a page of text. The IMLangLineBreakConsole interface provides locale-aware text-breaking and line-breaking functionality for console-based applications.
The IMLangLineBreakConsole interface enables a user to break either Unicode or multibyte strings depending on the maximum number of columns that are wanted for output. A column in this context is the size of one half-width character; a full-width character is two columns wide.
The following code example shows how to break a Unicode string for output, based on the number of columns and the given locale, and print it to the screen.
// pwszStr - Null-terminated Unicode string.
// locale - Locale identifier of the output string.
// pMLLBC - Pointer to an IMLangLineBreakConsole interface.
long cchSize = wcslen(pwszStr);
// Size of pwszStr in characters.
int MaxColumns = NUMCOLUMNS;
// Desired number of columns for output.
long cchLine;
// Number of characters to output in the current line.
long cchSkip;
// Number of characters to skip before starting the next line.
long totalLine = 0;
// Total number of characters processed.
WCHAR wStr[NUMCOLUMNS] = "";
int cchCopy = 0;
long cchStr = 0;
HRESULT hr = S_OK;
while((totalLine < cchSize) && SUCCEEDED(hr))
// Process the entire string unless an error occurs.
{
hr = pMLLBC->BreakLineW(locale, pwszStr + totalLine,
cchSize - totalLine, MaxColumns, &cchLine, &cchSkip);
cchStr = sizeof(wStr)/sizeof(WCHAR);
cchCopy = (cchLine < cchStr) ? cchLine : (cchStr – 1);
wcsncpy(wStr, pwszStr + totalLine, cchCopy);
// Copy characters of pwszStr for output.
wStr[cchCopy] = L'\0';
totalLine = totalLine + cchLine + cchSkip;
// Increase the total number of characters processed.
wprintf(L"%s\n", wStr);
// Output the string to the console-based application.
// Release the interface and call CoUnitialize to uninitialize the
// Component Object Library before terminating the application.
}
See Also
Internet Explorer Multiple-Language API Application Development
Send Feedback on this topic to the authors