2013-02-09 644 views
-4

我已經瀏覽和它的我不清楚如何簡單的CTRL + X或Ctrl + C命令複製/剪切數據(串)發,但我很確定這是所需的pInvoke。快速的手,任何人?的SendMessage()來複制/剪切/粘貼WM_COPYDATA 0x004A

[DllImport("user32.dll")] 
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); 

可能連同此: [的DllImport( 「USER32.DLL」)] 靜態外部的IntPtr SetClipboardData(UINT uFormat,IntPtr的HMEM);

不知道如何正確使用其中任何一種,請幫忙。

IntPtr nextClipboardAppWindow; 
public frmMain() 
{ 
     nextClipboardAppWindow = (IntPtr)SetClipboardViewer((int)this.Handle); 
} 

    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(nextClipboardAppWindow, m.Msg, m.WParam, 
          m.LParam); 
       break; 

      case WM_CHANGECBCHAIN: 
       if (m.WParam == nextClipboardAppWindow) 
        nextClipboardAppWindow = m.LParam; 
       else 
        SendMessage(nextClipboardAppWindow, m.Msg, m.WParam, 
           m.LParam); 
       break; 

      default: 
       base.WndProc(ref m); 
       break; 
     } 
    } 
+0

什麼是您的實際問題? – 2013-02-09 06:17:24

+0

** who **,_what_,@where,____ whenhen,「why」,but most:How?... – nobodies 2013-02-09 06:19:27

+0

如果你只是想要答案,沒有人可以幫助你。你需要非常具體,而要求一個問題。 -1。 – coder 2013-02-09 06:20:24

回答

0

如果您使用的是.NET,並獲得System.Windows.Forms那麼你可以使用ClipboardSetGet剪貼板數據。 這裏是以MSDN爲例的鏈接。

http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx

Clipboard類實際上數據發佈到系統剪貼板。它不受限於應用。這是簡單的

System.Windows.Forms.Clipboard.SetText("This will be available across all applications");

+0

我需要複製的應用程序本身以外的東西你如何Clipboard.SetDataObject(對象數據,布爾拷貝);在外面的形式? – nobodies 2013-02-09 06:33:46

+0

我無法讓它正常工作 – nobodies 2013-02-09 06:42:20

+0

'剪貼板類複製/粘貼不綁定到應用程序。它設置/從系統剪貼板獲取值。我已經更新了我的答案,所以看看。 – 2013-02-09 09:24:42

相關問題