Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Colorful RichTextBox?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sat Dec 29, 2007 9:04 am    Post subject: Colorful RichTextBox? Reply with quote

How would I make some words change colors like Microsoft Visual C#/C++ does?
not the one that selects the word and then change the color, that one is glitchy... Sad
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Dec 29, 2007 3:30 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites