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 these lines:
#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, hConsole As Dword
%ID_RichEdit = 500 : %IDC_Button = 501
Function PBMain() As Long
Dialog New Pixels, 0, "Pointer Test Code",900,300,220,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push to select text", 30,10,180,20
LoadLibrary("riched32.dll")
Call InitCommonControls
Control Add "RichEdit", hDlg, %ID_RichEdit, "This is sample text" + $CrLf + "and more!", 20, 40, 180, 100, _
%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, _
%WS_Ex_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE Or %ENM_Protected
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local P As CharRange, temp$, cf As CharFormat
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
'selected some text
P.cpMin = 0 : P.cpMax = 10
Control Send hDlg, %ID_RichEdit, %EM_ExSetSel, 0, VarPtr(P)
'protect the selected text and color it red
cf.cbSize = Len(cf) 'Length of structure
cf.dwMask = %CFM_COLOR Or %CFM_Protected 'Set mask to colors and protection
cf.dwEffects = %CFM_Protected
cf.crTextColor = %Red 'Set the new color value
SendMessage(hRichEdit, %EM_SETCHARFORMAT, %SCF_SELECTION, VarPtr(cf)) 'apply formatting to selection
End Select
Case %WM_Notify
Select Case Cb.NmId
Case %ID_RichEdit
Select Case Cb.NmCode
Case %EN_SelChange
CPrint "SelChange"
Case %EN_Protected
CPrint "EnProtected"
Function = %True : Exit Function 'disallow editing of the protected text
End Select
End Select
End Select
End Function
Sub CPrint (SOut As String)
Static cWritten As Long, iCount As Long
Incr iCount
SOut = Str$(iCount) + " " + SOut
If hConsole = 0 Then AllocConsole: hConsole = GetStdHandle(-11&)
WriteConsole hConsole, ByCopy sOut + $CrLf, Len(sOut) + 2, cWritten, ByVal 0&
End Sub
'gbs_01073
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm