Monitoring the clipboard?
Posted: Tue Mar 21, 2006 12:35 pm
Is this the correct way to monitor the clipboard?
Reasons for asking:
(1) The MSDN SDK ( http://tinyurl.com/4grj8 ) talks of the callback using
#WM_CREATE to add the viewer, but do I need to do that if I'm using the
SetClipboardViewer API?
(2) Justin's example ( http://www.purebasic.fr/english/viewtopic.php?t=3784 )
uses a Shared variable type for "nextviewer" but I'm using a Global; so which
is correct? The SDK says to use a "static variable" so I'm guessing Shared?
Although it shouldn't really matter in this example, right?
(3) Justin's example, in the #WM_CHANGECBCHAIN event, sets the value of
"nextviewer" to "hwnd" but the SDK says to set it to "lParam" (like I've done).
I assume that's what Justin meant?
(4) Justin doesn't use PostQuitMessage_(0), so is it necessary?
(5) The SDK has "break;" and I assume "Result=1" is the equivalent here?
Now, assuming what I've done is correct: I've noticed that at work, where my
PC uses "Remote Desktop Connection" (mstsc.exe) on Windows 2000, that
sometimes the clipboard in the remote desktop is empty after I copy something
from the "host" desktop. So, I'm guessing I'm missing something up there in my
clipboard code. Or, maybe it's just a bad app breaking the clipboard chain?
My exact problem is mentioned here: http://tinyurl.com/nbn38
The poster is referred to this topic: http://tinyurl.com/n2j6z
In that topic, the response is that another app enters the clipboard chain but
then doesn't exit it cleanly, causing the problem. If I quit "Remote Desktop
Connection" at work and re-launch it, all works well again, which would thus
suggest it's a remote app breaking the chain, and not my code above?
I guess I just want some reassurance that my code above is fine.
Code: Select all
Global nextviewer
Procedure Callback(WindowID,Message,wParam,lParam)
Result=#PB_ProcessPureBasicEvents
Select Message
Case #WM_CHANGECBCHAIN
If wParam=nextviewer
nextviewer=lParam
ElseIf nextviewer<>0
SendMessage_(nextviewer,Message,wParam,lParam)
EndIf
Result=1
Case #WM_DRAWCLIPBOARD
Debug GetClipboardText() ; Show new contents.
SendMessage_(nextviewer,Message,wParam,lParam)
Result=1
EndSelect
ProcedureReturn Result
EndProcedure
If OpenWindow(0,300,350,200,100,"Clipboard Viewer",#PB_Window_SystemMenu)
nextviewer=SetClipboardViewer_(WindowID(0)) ; So we are informed of clipboard changes.
SetWindowCallback(@Callback()) : Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
ChangeClipboardChain_(WindowID(0),nextviewer) : PostQuitMessage_(0)
EndIf
(1) The MSDN SDK ( http://tinyurl.com/4grj8 ) talks of the callback using
#WM_CREATE to add the viewer, but do I need to do that if I'm using the
SetClipboardViewer API?
(2) Justin's example ( http://www.purebasic.fr/english/viewtopic.php?t=3784 )
uses a Shared variable type for "nextviewer" but I'm using a Global; so which
is correct? The SDK says to use a "static variable" so I'm guessing Shared?
Although it shouldn't really matter in this example, right?
(3) Justin's example, in the #WM_CHANGECBCHAIN event, sets the value of
"nextviewer" to "hwnd" but the SDK says to set it to "lParam" (like I've done).
I assume that's what Justin meant?
(4) Justin doesn't use PostQuitMessage_(0), so is it necessary?
(5) The SDK has "break;" and I assume "Result=1" is the equivalent here?
Now, assuming what I've done is correct: I've noticed that at work, where my
PC uses "Remote Desktop Connection" (mstsc.exe) on Windows 2000, that
sometimes the clipboard in the remote desktop is empty after I copy something
from the "host" desktop. So, I'm guessing I'm missing something up there in my
clipboard code. Or, maybe it's just a bad app breaking the clipboard chain?
My exact problem is mentioned here: http://tinyurl.com/nbn38
The poster is referred to this topic: http://tinyurl.com/n2j6z
In that topic, the response is that another app enters the clipboard chain but
then doesn't exit it cleanly, causing the problem. If I quit "Remote Desktop
Connection" at work and re-launch it, all works well again, which would thus
suggest it's a remote app breaking the chain, and not my code above?
I guess I just want some reassurance that my code above is fine.
