Page 1 of 1

Hooking the windows clipboard?

Posted: Mon Dec 05, 2011 10:13 pm
by jassing
Has anyone done any work with regards to hooking the windows clipboard (and willing to share)?

Re: Hooking the windows clipboard?

Posted: Mon Dec 05, 2011 10:33 pm
by netmaestro
Personally, I've never done it but if I were to need it at some point, I think I'd start here: http://www.delphidabbler.com/articles?article=9

Re: Hooking the windows clipboard?

Posted: Mon Dec 05, 2011 10:47 pm
by srod
Yes it is straight forward enough; registering one of your windows as a clipboard viewer. I am not on my development machine right now so cannot yank out any code, but once you have registered your window you just have to look out for and respond to a couple of Windows messages, checking the available clipboard formats as and when appropriate.

Re: Hooking the windows clipboard?

Posted: Mon Dec 05, 2011 10:50 pm
by jassing
Thank you! That's helpful -- much easier reading than examples I found.
Thanks srod, for the info.
-j

Re: Hooking the windows clipboard?

Posted: Mon Dec 05, 2011 11:49 pm
by rsts
This might be a start

Code: Select all

nextviewer=SetClipboardViewer_(WindowID(#window_0)) ; So we are informed of clipboard changes.
SetWindowCallback(@windowCallback())

; in windows callback
Case #WM_DRAWCLIPBOARD 
;process the TEXT format
   If OpenClipboard_(0) 
      If IsClipboardFormatAvailable_(#CF_TEXT) <> 0
        hStrPtr.l = GetClipboardData_(#CF_TEXT)
        If hStrPtr
          text$= PeekS(hStrPtr)
        endif
      endif
 ;other formats?
  endif
CloseClipboard_()
SendMessage_(nextviewer,message,wParam,lParam); free the clipboard
          ProcedureReturn Result
might also see EnumClipboardFormats_
and IsClipboardFormatAvailable_

There are some complete examples in the forums, I believe, but this may get you started.

cheers

Re: Hooking the windows clipboard?

Posted: Tue Dec 06, 2011 12:02 pm
by MachineCode
Hooking never worked for me on some PCs I used at work, so I gave up relying on it. Just a warning. Setting a clipboard viewer and then forwarding the messages on is not going to work on all PCs, trust me. I ended up just using my own clipboard monitoring routine instead.

Re: Hooking the windows clipboard?

Posted: Thu Dec 08, 2011 11:30 pm
by utopiomania
I had the same question. Thanks, rsts!