Пример #1
0
        private static bool remove_javascript_alert(IntPtr h, IntPtr lp)
        {
            string title = OS_Win.GetWindowText(h, 256);

            if (title == null)
            {
                return(true);
            }
            if (title.ToLower().Contains("javascript confirm"))
            {
                OS_Win.SetForegroundWindow(h);
                System.Windows.Forms.SendKeys.SendWait("{TAB}");
                System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            }
            return(true);
        }
Пример #2
0
        public async static Task <bool> set_upload_file(string path, int worker_ID)
        {
            lock (locker)
            {
                MainApp.log_info($"#{worker_ID}: Upload file dialog is opened. If it stays open, click 'Open' manually");;

                IntPtr    hnd     = IntPtr.Zero;
                IntPtr    par_hnd = IntPtr.Zero;
                Stopwatch w       = new Stopwatch();
                string[]  title   = { "Open", "Open File" };
                string    sel_t   = "N";
                w.Start();
                while (w.ElapsedMilliseconds < timeout)
                {
                    foreach (var t in title)
                    {
                        hnd = OS_Win.FindWindow("#32770", t);
                        if (hnd != IntPtr.Zero)
                        {
                            par_hnd = OS_Win.GetParent(hnd);
                            if (par_hnd != null)
                            {
                                sel_t = t;
                                break;
                            }
                        }
                    }
                    if (sel_t != "N")
                    {
                        break;
                    }
                    Thread.Sleep(100);
                }
                w.Stop();
                Thread.Sleep(500);
                if (w.ElapsedMilliseconds >= timeout)
                {
                    MainApp.log_info($"#{worker_ID}: Can not find the open file dialog. (timeout)");
                    return(false);
                }

                MainApp.log_info($"#{worker_ID}: Upload file: find window by class and name return {hnd.ToString("X4")} and the parent is {par_hnd.ToString("X4")}");

                w.Start();
                while (w.ElapsedMilliseconds < 5000)
                {
                    OS_Win.SendMessage(hnd, OS_Win.WM_ACTIVATE, (IntPtr)0, (IntPtr)0);
                    OS_Win.SetForegroundWindow(hnd);
                    string keys = "";
                    foreach (char key in path)
                    {
                        keys += "{" + key + "}";
                    }
                    System.Windows.Forms.SendKeys.SendWait(path);
                    break;
                    //StringBuilder written = new StringBuilder();
                    //OS_Win.GetDlgItemText(hnd, 0x47C, written, 512);
                    //Thread.Sleep(500);
                    //if (written.ToString() == path)
                    //    break;
                    //MainApp.log_info($"#{worker_ID}: Send key result differs. {written}-{path}");
                    //System.Windows.Forms.SendKeys.SendWait("^+{A}");
                }
                w.Stop();

                OS_Win.SetForegroundWindow(hnd);
                System.Windows.Forms.SendKeys.SendWait("%+{O}");
                Thread.Sleep(100);
                MainApp.log_info($"#{worker_ID}: Alt+O clicked. ({hnd.ToString("X4")})");
                return(true);
            }
        }