Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code is written to compile with PBWin10. To compile with PBWin9,
'add this line:
#Include "CommCtrl.inc"
'Primary Code:
SendMessage(hRichEdit, %EM_EXGetSel, 0, VarPTR(P)) 'start/stop of selection, caret position if no selection
SendMessage(hRichEdit, %EM_LineIndex, n&, 0) 'position of 1st char in line m&
SendMessage(hRichEdit, %EM_LineLength, iStartPos&, 0) 'length of specified line
SendMessage(hRichEdit, %EM_GetTextLengthEX, VarPTR(D),0) 'length of all text in control
SendMessage(hRichEdit, %EM_EXLineFromChar, 0, -1) 'line#, current
SendMessage(hRichEdit, %EM_EXLineFromChar, 0, iStartPos&) 'line# containing specified character
SendMessage(hRichEdit, %EM_GetLineCount, 0,0) 'total line count in control
SendMessage(hRichEdit, %EM_GetLine, iStartLine&, StrPTR(buf$)) 'get text, specified line
SendMessage(hRichEdit, %EM_GetSelText, 0, StrPTR(buf$)) 'get text, selected
SendMessage(hRichEdit, %EM_GetTextEX, VarPTR(T), StrPTR(buf$)) 'get text, specified char ra
'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
Dialog New Pixels, 0, "Test Code",300,300,200,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 30,10,140,20
CreateRichEditControl
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 i,iCount,iLength As Long, buf$
iCount = SendMessage(hRichEdit, %EM_GetLineCount, 0,0)
For i = 0 to iCount-1
iLength = SendMessage(hRichEdit, %EM_LineLength, i, 0) 'length of specified line
buf$ = Space$(iLength-10)
buf$ = " "
SendMessage(hRichEdit, %EM_GetLine, i, StrPTR(buf$)) 'get text, specified line
? buf$
Next i
End If
End Function
Sub CreateRichEditControl
Local style&, buf$
buf$ = "This is sample" + $CrLf + "text for the" + $CrLf + "RichEdit 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
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %ID_RichEdit, buf$, 20, 40, 160, 100, style&, %WS_EX_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE Or %ENM_CHANGE Or %ENM_LINK
SendMessage hRichEdit, %EM_SETLIMITTEXT, &H100000&, 0
End Sub
'gbs_01061
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm