Date: 02-16-2022
Return to Index
created by gbSnippets
'... this snippet is in work
'Compiler Comments:
'This code is written to compile with PBWin10. To compile with PBWin9,
'add this line:
#Include "CommCtrl.inc"
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
Global hDlg, hRichEdit, hDC As Dword, OldProc&
%ID_RichEdit = 500
Function PBMain() As Long
Local style&, buf$
buf$ = Repeat$(50,"Welcom to the world of RichEdit controls!"+$CrLf)
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, "RichEdit Line Numbers",300,300,400,400, %WS_OverlappedWindow To hDlg
LoadLibrary("msftedit.dll") : InitCommonControls
Control Add "RichEdit50W", hDlg, %ID_RichEdit, buf$,10,10,380,380, style&, %WS_Ex_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
SendMessage hRichEdit, %EM_SETMARGINS, %EC_LEFTMARGIN, 50
SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_CHANGE
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_InitDialog
OldProc& = SetWindowLong(hRichEdit, %GWL_WndProc, CodePtr(NewProc))
Control Post hDlg, %ID_RichEdit, %EM_SetSel, 0, 0 'remove initial selection
Case %WM_Command
If Cb.Ctl = %ID_RichEdit And Cb.CtlMsg = %EN_Update Then DrawStuff
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %ID_RichEdit, w-20,h-20
Case %WM_Destroy
SetWindowLong hRichEdit, %GWL_WNDPROC, OldProc&
End Select
End Function
Sub DrawStuff
Local R As Rect, temp$, j,StartLine,EndLine As Long
hDC = GetDC(hRichEdit)
R.nLeft = 5 : R.nTop = 0 : R.nRight = 30 : R.nBottom = 300
FillRect hDC, R, GetStockObject(%White_Brush) 'clear the margin area
StartLine = SendMessage(hRichEdit, %EM_GetFirstVisibleLine, 0,0)
EndLine = StartLine + 21 '<--- 25 need to be calculate - not hard, just haven't done it yet
For j = StartLine To EndLine
temp$ = LTrim$(Str$(j))
R.nleft = 5 : R.ntop = (j-StartLine)*15 : R.nright = 30 : R.nbottom = R.ntop + 15
DrawText hDC, ByVal StrPtr(temp$), Len(temp$), R, %DT_Left
Next j
ReleaseDC (hRichEdit, hDC)
End Sub
Function NewProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Local R As Rect, temp$, j,StartLine,EndLine As Long, PS As PaintStruct
Select Case Msg
Case %WM_NCPaint
hDC = BeginPaint(hWnd,PS)
R.ntop = 0
R.nbottom = 70
R.nright = 40
R.nleft = 0
DrawText hdc, ByVal StrPtr(temp$), Len(temp$), R, %DT_LEFT
EndPaint hDlg, PS
' Function = 1 : Exit Function
End Select
Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
End Function
'gbs_01066
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm