Friday, 15 January 2010

c# - Execute application when paste is clicked in Windows (explorer) -



c# - Execute application when paste is clicked in Windows (explorer) -

i have application, copier, can much more other stuff. can't past this:

i want open application when user selected few files (in explorer, desktop, or anywhere in windows), , selected files, should in cache or in list or something.

this done windows, don't have that. when user selected of files wanted select, , copied it, how execute application when user pastes files somewhere else? automatically opens?

i have this:

[dllimport("user32.dll")] protected static extern int setclipboardviewer(int hwndnewviewer); [dllimport("user32.dll", charset = charset.auto)] public static extern bool changeclipboardchain(intptr hwndremove, intptr hwndnewnext); [dllimport("user32.dll", charset = charset.auto)] public static extern int sendmessage(intptr hwnd, int wmsg, intptr wparam, intptr lparam); intptr nextclipboardviewer; protected override void wndproc(ref system.windows.forms.message m) { // defined in winuser.h const int wm_drawclipboard = 0x308; const int wm_changecbchain = 0x030d; switch (m.msg) { case wm_drawclipboard: displayclipboarddata(); sendmessage(nextclipboardviewer, m.msg, m.wparam, m.lparam); break; case wm_changecbchain: if (m.wparam == nextclipboardviewer) { nextclipboardviewer = m.lparam; } else { sendmessage(nextclipboardviewer, m.msg, m.wparam, m.lparam); } break; default: base.wndproc(ref m); break; } } void displayclipboarddata() { seek { idataobject idata = new dataobject(); idata = clipboard.getdataobject(); if (idata.getdatapresent(dataformats.rtf)) { richtextbox1.rtf = (string)idata.getdata(dataformats.rtf); } else if (idata.getdatapresent(dataformats.text)) { richtextbox1.text = (string)idata.getdata(dataformats.text); } else { richtextbox1.text = "[clipboard info not rtf or ascii text]"; } } grab (exception e) { messagebox.show(e.tostring()); } }

but works when text selected. how can display file directory of each file?

if want react on re-create (ctrl+c) or cutting (ctrl+v) operation rather paste (ctrl+v) operation, relatively simple. have monitor clipboard, because that's info goes. info format have hear filedrop.

unfortunatelly, have utilize winapi hear clipboard changes.

when received such change, can retrieve list of copied files this:

void displayclipboarddata() { if(!clipboard.containsfiledroplist()) return; var filelist = clipboard.getfiledroplist(); // file list. }

c#

No comments:

Post a Comment