June 05, 2020, 12:38:22 am

## News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!

## Line Numbers in Richedit control using margins

Started by aurelCB, February 10, 2020, 09:43:38 am

0 Members and 1 Guest are viewing this topic.

#### aurelCB

##### February 10, 2020, 09:43:38 amLast Edit: February 10, 2020, 09:46:52 am by aurelCB
Hello
This topic i open as reference and i hope that would be usefull for anyone who wish to add
line numbers in his own text/code editor using richedit control and margin.

..but now something offtopic
I hope that nobody kill me because code is in Purebasic.
Yes i search trough many web places and cannot found anything usefull and simple
and as possible easy to understand and use with basic-like syntax
then i found one large program on PB forum - html editor which have
just i want line numbers in richedit control.
It looks to me preaty simple with few api functions...
I tested program with PB compiler and work excellent ,line numbering work like in any code editor.
All code for line numbers in two routines/functions/procedures ..so should be easy to translate to CB or
EB or IWB ..i hope

QuoteProcedure drawLinenumbers()
id = GadgetID(#EDIT1)
hdc = GetDCEx_(id, 0, #DCX_CACHE)

;  hFont = fontId(getGadgetFont(#EDIT1))
hFont = GetGadgetFont(#EDIT1)

prevObj = SelectObject_(hDC, hFont)

GetTextMetrics_(hDC, @tm.TEXTMETRIC)
fontH = tm\tmHeight

GetClientRect_(id, rc.RECT)
rc\right = leftM - 8
FillRect_(hDC, rc, GetStockObject_(#WHITE_BRUSH))
SetBkMode_(hDC, #TRANSPARENT)

#### aurelCB

##### February 13, 2020, 05:11:48 am #3
Well yes i know that i must subclass richedit but with or without subclasing not work as in PB
forum for hobby programming:<br />https://aurelsoft.ucoz.com

#### Andy

##### February 13, 2020, 06:22:01 am #4
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.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

#### aurelCB

##### February 13, 2020, 11:45:23 am #5
QuoteAurel,

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.
That is nice to know Andy

also original C code is without subclassing.No need to hurry!
forum for hobby programming:<br />https://aurelsoft.ucoz.com