2

I have read many topics about cut/copy to clipboard, but haven't found the answer for my problem

I'm working on a "File Manager" application like Windows Explorer. Files are listed in a listview, in details view.

I have CUT/COPY/PASTE operations, and I know how to use File.Move, .Copy, Clipboard.GetFileDropList(), .SetFileDropList()........... and it works great.

What I dont know is how and where can I write in memory (which method) and how can I read from memory (Clipboard) which operation is last used, Cut or Copy? Is there any string in memory windows explorer writes, that I can read and then know if it is CUT or COPY?

I want to let the user be able to cut/copy from my app to win Explorer and vice versa.

SxOne
  • 143
  • 1
  • 8

3 Answers3

1

If you want to determine which Clipboard operation was last called, I think you have to listen to Windows messages, particularly WM_CUT (0x0300) versus WM_COPY (0x0301), and track which was last sent/received. You can override the Control.WndProc method as discussed on MSDN.

Here are a few more reference links for Windows messages:

Clipboard messages

WM_CUT

WM_COPY

bitxwise
  • 3,534
  • 2
  • 17
  • 22
  • hmmm to complicated for now :((((( dont have time for that right now, but i will save this and try to figure it out.... thanks again !!! – SxOne Jan 28 '11 at 03:01
0

You use Clipboard.SetText to add text to the clipboard (Copy), and Clipboard.GetText to retrieve text from the clipboard (Paste).

There is an article here that should be able to help you out.

Also, regarding copy/paste of files, see this SO question:

Community
  • 1
  • 1
Øyvind Bråthen
  • 59,338
  • 27
  • 124
  • 151
  • The OP's not asking how to read and write text from the clipboard. He is trying to make sure that files that were "cut" from his app and pasted in Explorer get deleted after the "paste" operation. – Gabe Jan 27 '11 at 06:35
  • nope, i read both threads before, and there is no answer for my problem there...... i tried Clipboard.SetText("Cut"); but then when i Paste in Win Explorer it still just copy file... it will be perfect if it can be synchronized ... – SxOne Jan 27 '11 at 06:54
0

Using this topic I wrote this code:

private const string DROP_EFFECT = "Preferred DropEffect";

private void CmdPaste()
{
  DataObject data = Clipboard.GetDataObject() as DataObject;
  var obj = data.GetData(DROP_EFFECT);
  bool isCut = false;
  if (obj != null)
  {
    if (obj is MemoryStream) //from Windows
    {
      var m = (obj as MemoryStream).ToArray();
      isCut = m[0] == 2;
    }
    else
      isCut = obj.ToString() == "Move";
  }

  PasteItems(data.GetFileDropList(), Path, isCut); //here start operation with items
}

private void ItemsToClipboard(StringCollection items, bool isCut)
{
  DataObject data = new DataObject();
  data.SetFileDropList(items);
  if (isCut)
    data.SetData(DROP_EFFECT, DragDropEffects.Move);
  else
    data.SetData(DROP_EFFECT, DragDropEffects.Copy);
  Clipboard.Clear();
  Clipboard.SetDataObject(data);
}
NeoSvet
  • 151
  • 1
  • 4