i have 2 richedit controls next to each other. lets say they both have there font set to the size of 10. then in one of the controls i change the font to size 16. assuming both controls are loaded with the same text, what would i need to do to make each line, line up to each other still. so line 15 in control 1 is lined up with line15 in control 2. any suggestions?
Posted on 2002-02-27 20:24:33 by smurf
Sounds like you need to echo messages from one to the
other - filtering them first. Have you tried that?
Posted on 2002-02-27 20:38:27 by bitRAKE
no bitrake i havent tried anything yet because i cant think of a way to do it. here is a screen shot of what i want done. notice the line numbers on the left are lined up with the text on the right.
Posted on 2002-02-27 20:54:20 by smurf
I believe you need to use Enumeration.

EnumChildWindows?
Posted on 2002-02-27 20:56:14 by bdjames
bdjames: maybe you missunderstand what im trying to do or i missunderstand you. what you do you mean by me needing to enumerate some windows?
Posted on 2002-02-28 13:21:14 by smurf
Enumeration takes a parent handle and calls the child procedure for each child.

BOOL EnumChildWindows(
HWND hWndParent, // handle to parent window
WNDENUMPROC lpEnumFunc, // pointer to callback function
LPARAM lParam // application-defined value
);

BOOL CALLBACK EnumChildProc(
HWND hwnd, // handle to child window
LPARAM lParam // application-defined value
);

So maybe you could do this:

invoke EnumChildWindows hWnd EnumChildProc FIX_ROWS
Posted on 2002-02-28 16:34:18 by bdjames
i have yet to find a solution to my problem. does anyone have anymore ideas?
Posted on 2002-05-01 13:08:46 by smurf
Well I have yet to use some of these messages personally, but it looks like it might work but also looks like a real pain to implement...

1st -
use GetTextExtentPoint32 for the height of a line in the first window.

2nd -
send a EM_EXSETSEL to select all the text in the second richedit.

3rd - send the second richedit a EM_SETCHARFORMAT message:
wParam = uFlags
lParam = lpFmt

lpFmt:
cbSize = sizeof CHARFORMAT
dwMask = CFM_SIZE
yHeight = Character height, in twips (1/1440 of an inch or 1/20 of a printer's point).

-----
Looks like it should work but thats a lot of coding just to test it out...
Posted on 2002-05-01 14:13:02 by Graebel
Hi smurf

Asuming you only use the second richedit to display line numbers.
My suggestion: Get rid of it and draw the line numbers yourself. Should not be very hard to do.

KetilO
Posted on 2002-05-01 14:14:17 by KetilO
Why not just put the line number on the status bar and call it a day? ;)

Or wait for NaN to finish his custom edit control. :D
Posted on 2002-05-01 14:22:55 by iblis
Graebel: thank you for your suggestion. i especially like the GetTextExtentPoint32 api call which i didnt realize existed. i may use KetilO's suggestion though.

KetilO: using your method will i run into trouble if i want the richedit control that displays my number to be a smaller font than the richedit control that displays the text? will i be able to make them line up still?
Posted on 2002-05-01 14:28:20 by smurf
To use GetTextExtentPoint32 you need the separate DC's of each control. Or in short *any* DC with a font selected into it.

I dunno about RichEdit (it makes my head hurt), but if you *can* get the DC's back from each, you can cut to the chase and call GetTextMetrics, on the DC which only gets text data.

I use this:
SetFontData PROC

LOCAL TM :TEXTMETRIC

invoke GetTextMetrics, [ebx].ECon.GDI.xDC, addr TM
lea ecx, TM
mov edx, [ecx].TEXTMETRIC.tmHeight
mov eax, [ecx].TEXTMETRIC.tmAveCharWidth
mov [ebx].ECon.WIN.FONTWIDTH, eax
mov [ebx].ECon.WIN.FONTHEIGHT, edx
ret
SetFontData ENDP


If you can't get your hands on the DC's easily, but you have the font handles for each, you can create your own DC, select the font into it, call GetTextMetrics, and then replace the original font and destroy the private DC. You'd only be using it so you can call the TextMetrics on it... but its an ok work-around if you dont change font alot.

Back to topic, if you call this on both fonts, use the larger 'tmHeight' value for your line numbering, by adjusting a drawing rectangle with this data, and its text justified to top left.

Hope it helps..
:alright:
NaN
Posted on 2002-05-01 14:54:33 by NaN

KetilO: using your method will i run into trouble if i want the richedit control that displays my number to be a smaller font than the richedit control that displays the text? will i be able to make them line up still?


You can still line them up. Use ummm...

iterate through the lines you need numbers for and call EM_LINEINDEX for the 1st character position then EM_POSFROMCHAR to get the screen coords for the upper left of that character. You would then have to add the chars height for the larger font and subtract the height of the smaller font. This will result in the Y position to draw at.
Posted on 2002-05-01 15:34:26 by Graebel
Hi Smurf

Here is a little test project to show what I mean.
There are still issues that need to be solved tho.

KetilO
Posted on 2002-05-01 15:57:01 by KetilO
thanks everyone for the suggestions. i especially appreciate the source code KitilO.
Posted on 2002-05-01 22:14:46 by smurf