CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2007
    Posts
    19

    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.

  2. #2
    Join Date
    Sep 2004
    Location
    Italy
    Posts
    389

    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.

  3. #3
    Join Date
    Jan 2007
    Posts
    19

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured