1、找到企业微信窗口
//查找窗口 IntPtr ParenthWnd = new IntPtr(0); //句柄:000103E8 标题:企业微信 类:WeWorkWindow ParenthWnd = FindWindow("WeWorkWindow", "企业微信");
2、移动到左上角,并定义为1100*600,窗口最前
ShowWindow(ParenthWnd, 1); //长1100 宽650,移动到左上角位置 SetWindowPos(ParenthWnd, -1, 0, 0, 1100, 600, 0);
3、一些常规操作,定位鼠标位置和鼠标左右键操作
//定位鼠标位置 SetCursorPos(247, 41); //按下鼠标左键 mouse_event(0x0002, 0, 0, 0, 0); //鼠标左键抬起 mouse_event(0x0004, 0, 0, 0, 0); //复制文字 Clipboard.SetText(msgModel.ToName);
4、粘贴
keybd_event((byte)Keys.ControlKey, 0, 0, 0); keybd_event((byte)Keys.V, 0, 0, 0); keybd_event((byte)Keys.V, 0, 2, 0); keybd_event((byte)Keys.ControlKey, 0, 2, 0);
5、ALT+S发送
keybd_event((byte)Keys.Menu, 0, 0, 0); keybd_event((byte)Keys.S, 0, 0, 0); keybd_event((byte)Keys.S, 0, 2, 0); keybd_event((byte)Keys.Menu, 0, 2, 0);
6、DllImport
[DllImport("User32.dll", EntryPoint = "FindWindow")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("User32.dll", EntryPoint = "FindWindowEx")] private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll")] public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, uint wFlags); [DllImport("user32.dll", EntryPoint = "SendMessage")] public static extern int SendMessage(int hWnd, int Msg, int wParam, ref int lParam); [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)] public static extern int ShowWindow(IntPtr hwnd, int showWay); [System.Runtime.InteropServices.DllImport("user32")] private static extern int mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); [DllImport("user32.dll", EntryPoint = "keybd_event")] public static extern void keybd_event(byte bVk,byte bScan,int dwFlags,int dwExtraInfo);