How do I do line numbering in a rich edit control
What would be the best way to do line numbering in a rich edit control? I tried to make a margin and then paint the line number in the margin but it resulted in the content of the edit control being erased. Is it possible to draw text in the margin or am I going about this the wrong way? Any hints would be appreciated.
Re: How do I do line numbering in a rich edit control
How and where do you paint that margin? I would do this way:
- handle WM_NCCALCSIZE and make some room in the left non-client area of the window for the margin
- handle WM_NCPAINT and do the drawing.
Re: How do I do line numbering in a rich edit control
I make the margin using this function...
Code:
SendMessage(hEdit, EM_SETMARGINS, EC_LEFTMARGIN, 40 );
I paint it by calling this in the subclassed rich edit control
Code:
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
rect.top = 0;
rect.bottom = 70;
rect.right = 40;
rect.left = 0;
hdc = BeginPaint( hwnd, &ps );
DrawText( hdc, lineNumber, 1, &rect, DT_LEFT );
EndPaint( hwnd, &ps );
break;
I don't understand what WM_NCCALCSIZE does. Do I need it to calculate the size of my margin? Or do I need it to calculate the position of the text to draw?