Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
When GetClipboardData() is used to access the data captured by the Clipboard, is there an API call or flag to distinguish between a Copy action (CTRL+C) and a Cut action (CTRL+X)?

What I have tried:

Searching the web. Generally speaking, I couldn't find any documentation about the difference between Cut and Copy when it comes to data captured by the Clipboard
Posted
Updated 23-Apr-18 23:38pm
Comments
[no name] 23-Apr-18 14:48pm    
A very good question. I just tried the follwing, to check wheter a cut Operation works between applications:
a.) Cut a text file in the Windows Explorer
b.) Paste it in a Word document

Result:
The file is copied into the word document, but _not_ deleted in the file System by explorer.

[Edit]
While vice versa, cut the file from WinWord doc and paste it with Explorer, the file disapears from the word doc....
Richard MacCutchan 24-Apr-18 3:48am    
That is a totally different test and will not do what you expect. Cut & Paste of files will only work within Explorer, as that is the application that deletes the original when it pastes it to the new location. Pasting it into Word means that explorer never sees the Paste operation.
Michael Haephrati 23-Apr-18 15:50pm    
This may be a different limitations but let's say you develop App1 and a user running App2 is cutting text and pasting it to the same app (App2). There are ways to capture this text but I wonder how can one determine whether it was a Copy or a Cut...
[no name] 23-Apr-18 16:02pm    
My thinking was more that the cuting app (owner of the clipboard (?)) receives finally something like a "paste_executed" Event. But it seems not to be like this. And I also recognized, word imediatelly shows "cuted" while Explorer Shows it something like "marked as cut". Sorry for my english :-)

Anyway your question was interesting and started me to think about some Details
Jochen Arndt 24-Apr-18 5:48am    
You had the right idea.

See my answer below. It explains why the Explorer shows such files marked.

There is something similar to the "paste_executed" event. The target creates two clipboard objects CFSTR_PASTESUCCEEDED and CFSTR_PERFORMEDDROPEFFECT that are read by the source (the Explorer). So it knows when a paste has succeded and can delete the file or update the display depending on the action performed by the target.

No. You can't tell, because the application which places it on the clipboard:
1) Doesn't tell the clipboard anything other than "here is some data, it's this type"
2) Doesn't have to obey "normal" cut or copy rules at all: it could for example move text to an archive, and copy it to the clipboard.
3) Doesn't have to have a user input of any kind in order to load data to the clipboard - it could be automated via a timer to load data from an RSS feed onto the clipboard in order to issue a "paste" instruction message to a different app.

So, no. No way to tell at all.
 
Share this answer
 
Comments
Michael Haephrati 23-Apr-18 14:39pm    
You got my 5 stars! I wonder if there is a creative solution to capture the CUT or COPY actions
Dave Kreskowiak 23-Apr-18 15:31pm    
No, there isn't. The application that is putting the data in the clipboard knows, but never the receiving application. The "sending" application handles the Cut or Copy operation, but that is only to tell the application what to do with its own document data. The data that's being put on the clipboard is completely independent of the cut or copy operation. The "receiving" application how no way on knowing what happened in the "sending" application.
[no name] 23-Apr-18 15:40pm    
Please see my comment to the question. How you explain the Experiment?
Michael Haephrati 23-Apr-18 15:38pm    
I meant some sort of "global hooking" to capture the Copy or Cut events
Dave Kreskowiak 23-Apr-18 16:14pm    
There are no such things as a "cut event" or a "copy event". Also, stuff can get on the clipboard without ever having been cut or copied. For example, running your app in a virtual machine and cutting something to the clipboard from the host machine.

Global Keyboard hook? Nope. First, there's no way to tell where those keystrokes were going. You have no idea what app was doing the cut/copy. Also, There's more than one way to Cut/Copy something in an app besides Ctrl-X and Ctrl-C.

You will also have to handle the alternate key combinations and sequences, such as the ever popular, not not required!, Alt-E, Alt-C or Alt-T to do the same things.

You will also miss context menus. Select a range of text in the "sender" app, right-click the selection and click Copy/Cut.

There really isn't any way to do what you're thinking about in any consistent manner. There are no such things as "global events" for these operations.
As said in solution 1 and the comments:
There is no general way to know what had happened on the source side.

But there is one exception: Delete-on-Paste Operations
These are used when cutting files (e.g. from within the Windows Explorer).

With those the source requests the target to get informed when a paste operation has been performed by adding an additional object to the clipboard data. When a target detects such requests, it knows that there was a cut operation at the source side (and that it should act acordingly).

See the section Handling Delete-on-Paste Operations at Handling Shell Data Transfer Scenarios (Windows)[^] for how it works.
 
Share this answer
 
Comments
[no name] 24-Apr-18 6:16am    
My 5 and thanks for sharing this
Jochen Arndt 24-Apr-18 6:28am    
Thank you for upvoting.

Normally I do not write comments to point to my solution but in this case I thought you where interested to know about the background of what you have observed when cutting files in the Explorer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900