Date: 02-16-2022
Return to Index
created by gbSnippets
'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
%ID_RichEdit = 500
Function PBMain() As Long
Local style&, buf$
buf$ = "This is sample" + $CrLf + "text for the" + $CrLf + "edit control."
style& = %WS_Child Or %WS_Visible Or %ES_Center Or %ES_MultiLine Or %WS_VScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop
Dialog New Pixels, 0, "Test Code",300,300,200,150, %WS_OverlappedWindow To hDlg
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %ID_RichEdit, buf$,10,10,180,130, style&, %WS_Ex_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE Or %ENM_CHANGE Or %ENM_LINK
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
Case %WM_Size
ScrollRE
Case %WM_Notify
Select Case Cb.NmId
Case %ID_RichEdit
Select Case Cb.NmCode
Case %EN_Change
ScrollRE
End Select
End Select
End Select
End Function
Sub ScrollRE
Local wC,hC,wT,hT,y As Long, pt As Point, temp$
Control Get Client hDlg, %ID_RichEdit To wC,hC
Control Get Text hDlg, %ID_RichEdit To temp$
GetTextHeight temp$, pt
pt.x = 0 : pt.y = (hC-pt.y)/2
SendMessage hRichEdit, %EM_SetScrollPos, 0, VarPtr(pt)
End Sub
Sub GetTextHeight(temp$, pt As Point)
Local hBMP As Dword
Graphic Bitmap New 100,100 To hBMP
Graphic Attach hBMP,0
Graphic Text Size temp$ To pt.x, pt.y
pt.y = pt.y * SendMessage(hRichEdit,%EM_GetLineCount,0,0)
Graphic Bitmap End
Dialog Set Text hDlg, Str$(pt.y)
End Sub
http://www.garybeene.com/sw/gbsnippets.htm