Date: 02-16-2022
Return to Index
created by gbSnippets
'Primary Code:
Local iResult&, P as CharRange
P.cpmin = 0 : P.cpmax = -1
iResult$& = SendMessage(hRichEdit, %EM_EXSetSel, 0, VarPTR(P)) 'P.cpmin = P.cpmax unselects all
P.cpmin = 0 : P.cpmax = -1
iResult$& = SendMessage(hRichEdit, %EM_EXSetSel, 0, VarPTR(p)) '0,-1 selects all
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
#Include "CommCtrl.inc"
Global hDlg as Dword, hRichEdit as Dword
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,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Select All", 50,20,100,20
Control Add Button, hDlg, 150,"Unselect All", 50,50,100,20
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, 500, buf$,20,80,160,100, style&, %WS_EX_ClientEdge
Control Handle hDlg, 500 To hRichEdit
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iResult&, P as CharRange
'select all
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
P.cpmin = 0 : P.cpmax = -1
iResult& = SendMessage(hRichEdit, %EM_EXSetSel, 0, VarPTR(p)) '0,-1 selects all
End If
'unselect all
If CB.Msg = %WM_Command AND CB.Ctl = 150 AND CB.Ctlmsg = %BN_Clicked Then
iResult& = SendMessage(hRichEdit, %EM_EXGetSel, 0, VarPTR(P))
P.cpmax = P.cpmin 'put cursor at starting point of selection
iResult& = SendMessage(hRichEdit, %EM_EXSetSel, 0, VarPTR(P)) 'P.cpmin = P.cpmax unselects all
SetFocus hRichEdit
End If
End Function
'gbs_00233
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm