Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code does not compile in PBWin10 because of Include conflicts for
'the equate %EM_ScrollCaret
'Compiler Comments:
'This code is written to compile with PBWin10. To compile with PBWin9,
'add this line:
#Include "CommCtrl.inc"
'Compilable Example: (Jose Includes)
'In this example, subclassing is used to capture the KeyUp event, which is not
'normally available in the dialog Callback for a RichEdit control.
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
%ID_RichEdit = 500
Global hDlg As Dword, hRichEdit As Dword, OldProc&
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,300, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Paste", 30,10,140,20
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %ID_RichEdit, buf$,20,40,160,100, style&
SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE Or %ENM_CHANGE Or %ENM_LINK Or %ENM_KeyEvents
Control Add ListBox, hDlg, 200,, 20,160,160,100
Control Add Button, hDlg, 300,"Clear ListBox", 30,270,140,20
Control Handle hDlg, %ID_RichEdit To hRichEdit
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$
Select Case CB.Msg
Case %WM_InitDialog
OldProc& = SetWindowLong(GetDlgItem(hDlg, %ID_RichEdit), %GWL_WndProc, Codeptr(NewProc)) 'subclass
Case %WM_Destroy
SetWindowLong hRichEdit, %GWL_WNDPROC, OldProc& 'un-subclass
Case %WM_Command
Select Case CB.Ctl
Case 100
If CB.Ctlmsg = %BN_Clicked Then
Clipboard Get Text To temp$
Control Set Text hDlg, %ID_RichEdit, "main " + $CrLf + temp$ 'plain text
End If
Case 300
If CB.Ctlmsg = %BN_Clicked Then
ListBox Reset hDlg, 200
Control Set Text hDlg, %ID_RichEdit, ""
End If
End Select
End Select
End Function
Function NewProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Local temp$
Select Case Msg
Case %WM_GetDlgCode
ListBox Insert hDlg, 200, 1, "Subclass-GetDlgCode-Ctrl-V " + Str$(wParam)
Case %WM_KeyUp
ListBox Insert hDlg, 200, 1, "Subclass-KeyUp-Ctrl-V " + Str$(wParam)
Case %WM_KeyDown
ListBox Insert hDlg, 200, 1, "Subclass-KeyDown-Ctrl-V " + Str$(wParam)
Case %WM_Paste
ListBox Insert hDlg, 200, 1, "Subclass-Paste-Ctrl-V " + Str$(wParam)
Case %WM_Char
ListBox Insert hDlg, 200, 1, "Subclass-Char-Ctrl-V " + Str$(wParam)
Case %WM_Command
If Lo(Word,wParam) = 100 AND Hi(Word,wParam) = %BN_Clicked Then
Clipboard Get Text To temp$
Control Set Text hDlg, %ID_RichEdit, "subclass " + $CrLf + temp$ 'plain text
End If
End Select
Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
End Function
'If wParam = &H16 Then ' have we been pasted with CTL-V ?
'End If
'gbs_00232
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm