/// <summary> /// Links-Klick /// </summary> public static void MouseLeftClick() { //uint X = (uint)Cursor.Position.X; //uint Y = (uint)Cursor.Position.Y; //Win32User.mouse_event(Win32User.MOUSEEVENTF_LEFTDOWN | Win32User.MOUSEEVENTF_LEFTUP, X, Y, 0, 0); // oder //Win32User.mouse_event(Win32User.MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0); //Win32User.mouse_event(Win32User.MOUSEEVENTF_LEFTUP, X, Y, 0, 0); Win32User.Input[] MouseEvent = new Win32User.Input[2]; MouseEvent[0].Type = 0; MouseEvent[0].Data = new Win32User.MouseInput() { X = 0, Y = 0, MouseData = 0, Time = 0, DwFlags = Win32User.MOUSEEVENTF_LEFTDOWN }; MouseEvent[1].Type = 0; MouseEvent[1].Data = new Win32User.MouseInput() { X = 0, Y = 0, MouseData = 0, Time = 0, DwFlags = Win32User.MOUSEEVENTF_LEFTUP }; Win32User.SendInput((uint)MouseEvent.Length, MouseEvent, Marshal.SizeOf(MouseEvent[0].GetType())); }
/// <summary> /// liefert das oberste Fenster under der Position /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public static IntPtr WindowUnderPosition(int x, int y) { Win32User.Point p = new Win32User.Point() { X = x, Y = y }; return(Win32User.WindowFromPoint(p)); }
/// <summary> /// liefert den Text (i.A. Caption) des Fensters /// </summary> /// <returns></returns> public string GetText() { Int32 size = Win32User.SendMessage(hWnd, Win32User.WM_GETTEXTLENGTH, 0, 0).ToInt32(); if (size > 0) // sonst kein Text { StringBuilder title = new StringBuilder(size + 1); Win32User.SendMessage(hWnd, Win32User.WM_GETTEXT, title.Capacity, title); return(title.ToString()); } return(""); }
/// <summary> /// liefert die Prozess-ID zum Fenster /// </summary> /// <param name="hWnd"></param> /// <param name="bIsProgWindow"></param> /// <returns></returns> public uint GetProcessId(bool bIsProgWindow = true) { IntPtr hWnd = this.hWnd; if (!bIsProgWindow) // Programmfenster ermitteln { hWnd = Win32User.GetAncestor(hWnd, Win32User.GetAncestorFlags.GetRoot); } uint processId; Win32User.GetWindowThreadProcessId(hWnd, out processId); return(processId); }
/// <summary> /// liefert die Clientkoordinaten zu den Bildschirmkoordinaten /// </summary> /// <param name="pt"></param> /// <returns></returns> public Point ScreenToClient(Point pt) { Win32User.Point winpt = new Win32User.Point() { X = pt.X, Y = pt.Y }; if (Win32User.ScreenToClient(hWnd, ref winpt)) { return(new Point(winpt.X, winpt.Y)); } return(Point.Empty); }
Int32 EnumChildWindowProc(Int32 hwnd, Int32 lParam) { StringBuilder classBuilder = new StringBuilder(64); Win32User.GetClassName(hwnd, classBuilder, 64); ApiWindow window = new ApiWindow(new IntPtr(hwnd), classBuilder.ToString()); if (childClass.Length == 0 || window.ClassName.ToLower() == childClass) { WindowList.Add(window); } return(1); }
/// <summary> /// Mausbewegung /// </summary> /// <param name="x">neue Position</param> /// <param name="y">neue Position</param> public static void MouseMove(int x, int y) { x = x * 65535 / System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; y = y * 65535 / System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; Win32User.Input[] MouseEvent = new Win32User.Input[1]; MouseEvent[0].Type = 0; MouseEvent[0].Data = new Win32User.MouseInput() { X = x, Y = y, MouseData = 0, Time = 0, DwFlags = Win32User.MOUSEEVENTF_ABSOLUTE | Win32User.MOUSEEVENTF_MOVE }; Win32User.SendInput((uint)MouseEvent.Length, MouseEvent, Marshal.SizeOf(MouseEvent[0].GetType())); }
//public unsafe static string GetPanelText1(IntPtr hStatusBar, int pos) { // string text = ""; // // Programmfenster ermitteln // IntPtr hwnd = GetAncestor(hStatusBar, GetAncestorFlags.GetRoot); // // Prozess-ID ermitteln // uint processId; // uint threadId = GetWindowThreadProcessId(hwnd, out processId); // if (processId > 0) { // // Prozess öffnen // IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, processId); // if (hProcess != IntPtr.Zero) { // // Remote-Puffer anlegen // const int BUFFER_SIZE = 0x1000; // IntPtr ipRemoteBuffer = VirtualAllocEx(hProcess, IntPtr.Zero, new IntPtr(BUFFER_SIZE), AllocationType.COMMIT, MemoryProtection.READWRITE); // if (ipRemoteBuffer != IntPtr.Zero) { // // Textlänge und Text ermitteln // int chars = SendMessage(hStatusBar.ToInt32(), SB_GETTEXT, pos, ipRemoteBuffer.ToInt32()); // if (chars >= 0) { // byte[] localBuffer = new byte[BUFFER_SIZE]; // fixed (byte* pLocalBuffer = localBuffer) { // IntPtr ipLocalBuffer = new IntPtr(pLocalBuffer); // Int32 dwBytesRead = 0; // IntPtr ipBytesRead = new IntPtr(&dwBytesRead); // // Remote-Puffer in den lokalen Puffer einlesen // bool b4 = ReadProcessMemory(hProcess, ipRemoteBuffer, localBuffer, BUFFER_SIZE, out ipBytesRead); // //bool b4 = ReadProcessMemory(hProcess, ipRemoteBuffer, ipLocalBuffer, BUFFER_SIZE, out ipBytesRead); // if (b4) { // // Umwandlung in Text // text = Marshal.PtrToStringUni(ipLocalBuffer, chars); // if (text == " ") // text = String.Empty; // } // } // } // VirtualFreeEx(hProcess, ipRemoteBuffer, 0, FreeType.Release); // } // CloseHandle(hProcess); // } // } // return text; //} /// <summary> /// ermittelt den Text einer Statusbar /// </summary> /// <param name="hStatusBar"></param> /// <param name="pos">Position 0, ...</param> /// <returns></returns> public static string GetPanelText(IntPtr hStatusBar, int pos) { string text = ""; // Programmfenster ermitteln IntPtr hwnd = Win32User.GetAncestor(hStatusBar, Win32User.GetAncestorFlags.GetRoot); // Prozess-ID ermitteln uint processId; uint threadId = Win32User.GetWindowThreadProcessId(hwnd, out processId); if (processId > 0) { // Prozess öffnen IntPtr hProcess = Win32Kernel.OpenProcess(Win32Kernel.ProcessAccessFlags.All, false, processId); if (hProcess != IntPtr.Zero) { // Remote-Puffer anlegen const int BUFFER_SIZE = 0x1000; IntPtr ipRemoteBuffer = Win32Kernel.VirtualAllocEx(hProcess, IntPtr.Zero, new IntPtr(BUFFER_SIZE), Win32Kernel.AllocationType.COMMIT, Win32Kernel.MemoryProtection.READWRITE); if (ipRemoteBuffer != IntPtr.Zero) { // Textlänge und Text ermitteln int chars = Win32User.SendMessage(hStatusBar, Win32User.SB_GETTEXT, pos, ipRemoteBuffer.ToInt32()).ToInt32(); if (chars >= 0) { byte[] localBuffer = new byte[BUFFER_SIZE]; IntPtr ipBytesRead = new IntPtr(0); // Remote-Puffer in den lokalen Puffer einlesen if (Win32Kernel.ReadProcessMemory(hProcess, ipRemoteBuffer, localBuffer, BUFFER_SIZE, out ipBytesRead)) { // Umwandlung in Text text = System.Text.Encoding.Unicode.GetString(localBuffer).Substring(0, chars); if (text == " ") { text = String.Empty; } } } Win32Kernel.VirtualFreeEx(hProcess, ipRemoteBuffer, 0, Win32Kernel.FreeType.Release); } Win32Kernel.CloseHandle(hProcess); } } return(text); }
/// <summary> /// versucht, das Fenster in den Vordergrund zu setzen /// </summary> /// <returns></returns> public bool SetForeground() { return(Win32User.SetForegroundWindow(hWnd)); }
/// <summary> /// 1. Fenster dieser Klasse und mit dieser Überschrift /// </summary> /// <param name="classname"></param> /// <param name="caption"></param> public ApiWindow(string classname, string caption) { ClassName = classname; hWnd = Win32User.FindWindow(classname, caption); }
/// <summary> /// erzeugt eine Liste der Child-Windows /// </summary> /// <param name="hWndParent">Parent-Window</param> /// <param name="childClass">Klassenname der Child-Windows</param> public ChildWindows(IntPtr hWndParent, string childClass = null) { WindowList = new List <ApiWindow>(); this.childClass = string.IsNullOrEmpty(childClass) ? "" : childClass.ToLower(); Win32User.EnumChildWindows(hWndParent.ToInt32(), EnumChildWindowProc, 0); }
/// <summary> /// liefert die Clientgröße (Position ist immer 0,0) /// </summary> /// <returns></returns> public Rectangle ClientRect() { Win32User.RECT result; Win32User.GetClientRect(hWnd, out result); return(new Rectangle(result.Left, result.Top, result.Right - result.Left, result.Bottom - result.Top)); }