Hi,

I am trying to get the line numbering of a RichTextBox to work properly when scrolling. The text is moving continuously but the line numbers jumps from line to line.

What I am trying is to make the scrolling to move the text line by line or move the line number continuously. I have not succeeded.

Any idea how to solve this?

Here is the DrawLineNumbers function

DrawLineNumbers proc
LOCAL lineno:DWORD
LOCAL linecount:dword
LOCAL buffer[32]:BYTE
LOCAL hDC:HDC
LOCAL rect:RECT
LOCAL hRgn:DWORD
LOCAL pt:POINT
LOCAL fnthgt:dword

.if rect.left<38
mov rect.right,38
invoke ValidateRect,hRichEdit,addr rect
.endif
invoke GetDC,hRichEdit
mov hDC,eax
lea edx,rect
assume edx:ptr RECT
invoke CreateRectRgn,.left,.top,.right,.bottom
mov hRgn,eax
assume edx:nothing
invoke SelectObject,hDC,hRgn
push eax
invoke SelectObject,hDC,hFont
push eax
invoke SendMessage,hRichEdit,EM_GETFIRSTVISIBLELINE,0,0
inc eax
mov lineno,eax
invoke GetClientRect,hRichEdit,addr rect
mov rect.right,36
invoke GetStockObject,LTGRAY_BRUSH
invoke FillRect,hDC,addr rect,eax
mov rect.top,1 ;move linenumber down 1 pixels
invoke SendMessage,hRichEdit,EM_GETLINECOUNT,0,0
mov linecount,eax
mov eax,lineno
; invoke GetScrollPos,
.while eax<=linecount
push eax
invoke wsprintf,addr buffer,addr szFormat,eax
invoke SetBkMode,hDC,TRANSPARENT
invoke DrawText,hDC,addr buffer,-1,addr rect,DT_RIGHT or DT_TOP
add rect.top,eax
pop eax
inc eax
.endw
pop eax
invoke SelectObject,hDC,eax
pop eax
invoke SelectObject,hDC,eax
invoke ReleaseDC,hRichEdit,hDC
ret

DrawLineNumbers endp


and here is WM_SCROLL message

.elseif uMsg==WM_VSCROLL
invoke SendMessage,hWin,EM_GETFIRSTVISIBLELINE,0,0
mov lineno,eax
mov eax,wParam
and eax,0ffff0000h
shr eax,16
mov nScrollCode,ax
mov eax,wParam
and eax,0ffffh
mov nPos,ax
;SB_THUMBTRACK  = 5
;SB_THUMBPOSITION  = 4
.if nScrollCode==5 ;|| eax==5
invoke GetDC,hRichEdit
mov edx,eax
invoke GetTextMetrics,edx,addr tm
mov eax,tm.tmHeight
mov edx,lineno
mul eax
shl eax,16
add eax,track
mov wParam,eax

.endif
.endif
Posted on 2008-08-28 02:54:13 by minor28
I have solved the problem. I start numbering lines from top of the page and scroll both text area and numbering area.
Posted on 2008-08-28 13:30:32 by minor28