完全的新手里程 从今天开始把
C# 学玩过C++举得 C#就是一门英语
今日弄了个进程通信小事下OK了贴代码了事
没啥心得
MSDN 的例子 :如何:在代码中模拟鼠标和键盘事件
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_fxmancli/html/6abcb67e-3766-4af2-9590-bf5dabd17e41.htm
下面是自己写的 注意加个头引用
using System.Runtime.InteropServices;
- this.richTextBox1.Focus();
- IntPtr hwnd_win;
- IntPtr hwnd_button;
- hwnd_win = FindWindow(null,"Form132");
- richTextBox1.Text = hwnd_win.ToString();
- hwnd_button = FindWindowEx(hwnd_win, new IntPtr(0),null , "button1");
- const int BM_CLICK = 0x00F5;
- Message msg = Message.Create(hwnd_button, BM_CLICK, new IntPtr(0), new IntPtr(0));
- PostMessage(msg.HWnd, msg.Msg, msg.WParam, msg.LParam);
- }
- [DllImport("user32.dll")]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll")]
- public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
- [DllImport("user32.dll", CharSet = CharSet.Unicode)]
- public static extern IntPtr PostMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);