Hello
I'll try to convert this snippet to iwBasic syntax tonight.
This is what i've came up with. Haven't tested this snippet yet, you'll have to provide
the code template to create the window, the controls and the corresponding handler.
Don't forget to subclass your Richedit control at first.
INT rline, rchar ': Global variables
Sub drawLinenumbers()
Int hdc, hRichEdit, hFont, prevObj, fontH, first, lastChar
Int last, textW, textH, FWEIGHT, FTSIZE, FFLAGS, leftM
RECT rc
POINT pt
POINT tChar
TEXTMETRIC tm
String FONTNAME
FONTNAME = "FixedSys"
FWEIGHT = 0
FTSIZE = 9
FFLAGS = 0
leftM = 54 ': Left margin value
SetFont WIN, FONTNAME, FTSIZE, FWEIGHT, FFLAGS
GETTEXTSIZE (WIN, "0", textW, textH) ': Find the desired text Height
hRichEdit = GetControlHandle (WIN, RICHEDIT_1)
hdc = GetDC(hRichEdit, 0, DCX_CACHE)
hFont = CreateFont(textH,0,0,0, FWEIGHT,0,0,0,0,0,0,0,0, FONTNAME)
prevObj = SelectObject(hDC, hFont)
GetTextMetrics(hDC, tm)
fontH = tm.tmHeight
GetClientRect(hRichEdit, rc)
rc.right = leftM - 8
FillRect(hDC, rc, GetStockObject(WHITE_BRUSH))
SetBkMode(hDC, TRANSPARENT)
SetTextColor(hDC, 0xC0C0C0)
': get the first line
first = SendMessage(hRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0)
': get the last character/line
pt.x = rc.left
pt.y = rc.bottom
lastChar = SendMessage(hRichEdit, EM_CHARFROMPOS, 0, pt)
last = SendMessage(hRichEdit, EM_LINEFROMCHAR, lastChar, 0)
': get the first character
pt.y = rc.top
firstChar = SendMessage(hRichEdit, EM_CHARFROMPOS, 0, pt)
': get the client coordinates fo the first character
SendMessage(hRichEdit, EM_POSFROMCHAR, tChar, firstChar)
': adjust linenumber RECT
rc.top = tChar.y
For rline = first To last
DrawText(hDc, Str$(rline + 1), -1, rc, DT_RIGHT)
rc.top+ = fontH
Next rline
SelectObject(hDC, prevObj)
ReleaseDC(hRichEdit, hDC)
Return
Endsub
Sub getLinenumber(hRichEdit)
POINT pos
': gets the linenumber in a RichEdit control from the caret position
SetFocus(hRichEdit)
GetCaretPos(pos)
rchar = SendMessage(hRichEdit, EM_CHARFROMPOS, 0, pos)
rline = SendMessage(hRichEdit, EM_LINEFROMCHAR, rchar, 0)
Return rline
EndSub
Well yes i know that i must subclass richedit but with or without subclasing not work as in PB
Aurel,
I've done it without subclassing (just added it in).
Will send you the code tomorrow as I'm a little busy for the rest of the day.
Andy.
:)