invoke sendmessage,hwndrichedit,em_settypographyoptions,to_simplelinebreak,to_simplelinebreak invoke sendmessage,hwndrichedit,em_gettypographyoptions,1,1 .if eax==0 ; means this message is not processed mov richeditversion,2 .else mov richeditversion,3 invoke sendmessage,hwndrichedit,em_seteditstyle,ses_emulatesysedit,ses_emulatesysedit .endif
after the richedit control is created, we need to determine the its version. this step is necessary since em_posfromchar behaves differently for richedit 2.0 and 3.0 and em_posfromchar is crucial to our syntax hilighting routine. i have never seen a documented way of checking the version of richedit control thus i have to use a workaround. in this case, i set an option that is specific to version 3.0 and immediately retrieve its value. if i can retrieve the value, i assume that the control version is 3.0.
if you use richedit control version 3.0, you will notice that updating the font color for a large file takes quite a long time. this problem seems to be specific to version 3.0. i found a workaround: making the control emulate the behavior of the system edit control by sending em_seteditstyle message.
after we can obtain the version information, we proceed to subclass the richedit control. we will now examine the new window procedure for the richedit control.
newricheditproc proc hwnd:dword, umsg:dword, wparam:dword, lparam:dword ........ ....... .if umsg==wm_paint push edi push esi invoke hidecaret,hwnd invoke callwindowproc,oldwndproc,hwnd,umsg,wparam,lparam push eax
we handle wm_paint message. first, we hide the caret so as to avoid some ugly gfx after the hilighting. after that we pass the message to the original richedit procedure to let it update the window. when callwindowproc returns, the text is updated with its usual color/background. now is our opportunity to do syntax hilighting.
mov edi,offset asmsyntaxarray invoke getdc,hwnd mov hdc,eax invoke setbkmode,hdc,transparent
store the address of asmsyntaxarray in edi. then we obtain the handle to the device context and set the text background mode to transparent so the text that we will write will use the default background color.