469,364 Members | 2,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

which application put data into clipboard

Is there a way to find out which application put data into the clipboard. I want my app to respond only when data was put into the clipboard from a specific application. The clipboard notifier code that I am using
Sep 21 '09 #1
3 2169
I figured it out after doing some more research. Here is the code that I put in the clipboard change event.

IntPtr ownerHwnd = GetClipboardOwner();

uint processId;
GetWindowThreadProcessId(ownerHwnd, out processId);
Process process = Process.GetProcessById((int)processId);
Debug.WriteLine(String.Format("Owner: {0}, processid: {1} Title: {2} Exe: {3}", ownerHwnd.ToString("X8"), processId, process.MainWindowTitle, process.MainModule.FileName));

One thing that I have noticed is that I can't always get the window title. Apps like Internet Explorer and file explorer don't return a title.
Sep 21 '09 #2
7,872 Expert 4TB
Is the application that puts data on the clipboard your own?
If so, have it add a custom datatype to the clipboard as well as the other data that you can trigger off of?
Sep 21 '09 #3
Nope, it could be any application that puts any type of data into the clipboard. My solution is back a few posts. This is how it works:

In the configuration of section of my program, I have a property that stores the application being monitored, which is the exe filename. When I get a clipboard content changed notification, I find the processid from the owner handle that last put data into the clipboard using GetClipboardOwner and then GetWindowThreadProcessId. With the processid, I can get the Process using Process.GetProcessById. From there, I can get various properties including the filename, which is compared against the one that I configured to be monitored. If they match, the clipboard data is processed.
Sep 21 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by VB User | last post: by
2 posts views Thread by yxq | last post: by
1 post views Thread by GeorgeK | last post: by
1 post views Thread by Robert Bravery | last post: by
2 posts views Thread by =?Utf-8?B?dmluY2VudA==?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.