First, I'd like to say I love Iczelion's tutorial on syntax hilighting. Even I can understand it now! Anyway, I'm wondering is there a way to change the font, still using the ideas in the tutorial? I tried setting the font in the Rich Edit control, but it doesn't come out right, and loading an 'identical' font with CreateFont is messy, and still doesn't work right. Is there a simple way to do this?
I belive he's trapping the WM_PAINT procedure by subclassing the RichEdit control. So look in that procedure for where he picks the font and/or font spacing. See ya, Ben
I'm pretty sure that doesn't happen in the WM_PAINT routine, or anywhere else for that matter. I've gone over the code a dozen times. Of course, if I'm wrong, just tell me what line number (or show me the chunk), and I'll be most grateful for the help. :)
The font change is not a problem with my syntax hilighting method so long as both fonts (used by the richedit control itself and the one used by DrawText) are the same Changing the font for the richedit control is easy: you don't have to use CreateFont or CreateFontIndirect at all. Just look at CHARFORMAT structure used by EM_SETCHARFORMAT. In it, you can specify the font face/size and then issue EM_SETCHARFORMAT with SCF_ALL flag. However, once you change the default richedit font, you have to change the one used in syntax hilighting code too. This time, you don't have to call CreateFont/CreateFontIndirect either: just send WM_GETFONT to the richedit control and select the font returned by WM_GETFONT into the device context before you call DrawText
I must be doing something wrong because it's still not working for me. First I set the font in the Rich Edit control (using EM_SETCHARFORMAT). Then, I try WM_GETFONT. That works okay (it doesn't fail when called), but the problem is, invoke SelectObject,hdc,hFont doesn't work. It fails every time.
Rasco: I'm sorry for my previous post: it's not correct. The part where you set the font with EM_SETCHARFORMAT is correct but when you need to call DrawText/TextOut, you must call EM_GETCHARFORMAT to obtain the info about the font, ie, its face, height, charset then you create a logical font with that info. If the whole richedit control uses the same font, the easier method is to create the font once and set it to the richedit control with WM_SETFONT and then select the same font into hdc when you do syntax hilighting.