Exemplo n.º 1
0
        private static void RunFormSteps(int hwndWindow, Step step)
        {
            List <IntPtr> ctrls = WinApiHelper.GetFormControls((IntPtr)hwndWindow, step.ClassName, step.Title, step.FormSteps);

            for (int idx = 0; idx < step.FormSteps.Count; idx++)
            {
                var ctrlStep = step.FormSteps[idx];
                var ctrl     = ctrls[idx];
                WinApi.SendMessage((int)ctrl, WinApi.WM_SETTEXT, 0, ctrlStep.Text);
            }
        }
Exemplo n.º 2
0
        private static void RunStep(int hwndWindow, Step step)
        {
            var sp = new Stopwatch();

            sp.Start();
            int    spend = 0;
            IntPtr ctrl  = IntPtr.Zero;

            while (spend <= step.WaitForSec && ctrl == IntPtr.Zero)
            {
                ctrl = WinApiHelper.GetChildByClassNameAndTitle((IntPtr)hwndWindow, step.ClassName, step.Title);
                if (ctrl == IntPtr.Zero)
                {
                    Thread.Sleep(1000);
                }
                spend = (int)sp.Elapsed.TotalSeconds;
            }

            sp.Stop();

            if (ctrl == IntPtr.Zero)
            {
                throw new ApplicationException($"cannot find class {step.ClassName} with title {step.Title}");
            }

            switch (step.Action)
            {
            case Actions.Click:
                WinApi.SendMessage((int)ctrl, WinApi.BN_CLICKED, 0, IntPtr.Zero);
                break;

            case Actions.SetText:
                WinApi.SendMessage((int)ctrl, WinApi.WM_SETTEXT, 0, step.Text);
                break;

            default:
                throw new NotSupportedException($"{step.Action} not supported");
            }
        }