How to unlock the Clipboard when another app misbehaves

Post Reply
User avatar
Luis Krause
Posts: 59
Joined: Tue Oct 11, 2005 1:39 am
Location: Vancouver, Canada

How to unlock the Clipboard when another app misbehaves

Post by Luis Krause »

Hi all

I'm having a problem. Something in my PC (and I know it's not FWH) is not releasing the Windows Clipboard, forcing me to reboot my PC in order to be able to do the everyday Cut & Paste stuff!

Researching in msdn, I found a couple of API functions that I thought would allow me to forcibly kill the other apps stronghold on the clipboard, but I'm missing something.

Code: Select all

DLL32 FUNCTION ClipboardOwner() ;
   AS LONG PASCAL FROM "GetClipboardOwner" Lib "user32"

DLL32 FUNCTION ClipboardChain( ;
   hPrevWnd AS LONG, ;
   hNewWnd  AS LONG ) ;
   AS LONG PASCAL FROM "ChangeClipboardChain" Lib "user32"
doing something like

Code: Select all

#define WM_DESTROYCLIPBOARD 775

Function Test()
   Local oClp
   Local hOwner := 0
   Local hNewOwner := 0

   MsgInfo( ClipBoardOwner() )
   oClp := TClipboard():New()
   //MsgInfo( "App handle: " + cValToChar( oClp:oWnd:hWnd ) )
   oClp:Open()

   // this doesn't forcibly release ownership
   hOwner := ClipBoardOwner()
   MsgGet( "New Clipboard Owner Handle", "New ::hWnd:", @hNewOwner )
   ClipboardChain( hOwner, hNewOwner )
   SendMessage( hNewOwner, WM_DESTROYCLIPBOARD, 0, 0 )

   oClp:Close()  // this works as expected, of course

   hOwner := ClipBoardOwner()
   MsgInfo( "Clipboard Owner: " + cValToChar( hOwner ) )

return nil
Has no efect.
If anyone has already created a routine that can release the clipboard when a misbehaved app doesn't release it, I'd appreciate your help.

Regard,
Luis
"May the Source be with GNU"
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Post by Badara Thiam »

Luis,

Please look at SetClipboardViewer() API (w98 and 2000) if you don't know.

This is a part of "SAMS Windows 2000 API SuperBible" :

"SetClipBoardViewer places the given windows at the lead of the chain
of the clipboard viewers. The value returned, the handle of the next clipboard viewer on the chain, must be saved by the caller and kept up-to-date by processing the WM_CHANGECBCHAIN message. The handle of the next clipboard viewer is needed to process the WM_DRAWCLIPBOARD, WM_CHANGECBCHAIN, and WM_DESTROY messages.


Syntax : HWND SetClipboardViewer( HWND hWnd )"


Hope this help, 8)
Badara Thiam
http://www.icim.fr
Post Reply