public static string GetClassName(IntPtr hwnd, int maxLen) { StringBuilder sb = new StringBuilder(maxLen); Api_User32.GetClassName(hwnd, sb, sb.Capacity); return(sb.ToString()); }
public static string GetWindowTitle(IntPtr hWnd, int maxLen) { StringBuilder sb = new StringBuilder(maxLen); Api_User32.GetWindowText(hWnd, sb, sb.Capacity); return(sb.ToString()); }
public static int GetWindowProcessID(IntPtr hWnd) { int procId; Api_User32.GetWindowThreadProcessId(hWnd, out procId); return(procId); }
public static string SetTextContent(IntPtr hWnd) { StringBuilder sb = new StringBuilder(); Api_User32.SendMessage(hWnd, (int)Win32Messages.WM_SETTEXT, (IntPtr)sb.Capacity, sb); return(sb.ToString()); }
public static IntPtr CreateCursor(Bitmap xor, Bitmap and, int xHotspot, int yHotspot) { ImageConverter ic = new ImageConverter(); byte[] bfrXor = (byte[])ic.ConvertTo(xor, typeof(byte[])); byte[] bfrAnd = (byte[])ic.ConvertTo(and, typeof(byte[])); return(Api_User32.CreateCursor(IntPtr.Zero, xHotspot, yHotspot, and.Width, and.Height, bfrAnd, bfrXor)); }
public static IntPtr SendMessage(IntPtr hWnd, Win32Messages msg, int wParam, IntPtr lParam) { IntPtr retVal = Api_User32.SendMessage(hWnd, (int)msg, wParam, lParam); //if (retVal.ToInt32() > 0) // throw new Win32Exception(retVal.ToInt32(), "An error occured while sending the window message."); return(retVal); }
public static WindowPlacement GetWindowPlacement(IntPtr hWnd) { WindowPlacement wplc = new WindowPlacement(); if (!Api_User32.GetWindowPlacement(hWnd, ref wplc)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "An error occured trying to obtain window placement information."); } return(wplc); }
public static ScrollBarInfo GetScrollBarInfo(IntPtr hwnd, ScrollBarObjectID objId) { ScrollBarInfo info = new ScrollBarInfo(); info.cbSize = Marshal.SizeOf(info); if (Api_User32.GetScrollBarInfo(hwnd, (uint)objId, ref info) != IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error(), "Unable to obtain scrollbar information."); } return(info); }
public static WindowInfo GetWindowInfo(IntPtr hwnd) { WindowInfo wnfo = new WindowInfo(); wnfo.cbSize = Marshal.SizeOf(wnfo); if (!Api_User32.GetWindowInfo(hwnd, ref wnfo)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "Unable to retrieve window information."); } return(wnfo); }
public static uint SendInput(INPUT[] inputs) { if (inputs.Length > 0) { return(Api_User32.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(inputs[0]))); } else { return(0); } }
public static List <string> GetListContent(IntPtr hWnd) { List <string> lst = new List <string>(); int count = (int)Api_User32.SendMessage(hWnd, (int)Win32Messages.LB_GETCOUNT, IntPtr.Zero, null); for (int i = 0; i < count; i++) { StringBuilder sb = new StringBuilder(); Api_User32.SendMessage(hWnd, Win32Const.WM_GETTEXT, (IntPtr)i, sb); lst.Add(sb.ToString()); } return(lst); }
public static Rectangle GetClientRect(IntPtr hWnd) { RECT bnds = new RECT(); if (Api_User32.GetClientRect(hWnd, ref bnds)) { return(new Rectangle(bnds.left, bnds.top, bnds.Width, bnds.Height)); } else { return(Rectangle.Empty); } }
//*************************************************************************** // USER32 - Input public static void SendKeyPress(VK key) { INPUT[] inp = new INPUT[1]; inp[0].type = Win32Const.INPUT_KEYBOARD; inp[0].ki.wScan = 0; inp[0].ki.dwFlags = 0; inp[0].ki.time = 0; inp[0].ki.wVk = (ushort)key; inp[0].ki.dwExtraInfo = Api_User32.GetMessageExtraInfo(); Win32.SendInput(inp); // And now send the key release. inp[0].ki.dwFlags = Win32Const.KEYEVENTF_KEYUP; Win32.SendInput(inp); }
public static void SetMousePosition(int dx, int dy, bool relative) { INPUT[] inp = new INPUT[1]; inp[0].type = Win32Const.INPUT_MOUSE; if (relative) { inp[0].mi.dwFlags = Win32Const.MOUSEEVENTF_MOVE; } else { inp[0].mi.dwFlags = Win32Const.MOUSEEVENTF_MOVE | Win32Const.MOUSEEVENTF_ABSOLUTE; } inp[0].mi.dx = dx; inp[0].mi.dy = dy; inp[0].mi.mouseData = 0; inp[0].mi.time = 0; inp[0].mi.dwExtraInfo = Api_User32.GetMessageExtraInfo(); Win32.SendInput(inp); }
public static List <IntPtr> GetChildWindows(IntPtr hwndParent) { List <IntPtr> result = new List <IntPtr>(); GCHandle listHandle = GCHandle.Alloc(result); try { Win32Callback childProc = new Win32Callback(EnumWindow); Api_User32.EnumChildWindows(hwndParent, childProc, GCHandle.ToIntPtr(listHandle)); } finally { if (listHandle.IsAllocated) { listHandle.Free(); } } return(result); }
public static bool ShowCaret(IntPtr hWnd) { return(Api_User32.ShowCaret(hWnd)); }
public static bool HideCaret(IntPtr hWnd) { return(Api_User32.HideCaret(hWnd)); }
public static IntPtr FindWindow(string className, string windowName) { return(Api_User32.FindWindow(className, windowName)); }
public static IntPtr FindWindowEx(IntPtr parentHandle, string className) { return(Api_User32.FindWindowEx(parentHandle, IntPtr.Zero, className, IntPtr.Zero)); }
public static void ReleaseCursor(IntPtr hCursor) { Api_User32.DestroyCursor(hCursor); }
public static void SetCursor(IntPtr hCursor) { Api_User32.SetCursor(hCursor); }
public static IntPtr GetParent(IntPtr hWnd) { return(Api_User32.GetParent(hWnd)); }
public static void ReleaseDeviceContext(HandleRef hWnd, IntPtr hDC) { Api_User32.ReleaseDC(hWnd, hDC); }
public static IntPtr GetDeviceContext(HandleRef hWnd) { return(Api_User32.GetDC(hWnd)); }
public static void RedrawWindow(IntPtr hwnd, RedrawWindowFlags flags) { Api_User32.RedrawWindow(hwnd, IntPtr.Zero, IntPtr.Zero, (uint)flags); }
public static bool IsWindowVisible(IntPtr hWnd) { return(Api_User32.IsWindowVisible(hWnd)); }
public static bool BlockInputOn() { return(Api_User32.BlockInput(true)); }
public static IntPtr GetWindowFromPoint(Point pt) { return(Api_User32.WindowFromPoint(pt)); }
public static bool BlockInputOff() { return(Api_User32.BlockInput(false)); }
public static void SetFocus(IntPtr hWnd) { Api_User32.SetFocus(hWnd); }