atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Dec 29, 2007 3:30 pm Post subject: |
|
|
The most you will get out of this is selecting a word then changing it. To help with the flickering and such lock the window before redrawing it via LockWindowUpdate. I made this function to send colored strings to a richedit, might help, might not:
| Code: | void LogText(COLORREF cColor, TCHAR* tszFormat, ...)
{
//
// Grab System Time
//
SYSTEMTIME sysTime = {0};
GetLocalTime( &sysTime );
//
// Rebuilt Text Formatting
//
TCHAR tszOutput[4096] = {0};
va_list vArgs;
va_start( vArgs, tszFormat );
_vsntprintf_s( tszOutput, _countof(tszOutput), _TRUNCATE, tszFormat, vArgs );
va_end( vArgs );
//
// Deselect Then Goto End
//
LRESULT lEditLength = NULL;
SendMessage( hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM)0L );
lEditLength = SendMessage( hEdit, WM_GETTEXTLENGTH, NULL, NULL );
SendMessage( hEdit, EM_SETSEL, (WPARAM)lEditLength, (LPARAM)lEditLength+1 );
//
// Setup Timestamp Color
//
CHARFORMAT cfSysText = {0};
cfSysText.cbSize = sizeof( CHARFORMAT );
cfSysText.dwMask = CFM_BOLD|CFM_COLOR|CFM_FACE;
cfSysText.crTextColor = RGB( 0, 255, 0 );
_tcscpy_s( cfSysText.szFaceName, 32, TEXT("Courier New") );
SendMessage( hEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfSysText );
//
// Start At Last Position In Edit Box
//
lEditLength = SendMessage( hEdit, WM_GETTEXTLENGTH, NULL, NULL );
SendMessage( hEdit, EM_SETSEL, (WPARAM)lEditLength, (LPARAM)lEditLength+1 );
//
// Printout Timestamp
//
TCHAR tszTimeFormat[1024] = {0};
_stprintf_s( tszTimeFormat, _countof(tszTimeFormat), TEXT("[%02i:%02i] "), sysTime.wHour, sysTime.wMinute );
SendMessage( hEdit, EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)&tszTimeFormat );
SendMessage( hEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfSysText );
//
// Printout Given Text
//
cfSysText.crTextColor = cColor;
SendMessage( hEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfSysText );
SendMessage( hEdit, EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)&tszOutput );
//
// Scroll With Box
//
int iLength = GetWindowTextLength( hEdit );
SendMessage( hEdit, WM_VSCROLL, SB_BOTTOM, 0 );
SendMessage( hEdit, EM_SETSEL, iLength+_countof(tszOutput), iLength+_countof(tszOutput) );
//
// Remove Selection
//
SendMessage( hEdit, EM_SETSEL, (WPARAM)-1, 0 );
SendMessage( hEdit, WM_VSCROLL, SB_BOTTOM, 0 );
} |
hEdit is externed from the main .cpp file. It is the handle to the edit box.
A nice source to look at for a highlighting example would be notepad++ though, their project is open source on SourceForge found here:
http://notepad-plus.sourceforge.net/uk/site.htm
_________________
- Retired. |
|