如何使用C ++在后台跟踪剪贴板更改 [英] How to track clipboard changes in the background using C++

查看:92
本文介绍了如何使用C ++在后台跟踪剪贴板更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在后台应用程序中处理剪贴板的内容。

I need to process the contents of the clipboard in the background application.

我该怎么办?

我需要一个在每次更换剪贴板时都会调用的事件。

I need an event that will be called each time when the clipboard is changed. It does not matter from which the application is copying.

我知道读写功能,例如 GetClipboardData() SetClipboardData()

I know the function for reading and writing, such as GetClipboardData() and SetClipboardData().

有什么想法可以在C ++中做到吗?

Got any ideas how to do this in C++?

谢谢!

推荐答案

自Windows Vista以来,正确的方法是使用剪贴板格式的侦听器:

Since Windows Vista, the right method is to use clipboard format listeners:

case WM_CREATE: 
  // ...
  AddClipboardFormatListener(hwnd);
  // ...
  break;

case WM_DESTROY: 
  // ...
  RemoveClipboardFormatListener(hwnd);
  // ...
  break;

case WM_CLIPBOARDUPDATE:
  // Clipboard content has changed
  break;






请参见监视剪贴板内容


有三种监视剪贴板更改的方法。最古老的方法是创建剪贴板查看器窗口。 Windows 2000添加了查询剪贴板序列号的功能,并且 Windows Vista添加了对剪贴板格式侦听器的支持。支持剪贴板查看器窗口,以便与早期版本的Windows向后兼容。 新程序应使用剪贴板格式的侦听器或剪贴板序列号。

There are three ways of monitoring changes to the clipboard. The oldest method is to create a clipboard viewer window. Windows 2000 added the ability to query the clipboard sequence number, and Windows Vista added support for clipboard format listeners. Clipboard viewer windows are supported for backward compatibility with earlier versions of Windows. New programs should use clipboard format listeners or the clipboard sequence number.

这篇关于如何使用C ++在后台跟踪剪贴板更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆