Monitor the clipboard
Posted: Sat Aug 17, 2002 1:00 pm
Code updated for 5.20+
Restored from previous forum. Originally posted by Justin.
This code uses a window callback to monitor the clipboard for a change, if it is a text change it will display it.
msdn link:
http://msdn.microsoft.com/library/defau ... pboard.asp
Restored from previous forum. Originally posted by Justin.
This code uses a window callback to monitor the clipboard for a change, if it is a text change it will display it.
msdn link:
http://msdn.microsoft.com/library/defau ... pboard.asp
Code: Select all
Procedure CBCallback(hwnd,msg,wParam,lParam)
Shared hwndNextViewer
ReturnValue=#PB_ProcessPureBasicEvents
Select msg
Case #WM_CHANGECBCHAIN
;If the next window is closing, repair the chain
If hwnd = hwndNextViewer
hwndNextViewer = hwnd
;Otherwise, pass the message to the next link
Else
If hwndNextViewer<>#Null
SendMessage_(hwndNextViewer,msg,wParam,lParam)
EndIf
EndIf
ReturnValue=1
Case #WM_DRAWCLIPBOARD ;clipboard contents changed
cbtxt$=GetClipboardText() ;text only
If cbtxt$<>"" : MessageRequester("Clipboard Change",cbtxt$,0) : EndIf
;Pass the message to the next window in clipboard viewer chain
SendMessage_(hwndNextViewer,msg,wParam,lParam)
ReturnValue=1
EndSelect
ProcedureReturn ReturnValue
EndProcedure
hwnd=OpenWindow(0,200,200,300,100,"Monitoring Clipboard",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
hwndNextViewer=SetClipboardViewer_(hwnd)
SetWindowCallback(@CBCallback())
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
;remove the pb window from the chain of clipboard viewers
ChangeClipboardChain_(hwnd,hwndNextViewer)