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,"Rats! This text will covered!"+$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, "Test Code",300,300,400,400, %WS_OverlappedWindow To hDlg
LoadLibrary("msftedit.dll") : InitCommonControls
Control Add "RichEdit50W", hDlg, %ID_RichEdit, buf$,20,40,340,340, style&, %WS_Ex_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
SendMessage hRichEdit, %EM_SETMARGINS, %EC_LEFTMARGIN, 70
SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_CHANGE
' OldProc& = SetWindowLong(GetDlgItem(hDlg, 500), %GWL_WndProc, CodePtr(NewProc)) 'subclass
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog : DrawStuff
Case %WM_Paint : DrawStuff
Case %WM_Command
If Cb.Ctl = %ID_RichEdit And Cb.CtlMsg = %EN_Change Then DrawStuff
If Cb.Ctl = %ID_RichEdit And Cb.CtlMsg = %EN_Update Then DrawStuff
' Case %WM_Destroy : SetWindowLong hRichEdit, %GWL_WNDPROC, OldProc& 'un-subclass
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 + 15
For j = StartLine To EndLine
temp$ = LTrim$(Str$(j))
R.nleft = 5 : R.ntop = j*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 hDC As Dword, PS As PaintStruct
Local txtZ As Asciiz*10, R As Rect, temp$, i As Long, j As Long
Select Case Msg
Case %WM_Paint
hDC = BeginPaint(hWnd,PS)
i = SendMessage(hRichEdit, %EM_GetFirstVisibleLine,0,0)
For j = i To 20+i
temp$ = LTrim$(Str$(j))
R.nleft = 5 : R.ntop = j*20
R.nright = 30 : R.nbottom = R.nTop+25
DrawText hDC, ByVal StrPtr(temp$), Len(temp$), R, %DT_Left
Next j
EndPaint hDC, PS
End Select
Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
End Function
'gbs_01065
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm