那就调用粘贴那方法不是行了吗
就是不会啊。怎么调用粘贴那方法?
找到了一篇资料可惜不是C#的,不太会弄:
调用SendMessage API就能够向任何带有hWnd属性的表单或者控件发送Windows消息。很多控件内置有对特定消息的响应机制。使用这一机制,你在自己的Visual Basic 6应用程序里很容易就能够实现剪切、复制和粘贴的功能。
要使用这一技巧,你就需要声明用于剪切、复制和粘贴的常数:
Private Const WM_COPY = &H301
Private Const WM_CUT = &H300
Private Const WM_PASTE = &H302
然后,声明对SendMessage API的调用:
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByValhWnd As Long, _
ByValwMsg As Long, ByValwParam As Long, lParam As Any) As Long
HWnd自变量能够接受消息发送的目的控件的句柄,而wMsg自变量会接受一个表明要被发送的是哪个对象的常数。WParam和lParam自变量被用来把其他信息同消息一起传递,但是不对WM_CUT、WM_COPY或者WM_PASTE使用。
下面是从菜单点击事件调用SendMessage API的代码:
Private Sub mnuCopy_Click()
Call SendMessage(Me.ActiveControl.hwnd, WM_COPY, 0, 0)
End Sub
Private Sub mnuCut_Click()
Call SendMessage(Me.ActiveControl.hwnd, WM_CUT, 0, 0)
End Sub
Private Sub mnuPaste_Click()
Call SendMessage(Me.ActiveControl.hwnd, WM_PASTE, 0, 0)
End Sub
我照着大概改了一下不成功啊
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, string lParam);
private const WM_COPY= &H301 ;//c#里缺乏定义
private const WM_CUT = &H300 ;//
private const WM_PASTE = &H302;//
调用:
IntPtr hLogin = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Edit", null); //获取任意窗口Edit句柄
if (hLogin.ToInt32() != 0)//判断获取成功
{
string s = this.khmc.Text.Trim();
SendMessage(hLogin,IntPtr.Zero, IntPtr.Zero, s);//向特定Edit粘贴,但没起到作用:(
}