4

I'm trying make an WPF application that I could copy/cut and paste files info and it would copy/move them to a special folder. I know I can get the paths of the files being copied/cut with

var files = Clipboard.GetFileDropList();

But I would like to know, do I need to copy or move the files? I've read something about listening to WM_COPY and WM_CUT. And I tried by hooking a Hwnd hook to my window handel and it didn't work, neither WM_COPY nor WM_CUT got called. And I tried everyting.

So what's the best way of determining if the files were copied or cut? And some code examples or links would really help a lot.

Thank you.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Metod Medja
  • 768
  • 6
  • 10
  • What word do you mean instead of "whther" exactly? The sentence with that word does not make sense. – Security Hound Jan 05 '12 at 16:33
  • I think the sentence misses a "know" between "to" and "whether" and a "I have to" after that – Nuffin Jan 05 '12 at 16:35
  • also reconsider rewording your question to state the issue that you are having or what you are truly trying to accomplish.. thanks – MethodMan Jan 05 '12 at 16:35
  • The hook will most likely not work in .NET, sorry. Only two global hooks are allowed, and that's not them. Unless the hook isn't global, is the origin of the clipboard action inside your application? – Jonathan Henson Jan 05 '12 at 16:40
  • @Jonathan Henson No. The I'd like the origin to be any application that allows copying files. – Metod Medja Jan 05 '12 at 16:46
  • 1
    Then you will not be able to install the hook. I know from experience. Windows only allows left and right clicks to be hooked from .NET. You will have to create a win32 dll, then invoke it in your .NET code to capture the hooks if you have to take that approach. – Jonathan Henson Jan 05 '12 at 16:50
  • In fact, as simple as this sounds as an app, just write it with the API in c or c++. – Jonathan Henson Jan 05 '12 at 16:51
  • I currently have it working by listening to a low-level keyboard hook. But I feel a bit wrong as the code I'm using could be heavily abused. – Metod Medja Jan 05 '12 at 16:54
  • Yea, if you can find a way to grab the actual cut and copy hooks, that would be optimal. – Jonathan Henson Jan 05 '12 at 16:56
  • If you want to know if a file in clipboard is to copy or move, look at this article: http://www.codeproject.com/Articles/32670/Getting-the-Clipboard-File-DropEffect-in-VB-NET – Mike Aug 24 '12 at 14:44
  • Possible duplicate of [Paste Files from Clipboard with Cut or Copy](https://stackoverflow.com/questions/57787840/paste-files-from-clipboard-with-cut-or-copy) – 41686d6564 stands w. Palestine Sep 04 '19 at 12:03

2 Answers2

2

Work from https://stackoverflow.com/a/2078081/939213 backwards. and for copying – substitute 5 for 2.

Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291
1

You will not be able to install the hook. I know from experience. Windows only allows left and right clicks to be hooked from .NET. You will have to create a win32 dll, then invoke it in your .NET code to capture the hooks if you have to take that approach.

Or, as simple as this app sounds, just write it using the API anyways in C or C++.

If this is just a small feature in your application and not the application itself, you will either have to find someway to perform the injection and pass it to your .NET app, or you will have to find a way that doesn't involve hooks.

Jonathan Henson
  • 8,076
  • 3
  • 28
  • 52