如何获取剪贴板的独占访问权限以进行测试?

发布于 2024-08-13 04:47:41 字数 160 浏览 4 评论 0原文

我有一个应用程序,长话短说,它使用剪贴板进行部分操作。

但有时,由于我从未 100% 确定的原因,有时剪贴板不可用。有时 RDC 客户端会阻止它,有时则不会。当你确实需要进行各种交易时,这是极难复制的之一。

是否可以编写一个小测试程序,在运行时不允许任何其他程序访问剪贴板?

I have an app which, long story short, uses the clipboard for part of its operation.

Sometimes though, for reasons I've never 100% nailed down, sometimes the clipboard isn't available. Sometimes the RDC client blocks it, sometimes it doesn't. And it's one of those extremely hard to reproduce when you really need to sorts of deals.

Could one write a little testing program that, while it runs, doesn't allow any other programs to access the clipboard?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯℡ 2024-08-20 04:47:41

我想您可以调用 OpenClipboard 和 EmptyClipboard,然后只需将其保持打开状态,仅在测试应用程序退出时调用 CloseClipboard 或类似的操作...

从 SCHNAPPLE 编辑

所以这就是我本质上所做的,我发现 C# 代码可以在... 其他网站

[ DllImport( "user32.dll" ) ]
extern static bool OpenClipboard( IntPtr hWnd );

[ DllImport( "user32.dll" ) ]
extern static bool CloseClipboard();

[ DllImport( "user32.dll" ) ]
extern static IntPtr GetClipboardData( uint uFormat );

public static void GetSomeDib()
{
      OpenClipboard( System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle );

      IntPtr img = GetClipboardData(8);

      MessageBox.Show("Clipboard Locked");

      CloseClipboard();

      MessageBox.Show("Clipboard Unlocked");
}

I suppose you could call OpenClipboard, and EmptyClipboard, then simply keep it open and only call CloseClipboard when the testing application exits, or something like that...

EDIT FROM SCHNAPPLE

So this is what I did essentially and I found C# code to do it on... that other site

[ DllImport( "user32.dll" ) ]
extern static bool OpenClipboard( IntPtr hWnd );

[ DllImport( "user32.dll" ) ]
extern static bool CloseClipboard();

[ DllImport( "user32.dll" ) ]
extern static IntPtr GetClipboardData( uint uFormat );

public static void GetSomeDib()
{
      OpenClipboard( System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle );

      IntPtr img = GetClipboardData(8);

      MessageBox.Show("Clipboard Locked");

      CloseClipboard();

      MessageBox.Show("Clipboard Unlocked");
}
多情癖 2024-08-20 04:47:41

简单的解决方案可能是手动配置 RemDesk 以不监视剪贴板。这是 RemDesk 中的一个选项...
但是,是的,保持剪贴板打开应该会产生预期的效果,并且还会阻止将 WM_DrawClipboard 通知发送到剪贴板查看器。

The easy solution may be to just manually configure RemDesk to not monitor the clipboard. It's an option in RemDesk...
But yes, keeping the clipboard open should have the desired effect, and will also keep WM_DrawClipboard notifications from being sent to clipboard viewers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文