Date: 02-16-2022
Return to Index
created by gbSnippets
'Just to help a user keep track of position in a long document, it would be nice to
'add line numbers in the margine of a RichEdit control. Here's a way to do it.
'Compiler Comments:
'This code is written to compile with PBWin10. To compile with PBWin9,
'add this line:
#Include "CommCtrl.inc"
'Primary Code:
'First, create a margin (for the line numbers) along the left side of the RichEdit control.
SendMessage hRichEdit, %EM_SETMARGINS, %EC_LEFTMARGIN, 70
'Then, in the WM_Paint message, call a function to draw the numbers and colors.
'In this example, a specific window/control and font is used. In a more flexible
'program, a resizeable RichEdit control would be and unspecified font needs to be
Sub DrawStuff
Local txtZ As Asciiz*10, R As Rect, temp$, i As Long, j As Long
For i = 1 To 300 Step 30
R.nleft = 40 : R.ntop = i
R.nright = 350 : R.nbottom =i+15
FillRect hDC, R, %Color_BtnFace+1 'FillRect
R.nleft = 40 : R.ntop = i+15
R.nright = 350 : R.nbottom =i+30
FillRect hDC, R, %Color_GrayText+1 'FillRect
Next i
For i = 1 To 300 Step 15
Incr j
temp$ = LTrim$(Str$(j))
R.nleft = 5 : R.ntop = i
R.nright = 30 : R.nbottom =i+20
DrawText hDC, ByVal StrPTR(temp$), Len(temp$), R, %DT_Left
Next i
End Sub
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
Global hDlg As Dword, hRichEdit As Dword, hDC As Dword
%ID_RichEdit = 500
Function PBMain() As Long
Local style&, buf$
buf$ = "Rats! This text will covered!"
style& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop
Dialog New Pixels, 0, "Test Code",300,300,400,400, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 30,10,140,20
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %ID_RichEdit, buf$,20,40,340,340, style&, %WS_Ex_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
hDC = GetDC(hRichEdit)
SendMessage hRichEdit, %EM_SETMARGINS, %EC_LEFTMARGIN, 70
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Paint
DrawStuff
Case %WM_Destroy
ReleaseDC (hRichEdit, hDC)
Case %WM_Command
If CB.Ctl = 100 Then DrawStuff
End Select
End Function
Sub DrawStuff
Local txtZ As Asciiz*10, R As Rect, temp$, i As Long, j As Long
For i = 1 To 300 Step 30
R.nleft = 40 : R.ntop = i
R.nright = 350 : R.nbottom =i+15
FillRect hDC, R, %Color_BtnFace+1 'FillRect
R.nleft = 40 : R.ntop = i+15
R.nright = 350 : R.nbottom =i+30
FillRect hDC, R, %Color_GrayText+1 'FillRect
Next i
For i = 1 To 300 Step 15
Incr j
temp$ = LTrim$(Str$(j))
R.nleft = 5 : R.ntop = i
R.nright = 30 : R.nbottom =i+20
DrawText hDC, ByVal StrPTR(temp$), Len(temp$), R, %DT_Left
Next i
End Sub
'gbs_00399
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm