Date: 02-16-2022
Return to Index
created by gbSnippets
'This shorter skeleton is used throughout the snippets in this library. Note that it
'specifically skips these two statements which provide extra capability/features:
SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE Or %ENM_CHANGE Or %ENM_LINK
SendMessage hRichEdit, %EM_SETLIMITTEXT, &H100000&, 0
'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 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_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,200,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 30,10,140,20
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_KeyEvents
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$
Select Case CB.Msg
Case %WM_Notify
Select Case CB.NmID
Case %ID_RichEdit
Select Case CB.Nmcode
Case %EN_SelChange
temp$ = CharToLeftOfCursor
Dialog Set Text hDlg, temp$
End Select
End Select
End Select
End Function
Function CharToLeftOfCursor() As String
Local P As CharRange, buf$, T as TextRange
SendMessage(hRichEdit, %EM_EXGetSel, 0, VarPTR(P)) 'caret position
T.Chrg.cpmin = P.cpmin-1 : T.Chrg.cpmax = P.cpmax
T.lpstrText = StrPTR(Buf$)
SendMessage hRichEdit, %EM_GetTextRange, ByVal 0, VarPTR(T) 'get text, specified char range or from selection
Function = buf$
End Function
'gbs_00319
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm