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,hFont,hRichEdit As Dword
%ID_RichEdit = 500
%ID_Graphic = 501
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_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,300,400, %WS_OverlappedWindow To hDlg
Font New "Tahoma", 48, 1 To hFont
Control Add Graphic, hDlg, %ID_Graphic, "", 0,0,1,1
Graphic Attach hDlg, %ID_Graphic
Control Add Button, hDlg, 100,"Push", 30,10,140,20
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %ID_RichEdit, buf$,20,40,260,340, style&, %WS_Ex_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
Control Set Font hDlg, %ID_Graphic, hFont
Control Set Font hDlg, %ID_RichEdit, hFont
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Local hA,hB As Long
hA = Graphic(Text.Size.Y,"A")
hB = RELineHeight2
? Str$(hA) + $CrLf + Str$(hB)
End If
End Function
Function RELineHeight() As Long
Local PA, PB As Point, Index0, Index1 As Long
Index0 = SendMessage(hRichEdit, %EM_LineIndex, 0, 0) 'location of 1st character in first line (zero-based index)
Index1 = SendMessage(hRichEdit, %EM_LineIndex, 1, 0) 'location of 1st character in second line (zero-based index)
SendMessage hRichEdit, %EM_PosFromChar, VarPtr(PA), Index0 'PA will contain X,Y of upper-left of left-most character on line 0
SendMessage hRichEdit, %EM_PosFromChar, VarPtr(PB), Index1 'PA will contain X,Y of upper-left of left-most character on line 1
RELineHeight = PB.y - PA.y
End Function
Function RELineHeight2 () As Long
Local fr As FORMATRANGE
fr.hdc = GetDc(hRichEdit) 'class dc not used for drawing, so no need to release.. I think.
fr.chrg.cpmax = 1
SendMessage(hRichEdit, %EM_FORMATRANGE, 0, VarPtr(fr))
Function = fr.rc.nBottom / (1440 / GetDeviceCaps(fr.hdc, %LOGPIXELSY)) ' convert twips to pixels
End Function
http://www.garybeene.com/sw/gbsnippets.htm