I thought that subclassing the richedit control to gain access to WM_Char messages would let me prevent using Ctrl-V to paste into a RichEdit control.
I can detect a Ctrl-V just fine, but when I use the following code in WM_Char, the Ctrl-V pastes information once, then my code pastes it again (in this example, replacing). The WM_Char seems to be received AFTER the paste action has already been completed.
Can someone suggest a way to prevent Ctrl-V from pasting info from the clipboard? I also tried various other messages, including GetDlgCode, but Ctrl-V seems to take action before the messages come into play.
My forum search came up empty, although the forum is pretty big and sometimes the keywords I pick aren't the magic words!
I can detect a Ctrl-V just fine, but when I use the following code in WM_Char, the Ctrl-V pastes information once, then my code pastes it again (in this example, replacing). The WM_Char seems to be received AFTER the paste action has already been completed.
Can someone suggest a way to prevent Ctrl-V from pasting info from the clipboard? I also tried various other messages, including GetDlgCode, but Ctrl-V seems to take action before the messages come into play.
My forum search came up empty, although the forum is pretty big and sometimes the keywords I pick aren't the magic words!
Code:
#Compile Exe #Dim All #Include "RichEdit.inc" #Include "CommCtrl.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& 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 ' If wParam = &H16 Then ' have we been pasted with CTL-V ? ' ListBox Insert hDlg, 200, 1, "Subclass-GetDlgCode-Ctrl-V " + Str$(wParam) ' MsgBox temp$ ' Clipboard Get OEMText To temp$ ' Control Set Text hDlg, %ID_RichEdit, "subclass " + $CrLf + temp$ 'plain text ' Function = 1 : Exit Function ' End If Case %WM_Char If wParam = &H16 Then ' have we been pasted with CTL-V ? ListBox Insert hDlg, 200, 1, "Subclass-Char-Ctrl-V " + Str$(wParam) Clipboard Get Text To temp$ MsgBox temp$ Control Set Text hDlg, %ID_RichEdit, "subclass " + $CrLf + temp$ 'plain text Function = 1 : Exit Function End If Case %WM_Command Select Case Lo(Word, wParam) Case 100 If 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 End Select Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam) End Function
Comment