我遇到了与剪贴板相关的问题,每次尝试从Excel文件进行复制/粘贴操作时都会收到此错误消息。
代码在Clipboard.GetDataObject()
处中断,错误消息如下:
OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))
当我打开Excel,写一些文本并尝试复制/粘贴时,我的WPF应用程序已经在运行。
我使用的代码如下:
private void SetClipboardData()
{
IDataObject data = Clipboard.GetDataObject();
IList result = GetDataForFileDropFormat( data );
if ( ( result != null ) && ( result.Count > 0 ) )
{
this._elementsClipboard = result;
this._sourceDrag = null;
this._sourceClipboard = null;
}
}
上述函数在此处理程序方法中被调用:
public void Handle_WM_DRAWCLIPBOARD( IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled )
{
SendMessage( this._nextClipboardViewer, msg, wParam, lParam );
// get data from clipboard
SetClipboardData();
handled = true;
}
我在 MSDN 和 .NET 论坛上搜寻了很久,但没有找到解决这个问题的方法。
有人可以帮忙或者给我一些尝试的思路吗?
谢谢!