PowerBuilder – Clearing the clipboard

Posted on Thursday, September 17th, 2009 at 8:32 pm in

Powerbuilder’s native ‘clipboard’ method does not clear out the buffer. Here is how to do it:

// external function declarations
Function boolean OpenClipboard ( &
	ulong hWndNewOwner &
	) Library "user32.dll"
Function boolean EmptyClipboard ( &
	) Library "user32.dll"
Function boolean CloseClipboard ( &
	) Library "user32.dll"
// code in application
PowerObject lpo_parent
ULong lul_hWnd
// loop thru parents until a window is found
lpo_parent = This.GetParent()
Do While lpo_parent.TypeOf() <> Window! and IsValid (lpo_parent)
   lpo_parent = lpo_parent.GetParent()
// get handle to window
lul_hWnd = Handle(lpo_parent)
// clear the clipboard
If OpenClipboard(lul_hWnd) Then
Else // something else has the clipboard locked.
   MessageBox("error","OpenClipboard Failed")
End If

Updated March 2021 – not tested with newer PowerBuilder or Windows versions