我一直在浏览,我不清楚如何简单地发送 Ctrl+x 或 Ctrl+c 命令 来复制/剪切 data(strings),但我很确定这是所需的 pInvoke。快手,有人吗?
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
可能与此一起: [DllImport("user32.dll")] static extern 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;
}
}