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:
'Credit: Borje Hagsten
http://www.powerbasic.com/support/pbforums/showthread.php?t=2668
Function setRichTextTabs(ByVal hEdit As Long, ByVal tabStops As Long) As Long
Local pf As PARAFORMAT, pd As CHARRANGE, xEvents As Long, i&, n&
'Disable the event mask, for better speed
xEvents = SendMessage(hEdit, %EM_GETEVENTMASK, 0, 0)
SendMessage hEdit, %EM_SETEVENTMASK, 0, 0
' Hide the selection to eliminate flickering
SendMessage hEdit, %EM_HIDESELECTION, 1, 0
' Select the entire text
pd.cpmin = 0
pd.cpMax = -1
SendMessage hEdit, %EM_EXSETSEL, 0, VarPTR(pd)
pf.cbSize = SizeOf(pf)
pf.dwMask = %PFM_TABSTOPS
pf.cTabCount = %MAX_TAB_STOPS
For i& = 0 To %MAX_TAB_STOPS - 1
pf.rgxTabs(i&) = i& * 2880
Next i&
n& = SendMessage(hEdit, %EM_SETPARAFORMAT, 0, VarPTR(pf))
' Deselect the text
pd.cpmin = 0
pd.cpMax = 0
SendMessage hEdit, %EM_EXSETSEL, 0, VarPTR(pd)
' Turn selection back on
SendMessage hEdit, %EM_HIDESELECTION, 0, 0
' Reset the event mask
If xEvents Then
SendMessage hEdit, %EM_SETEVENTMASK, 0, xEvents
End If
Function = n&
End Function ' setRichTextTabs
'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,"Set", 30,10,40,20
Control Add Button, hDlg, 101,"Get", 80,10,40,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
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
SetRichTextTabs hRichEdit
End If
If CB.Msg = %WM_Command AND CB.Ctl = 101 AND CB.Ctlmsg = %BN_Clicked Then
MsgBox getRichTextTabs(hRichEdit)
End If
End Function
Function setRichTextTabs(ByVal hEdit As Long) As Long
Local pf As PARAFORMAT, pd As CHARRANGE, xEvents As Long, i&, n&
'Disable the event mask, for better speed
xEvents = SendMessage(hEdit, %EM_GETEVENTMASK, 0, 0)
SendMessage hEdit, %EM_SETEVENTMASK, 0, 0
' Hide the selection to eliminate flickering
SendMessage hEdit, %EM_HIDESELECTION, 1, 0
' Select the entire text
pd.cpmin = 0
pd.cpMax = -1
SendMessage hEdit, %EM_EXSETSEL, 0, VarPTR(pd)
pf.cbSize = SizeOf(pf)
pf.dwMask = %PFM_TABSTOPS
pf.cTabCount = %MAX_TAB_STOPS
For i& = 0 To %MAX_TAB_STOPS - 1
pf.rgxTabs(i&) = i& * 2880
Next i&
n& = SendMessage(hEdit, %EM_SETPARAFORMAT, 0, VarPTR(pf))
' Deselect the text
pd.cpmin = 0
pd.cpMax = 0
SendMessage hEdit, %EM_EXSETSEL, 0, VarPTR(pd)
' Turn selection back on
SendMessage hEdit, %EM_HIDESELECTION, 0, 0
' Reset the event mask
If xEvents Then
SendMessage hEdit, %EM_SETEVENTMASK, 0, xEvents
End If
Function = n&
End Function ' setRichTextTabs
Function getRichTextTabs(ByVal hEdit As Long) As String
Local pf As PARAFORMAT, pd As CHARRANGE, xEvents As Long, i&, temp$
SendMessage(hEdit, %EM_GETPARAFORMAT, 0, VarPTR(pf))
For i& = 0 To %MAX_TAB_STOPS - 1
temp$ = temp$ + $crlf + Str$(pf.rgxTabs(i&))
Next i&
End Function
'gbs_00303
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm