使用c#跨进程操作SysTreeView32

来源:互联网 发布:nfs windows 外网 编辑:程序博客网 时间:2024/06/06 20:23

项目需要模拟鼠标点击其他应用程序的SysTreeView32控件指定Item。

//define   public const int TVM_ENSUREVISIBLE = 0x1100 + 20;public const int WM_LBUTTONDOWN = 0x0201;public const int WM_LBUTTONUP = 0x0202;public const int WM_MOUSEMOVE = 0x0200;[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]//BOOL WINAPI PostMessage(_In_opt_ HWND   hWnd,_In_     UINT   Msg,_In_     WPARAM wParam,_In_     LPARAM lParam);public static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]//LRESULT WINAPI SendMessage( _In_ HWND hWnd, _In_ UINT Msg, _In_ WPARAM wParam, _In_ LPARAM lParam);public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

//implementthis.RunApi(() => Win32Api.SendMessage(treeWindow.HWnd, Win32Api.TVM_ENSUREVISIBLE, 0, remoteNodePtr));this.RunApi(() => Win32Api.SendMessage(treeWindow.HWnd, Win32Api.TVM_GETITEMRECT, 1, remoteTviRectPtr));this.RunApi(() => Win32Api.ReadProcessMemory(hProcess, remoteTviRectPtr, localTviRectPtr, new UIntPtr(sizeOfTviRect), IntPtr.Zero));getedTviRect = (Win32Api.Rect)Marshal.PtrToStructure(localTviRectPtr, typeof(Win32Api.Rect));Help.DebugWrite(this, getedTviRect.ToString());//SendInputTest(getedTviRect);this.RunApi(() => Win32Api.PostMessage(treeWindow.HWnd,    Win32Api.WM_MOUSEMOVE, 0, (getedTviRect.CenterY * 65536 + getedTviRect.CenterX)));this.RunApi(() => Win32Api.SendMessage(treeWindow.HWnd,    Win32Api.WM_LBUTTONDOWN, 0, (getedTviRect.CenterY * 65536 + getedTviRect.CenterX)));this.RunApi(() => Win32Api.SendMessage(treeWindow.HWnd,    Win32Api.WM_LBUTTONUP, 0, (getedTviRect.CenterY * 65536 + getedTviRect.CenterX)));


原创粉丝点击