/// <summary> /// 窗口大小 /// </summary> /// <param name="hWnd"></param> /// <returns></returns> public static Rectangle GetClientRect(IntPtr hWnd) { Rectangle result = default(Rectangle); WinAPIWrapper.GetClientRect(hWnd, ref result); return(result); }
/// <summary> /// 窗口相对屏幕位置转换成父窗口位置 /// </summary> /// <param name="hWnd"></param> /// <param name="rect"></param> /// <returns></returns> public static Rectangle ScreenToClient(IntPtr hWnd, Rectangle rect) { Rectangle result = rect; WinAPIWrapper.ScreenToClient(hWnd, ref result); return(result); }
/// <summary> /// 获得窗口内容或标题 /// </summary> /// <param name="hWnd">句柄</param> /// <returns></returns> public static string GetText(IntPtr hWnd) { StringBuilder result = new StringBuilder(128); WinAPIWrapper.GetWindowText(hWnd, result, result.Capacity); return(result.ToString()); }
public static void MouseEvent(IntPtr vHandle, uint msg, int x, int y) { var lParam = ((y << 16) | x); // The coordinates var wParam = 0; // Additional parameters for the click (e.g. Ctrl) WinAPIWrapper.SendMessage(vHandle, msg, wParam, lParam); // Mouse button down //SendMessage(vHandle, Win32ApiWrapper.WM_LBUTTONUP, wParam, lParam); // Mouse button up //SendMessage(handle, upCode, wParam, lParam); // Mouse button up }
public static void MouseClick(IntPtr vHandle, int x, int y) { var lParam = ((y << 16) | x); // The coordinates var wParam = 0; // Additional parameters for the click (e.g. Ctrl) WinAPIWrapper.SendMessage(vHandle, NativeMethods.WM_LBUTTONDOWN, wParam, lParam); // Mouse button down WinAPIWrapper.SendMessage(vHandle, NativeMethods.WM_LBUTTONUP, wParam, lParam); // Mouse button up //SendMessage(handle, upCode, wParam, lParam); // Mouse button up }
/// <summary> /// 找类名 /// </summary> /// <param name="hWnd">句柄</param> /// <returns></returns> public static string GetClassName(IntPtr hWnd) { StringBuilder lpClassName = new StringBuilder(128); if (WinAPIWrapper.GetClassName(hWnd, lpClassName, lpClassName.Capacity) == 0) { throw new Exception("not found IntPtr!"); } return(lpClassName.ToString()); }
//鼠标位置的坐标 public static Point GetCursorPosPoint() { Point p = new Point(); if (WinAPIWrapper.GetCursorPos(out p)) { return(p); } return(default(Point)); }
public static List <WindowInfo> GetChildWindowsByParentHwnd(IntPtr parentHwnd) { List <WindowInfo> childWndList = new List <WindowInfo>(); WinAPIWrapper.EnumChildWindows(parentHwnd, delegate(IntPtr hWnd, int lParam) { WindowInfo wnd = new WindowInfo(); StringBuilder sb = new StringBuilder(256); wnd.hWnd = hWnd; WinAPIWrapper.GetWindowTextW(hWnd, sb, sb.Capacity); wnd.SzWindowName = sb.ToString(); WinAPIWrapper.GetClassNameW(hWnd, sb, sb.Capacity); wnd.SzClassName = sb.ToString(); childWndList.Add(wnd); return(true); }, 0); return(childWndList); }
/// <summary> /// 获取桌面所有的窗口 /// </summary> /// <returns></returns> public static WindowInfo[] GetAllDesktopWindows() { List <WindowInfo> wndList = new List <WindowInfo>(); WinAPIWrapper.EnumWindows(delegate(IntPtr hWnd, int lParam) { WindowInfo wnd = new WindowInfo(); StringBuilder sb = new StringBuilder(256); wnd.hWnd = hWnd; WinAPIWrapper.GetWindowTextW(hWnd, sb, sb.Capacity); wnd.SzWindowName = sb.ToString(); WinAPIWrapper.GetClassNameW(hWnd, sb, sb.Capacity); wnd.SzClassName = sb.ToString(); wndList.Add(wnd); return(true); }, 0); return(wndList.ToArray()); }
/// <summary> /// 获取某 URL 的 Cookie 返回字符串 /// </summary> /// <param name="Url"></param> /// <returns></returns> public static string GetCookie(string Url) { uint Datasize = 1024; StringBuilder cookieData = new StringBuilder((int)Datasize); if (!WinAPIWrapper.InternetGetCookieEx(Url, null, cookieData, ref Datasize, 0x2000, IntPtr.Zero)) { if (Datasize < 0) { return(null); } cookieData = new StringBuilder((int)Datasize); if (!WinAPIWrapper.InternetGetCookieEx(Url, null, cookieData, ref Datasize, 0x00002000, IntPtr.Zero)) { return(null); } } return(cookieData.ToString()); }
/// <summary> /// 设置键盘Hook /// </summary> /// <param name="lpfn"></param> /// <returns></returns> public static IntPtr SetKeyboardHookEx(LowLevelKeyboardProc lpfn) { return(WinAPIWrapper.SetWindowsHookEx(NativeMethods.WH_KEYBOARD_LL, lpfn, IntPtr.Zero, 0)); }
/// <summary> /// 给窗口发送内容 /// </summary> /// <param name="hWnd">句柄</param> /// <param name="lParam">要发送的内容</param> public static void SetText(IntPtr hWnd, string lParam) { WinAPIWrapper.SendMessage(hWnd, NativeMethods.WM_SETTEXT, IntPtr.Zero, lParam); }
/// <summary> /// 子窗口句柄 /// </summary> /// <param name="hwndParent">父窗口句柄</param> /// <param name="hwndChildAfter">前一个同目录级同名窗口句柄</param> /// <param name="lpszClass">类名</param> /// <returns></returns> public static IntPtr GetChildHandle(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass) { return(WinAPIWrapper.FindWindowEx(hwndParent, hwndChildAfter, lpszClass, null)); }
public static IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam) { return(WinAPIWrapper.CallNextHookEx(hhk, nCode, wParam, lParam)); }
/// <summary> /// 全局修改UserAgent /// </summary> public static void SetUserAgent(string userAgent) { WinAPIWrapper.UrlMkSetSessionOption(NativeMethods.URLMON_OPTION_USERAGENT, userAgent, userAgent.Length, 0); }
/// <summary> /// 找到句柄 /// </summary> /// <param name="IpClassName">类名</param> /// <returns></returns> public static IntPtr GetHandle(string IpClassName) { return(WinAPIWrapper.FindWindow(IpClassName, null)); }
/// <summary> /// 反注册热键 /// </summary> /// <param name="handle"></param> /// <param name="id"></param> /// <returns></returns> public static bool UnRegisterHotKey(IntPtr handle, int id) { return(WinAPIWrapper.UnregisterHotKey(handle, id)); }
/// <summary> /// 注册热键 /// </summary> /// <param name="handle"></param> /// <param name="id"></param> /// <param name="virtualCode"></param> /// <param name="modifiers"></param> /// <returns></returns> public static bool RegisterHotKey(IntPtr handle, int id, uint modifiers, uint virtualCode) { return(WinAPIWrapper.RegisterHotKey(handle, id, (uint)modifiers, virtualCode)); }
public static void GetInfo(IntPtr vHandle) { WinAPIWrapper.SendMessage(vHandle, NativeMethods.WM_COMMAND, NativeMethods.IDM_VIEWSOURCE, (int)vHandle); }
public static IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId) { return(WinAPIWrapper.SetWindowsHookEx(idHook, lpfn, hMod, dwThreadId)); }
/// <summary> /// 真实的鼠标操作 /// </summary> /// <param name="dwFlags"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static int DeviceMouseEvent(int dwFlags, int dx, int dy) { return(WinAPIWrapper.mouse_event(dwFlags, dx, dy, 0, 0)); }
public static void UnhookWindowsHookEx(IntPtr hhk) { WinAPIWrapper.UnhookWindowsHookEx(hhk); }
/// <summary> /// 找到句柄 /// </summary> /// <param name="p">坐标</param> /// <returns></returns> public static IntPtr GetHandle(Point p) { return(WinAPIWrapper.WindowFromPoint(p)); }