Posted: Fri Jul 18, 2008 11:54 am
I see no problem with your method at all PB. I just prefer mine as it only blocks #WM_PASTE in my target EditorGadget, letting other gadgets go on as usual with no code interruption. 
rsts now has at least 3 options to choose from and he can decide which one is best suited for his app.
rsts now has at least 3 options to choose from and he can decide which one is best suited for his app.
Code: Select all
Procedure ProtectEditor(editorGadget)
With editFormat.CHARFORMAT2
\cbSize = SizeOf(CHARFORMAT2)
\dwMask = #CFM_PROTECTED
\dwEffects = #CFE_PROTECTED
EndWith
SendMessage_(GadgetID(editorGadget), #EM_SETCHARFORMAT, #SCF_ALL, @editFormat)
SendMessage_(GadgetID(editorGadget), #EM_SETEVENTMASK, 0, #ENM_PROTECTED)
EndProcedure
Procedure WinCallback(hwnd, msg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_NOTIFY
*pNMHDR.NMHDR = lParam
Select *pNMHDR\code
Case #EN_PROTECTED
*enp.ENPROTECTED = lParam
If *enp\msg = #WM_PASTE
;...Do your thing here and return nonzero to prevent paste
MessageRequester("Sorry", "Paste not allowed", #PB_MessageRequester_Ok | #MB_ICONERROR)
result = 1
Else
;...Allow everything else
result = 0
EndIf
EndSelect
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 500, 425, "ProtectEditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@WinCallback())
EditorGadget (0, 10, 10, 480, 180)
EditorGadget (1, 10, 200, 480, 180)
StringGadget(2, 10, 390, 450, 25, "StringGadget")
ProtectEditor(0)
For g = 0 To 1
For i = 0 To 15
AddGadgetItem(g, i, "Line " + Str(i))
Next i
Next g
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf