Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
#Include "CommCtrl.inc"
%IDC_RichEdit = 500
%IDC_Button = 501
%IDC_Label = 502
Global hDlg, hRichEdit As Dword, OldREProc&
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
CreateRichEditControl
Control Add Label, hDlg, %IDC_Label,"<message>", 10,140,160,20
Control Add Button, hDlg, %IDC_Button,"Push", 10,170,160,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
OldREProc& = SetWindowLong(GetDlgItem(hDlg, 500), %GWL_WndProc, CodePtr(NewREProc)) 'subclass
Case %WM_Destroy
SetWindowLong hRichEdit, %GWL_WNDPROC, OldREProc& 'un-subclass
End Select
End Function
Sub CreateRichEditControl
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
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %IDC_RichEdit, buf$,10,10,180,120, style&
Control Handle hDlg, %IDC_RichEdit To hRichEdit
End Sub
Function NewREProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case %WM_Cut : Dialog Set Text hDlg, "Cut"
Case %WM_Copy : Dialog Set Text hDlg, "Copy"
Case %WM_Paste : Dialog Set Text hDlg, "Paste"
Case %WM_Clear : Dialog Set Text hDlg, "Clear"
' Case %WM_KeyUp 'trap key up, for syntax color check while editing
' MsgBox "Subclassing: KeyUp"
' Case %WM_GETDLGCODE 'establish control by the RichEdit
' Function = %DlgC_WantAllKeys
' Exit Function
' Case %WM_Char
' If wParam = &H16 Then
' If UseProcList Then BuildProcedureList
' FullSyntax 'pasted with CTL-V ?
' End If
End Select
Function = CallWindowProc(OldREProc&, hWnd, Msg, wParam, lParam)
End Function
'gbs_00715
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm