Exemplo n.º 1
0
 private IntPtr GetValueControlByHandle(Process p, int ID, string title)
 {
     try
     {
         Thread.Sleep(0x3e8);
         IntPtr            mainWindowHandle = p.MainWindowHandle;
         List <HwndObject> children         = HwndObject.GetWindowByTitle(title).GetChildren();
         IntPtr            zero             = IntPtr.Zero;
         int num2 = -1;
         for (int i = 0; i < children.Count; i++)
         {
             if (GetDlgCtrlID(children[i].Hwnd) == ID)
             {
                 num2 = i;
                 zero = children[i].Hwnd;
                 break;
             }
         }
         return(zero);
     }
     catch (Exception exception)
     {
         CtlError.WriteError("ErroLog", "get ValueControlByHandle by title Loi khi set handle tren form", exception.Message);
         return(IntPtr.Zero);
     }
 }
Exemplo n.º 2
0
        public static WindowInfo GetWindow(string windowTitle, Size screenSize)
        {
            HwndObject window = HwndObject.GetWindowByTitle(windowTitle);

            if (window == null)
            {
                throw new ApplicationException(string.Format("Window '{0}' not found", windowTitle));
            }

            var parts = window.Title.Split('-');

            Bitmap   bitmap         = new Bitmap(screenSize.Width, screenSize.Height);
            Graphics memoryGraphics = Graphics.FromImage(bitmap);
            IntPtr   dc             = memoryGraphics.GetHdc();
            bool     success        = Win32.PrintWindow(window.Hwnd, dc, 0);

            memoryGraphics.ReleaseHdc(dc);

            return(new WindowInfo
            {
                Title = window.Title,
                TableName = parts.Length > 2 ? parts[2].Trim() : window.Title,
                Size = window.Size,
                Bitmap = bitmap
            });
        }
Exemplo n.º 3
0
 private void refreshWindowButton_Click(object sender, EventArgs e)
 {
     handle           = HwndObject.GetWindowByTitle(windowsComboBox.Text);
     widthField.Text  = handle.Size.Width.ToString();
     heightField.Text = handle.Size.Height.ToString();
     xField.Text      = handle.Location.X.ToString();
     yField.Text      = handle.Location.Y.ToString();
 }
Exemplo n.º 4
0
        public static IEnumerable <WindowInfo> GetWindowList(Size screenSize, Size targetSize, params WindowExtractor[] tableNameExtractors)
        {
            foreach (var extractor in tableNameExtractors)
            {
                var ws = HwndObject
                         .GetWindows();
                var windows = ws
                              .Select(w => new { Room = extractor.Name, Window = w, TableName = extractor.Extractor(w.Title) })
                              .Where(w => !string.IsNullOrEmpty(w.TableName));
                foreach (var window in windows)
                {
                    var size = window.Window.Size;
                    if (targetSize != size)
                    {
                        Console.WriteLine($"Current size {size.Width}x{size.Height}, resizing to {targetSize.Width}x{targetSize.Height}");
                        HwndObject.GetWindowByTitle(window.Window.Title).Size = targetSize;
                        continue;
                    }

                    Bitmap   bitmap         = new Bitmap(size.Width, size.Height);
                    Graphics memoryGraphics = Graphics.FromImage(bitmap);
                    IntPtr   dc             = memoryGraphics.GetHdc();
                    bool     success        = Win32.PrintWindow(window.Window.Hwnd, dc, 0);
                    memoryGraphics.ReleaseHdc(dc);

                    if (true)
                    {
                        RECT rect = new RECT();
                        if (Win32.GetWindowRect(window.Window.Hwnd, ref rect))
                        {
                            int width  = rect.right - rect.left;
                            int height = rect.bottom - rect.top;

                            bitmap = new Bitmap(width, height);
                            Graphics graphics = Graphics.FromImage(bitmap);
                            graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
                        }
                    }

                    yield return(new WindowInfo
                    {
                        Room = window.Room,
                        Title = window.Window.Title,
                        TableName = window.TableName,
                        Size = size,
                        Bitmap = bitmap
                    });
                }
            }
        }
Exemplo n.º 5
0
        public Game(PictureBox pictureBox1)
        {
            OpponentTeam = new List <Poke>();
            OwnTeam      = new List <Poke>();
            Board        = new Board();
            //System.Drawing.Bitmap table = (Bitmap)Bitmap.FromFile(@"c:\users\frick\documents\visual studio 2017\Projects\ConsoleApp1\ConsoleApp1\Images\op1.png");

            HwndObject blueStacksWindow = HwndObject.GetWindowByTitle(GameWindowTitle);

            blueStacksWindow.Location = new Point(10, 100);
            SetForegroundWindow(blueStacksWindow.Hwnd);
            blueStacksWindow = HwndObject.GetWindowByTitle(GameWindowTitle);
            var location = blueStacksWindow.Location;
            var size     = blueStacksWindow.Size;

            Rectangle formBounds = new Rectangle(location.X + 500, location.Y + 184, size.Width - 680, size.Height - 130);

            Bitmap bmp = new Bitmap(formBounds.Width, formBounds.Height);

            SetForegroundWindow(blueStacksWindow.Hwnd);
            using (Graphics g = Graphics.FromImage(bmp))
                g.CopyFromScreen(formBounds.Location, Point.Empty, formBounds.Size);

            //Console.WriteLine("Own Team");
            var idBoard = ConvertToFormat(bmp, PixelFormat.Format24bppRgb);

            OwnTeam = PokeFinder.FindPokes(idBoard, PokeFinder.Teams.Own, pictureBox1);
            //OwnTeam.ForEach(pok => Console.WriteLine(pok.Name));
            ConvertOwnTeamCoordsToBoard();
            //int benchc = 0;
            //foreach (var benchPos in Board._MyBench)
            //{
            //    var OcName = benchPos.Occupant != null ? benchPos.Occupant.Name : "";
            //    //Console.WriteLine($"Bench{benchc++}: {OcName}");
            //}
            //Console.WriteLine("Opponent Team");
            OpponentTeam = PokeFinder.FindPokes(idBoard, PokeFinder.Teams.Opponent, pictureBox1);
            //OpponentTeam.ForEach(pok => Console.WriteLine(pok.Name));
            ConvertOpponentTeamCoordsToBoard();
            //benchc = 0;
            //foreach (var benchPos in Board._OpponentBench)
            //{
            //    var OcName = benchPos.Occupant != null ? benchPos.Occupant.Name : "";
            //    //Console.WriteLine($"Bench{benchc++}: {OcName}");
            //}
            bmp.Save($"board_{DateTime.Now:ddMMyyyyhhmm}.jpg", ImageFormat.Jpeg);

            Console.Write(Board.ToString());
        }
Exemplo n.º 6
0
        private void windowsComboBox_TextChanged(object sender, EventArgs e)
        {
            if (windowsComboBox.Text.Length == 0)
            {
                xField.ResetText(); yField.ResetText(); widthField.ResetText(); heightField.ResetText();
            }
            else
            {
                handle = HwndObject.GetWindowByTitle(windowsComboBox.Text);

                if (populateOnChange && windowsComboBox.Text[0] != wildcard)
                {
                    widthField.Text           = handle.Size.Width.ToString();
                    heightField.Text          = handle.Size.Height.ToString();
                    xField.Text               = handle.Location.X.ToString();
                    yField.Text               = handle.Location.Y.ToString();
                    translateCheckbox.Checked = false;
                }
            }
        }
Exemplo n.º 7
0
 private string getValueControlByHandle(string title)
 {
     try
     {
         Process       process  = Process.GetProcessesByName("Openvpn-Gui")[0];
         Process       process2 = Process.GetProcessesByName("Openvpn")[0];
         IntPtr        dlgItem  = GetDlgItem(process.MainWindowHandle, 0xa1);
         IntPtr        ptr2     = FindWindowEx(process.MainWindowHandle, IntPtr.Zero, "Static", "Current State: Connecting");
         IntPtr        handle   = process.Handle;
         StringBuilder lpString = new StringBuilder(0xffff);
         GetWindowText(dlgItem, lpString, 50);
         IntPtr            mainWindowHandle = process2.MainWindowHandle;
         string            mainWindowTitle  = process.MainWindowTitle;
         List <HwndObject> children         = HwndObject.GetWindows()[0].GetChildren();
         return(HwndObject.GetWindowByTitle(title).Title);
     }
     catch (Exception)
     {
         return("");
     }
 }
Exemplo n.º 8
0
 private void setValueControlByHandleByTitle(Process p, int ID, string valueIP, string title)
 {
     try
     {
         Thread.Sleep(0x3e8);
         IntPtr            mainWindowHandle = p.MainWindowHandle;
         List <HwndObject> children         = HwndObject.GetWindowByTitle(title).GetChildren();
         int num2 = -1;
         for (int i = 0; i < children.Count; i++)
         {
             if (GetDlgCtrlID(children[i].Hwnd) == ID)
             {
                 num2 = i;
                 break;
             }
         }
         children[num2].Text = valueIP;
     }
     catch (Exception exception)
     {
         CtlError.WriteError("ErroLog", "setValueControlByHandle Loi khi set handle tren form", exception.Message);
     }
 }
Exemplo n.º 9
0
        public static Point Focus(string windowTitle)
        {
            HwndObject windowHwnd = HwndObject.GetWindowByTitle(windowTitle);

            if (windowHwnd == null)
            {
                throw new ApplicationException(string.Format("Window '{0}' not found", windowTitle));
            }

            // Bring window to front
            IntPtr realHwnd;
            int    loop = 3;

            do
            {
                Win32.SetForegroundWindow(windowHwnd.Hwnd);
                realHwnd = Win32.GetForegroundWindow();
                loop--;
            }while (realHwnd != windowHwnd.Hwnd && loop > 0);


            return(windowHwnd.Location);
        }
Exemplo n.º 10
0
        public Form1()
        {
            InitializeComponent();

            var npad = HwndObject.GetWindowByTitle("Untitled - Notepad");
        }