Beispiel #1
0
 private void RegisterClass(ref WindowClassExBlittable classEx)
 {
     if (User32Methods.RegisterClassEx(ref classEx) == 0)
     {
         var errString = string.Empty;
         var err       = Kernel32Methods.GetLastError();
         // It may not always be the correct code. Since we aren't using
         // Marshal's last error. If the CLR runtime calls into the
         // system meanwhile that may be returned instead, at times.
         if (err != 0)
         {
             errString = "Possible error code: " + err;
         }
         throw new Exception("Failed to register class. " + errString);
     }
 }
        // Ввод данных логина с паролем от TWS счета
        public static void SendLoginAndPassword(IntPtr window, string login, string password, ILogger logger)
        {
            WindowInfo pwi = new WindowInfo();

            User32Methods.GetWindowInfo(window, ref pwi);

            int x = pwi.WindowRect.Left + (pwi.WindowRect.Width * 50 / 100);
            int y = pwi.WindowRect.Top + (pwi.WindowRect.Height * 47 / 100);

            User32Methods.ShowCursor(true);

            if (!User32Methods.SetForegroundWindow(window))
            {
                var err = Kernel32Methods.GetLastError();
                logger.LogDebug("SetForegroundWindow error {0}", err);
            }
            ;
            if (!User32Methods.ShowWindow(window, ShowWindowCommands.SW_RESTORE))
            {
                var err = Kernel32Methods.GetLastError();
                logger.LogDebug("ShowWindow error {0}", err);
            }
            if (!User32Methods.SetCursorPos(x, y))
            {
                var err = Kernel32Methods.GetLastError();
                logger.LogDebug("SetCursorPos error {0}", err);
            }

            GenerateInput()
            .AddMouseClick(0, 0)
            .AddMouseClick(0, 0)
            .Send(TimeSpan.FromSeconds(1));

            GenerateInput()
            .AddText(login)
            .Send(TimeSpan.FromSeconds(1));

            x = pwi.WindowRect.Left + (pwi.WindowRect.Width * 50 / 100);
            y = pwi.WindowRect.Top + (pwi.WindowRect.Height * 54 / 100);

            User32Methods.SetForegroundWindow(window);
            User32Methods.ShowWindow(window, ShowWindowCommands.SW_RESTORE);
            User32Methods.SetCursorPos(x, y);

            GenerateInput()
            .AddMouseClick(0, 0)
            .AddMouseClick(0, 0)
            .Send(TimeSpan.FromSeconds(1));

            GenerateInput()
            .AddText(password)
            .Send(TimeSpan.FromSeconds(1));

            x = pwi.WindowRect.Left + (pwi.WindowRect.Width * 50 / 100);
            y = pwi.WindowRect.Top + (pwi.WindowRect.Height * 73 / 100);

            User32Methods.SetForegroundWindow(window);
            User32Methods.ShowWindow(window, ShowWindowCommands.SW_RESTORE);
            User32Methods.SetCursorPos(x, y);

            GenerateInput()
            .AddMouseClick(0, 0)
            .Send(TimeSpan.FromSeconds(0));
        }