コード例 #1
0
        Client Manage( IntPtr hwnd , TileMode tileMode )
        {

            if ( ContainClient( hwnd ) )
            {
                return GetClient( hwnd );
            }
            WindowInfo windowInfo = new WindowInfo( );
            User32Methods.GetWindowInfo( hwnd , ref windowInfo );
            Client client = CreateClient( hwnd );
            if ( tileMode == TileMode.Tile )
            {

                WindowPlacement windowPlacement = new WindowPlacement( );
                if ( User32Methods.IsWindowVisible( client.Hwnd )  )
                {
                    User32Methods.SetWindowPlacement( hwnd , ref windowPlacement );
                }

                if ( User32Methods.IsWindowVisible( client.Hwnd )  )
                {
                    Rectangle windowRect = windowInfo.WindowRect;
                    DWM.resize( client , windowRect.Left , windowRect.Top , windowRect.Width , windowRect.Height , ScreenGeom.Rect );
                }
            }
            client.TileMode = tileMode;

            WindowManager.Attach( client , WindowManager.SelectedTag );
            return client;
        }
コード例 #2
0
        // Отправка сообщений с кодом авторизации
        public static void SendEnterSecurityCode(IntPtr window)
        {
            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 * 70 / 100);

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

            GenerateInput()
            .AddMouseClick(0, 0)
            .Send(TimeSpan.FromSeconds(1));
        }
コード例 #3
0
        // Ввод данных логина с паролем от 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));
        }
コード例 #4
0
        private void AutoProcessWindowTws(TwsWatchDogOption option)
        {
            var processs = SearchTwsProcess();

            if (processs.Count() > 1)
            {
                RestartTwsProcess();
                return;
            }

            if (processs.Count() == 0)
            {
                logger.LogDebug("TWS Process not found");
                try
                {
                    logger.LogDebug("Try start new TWS process...");
                    RunNewProcess();
                    logger.LogInformation("TWS process running successfully");
                    return;
                }
                catch (Exception e)
                {
                    logger.LogError("TWS Process not started. error: {1}:{2}", e.GetType().Name, e.Message);
                    return;
                }
            }

            foreach (var process in processs)
            {
                var state = TwsWindowState(process, option);
                switch (state.Item1)
                {
                case TwsWindowStatus.EnterSecurityCode:
                    InputHelper.SendEnterSecurityCode(state.Item2);
                    break;

                case TwsWindowStatus.AuthentificateFailed:
                    logger.LogError("Automatic authorization error. Please sign in manually");
                    RestartTwsProcess();
                    break;

                case TwsWindowStatus.AuthentificateProcess:
                    logger.LogInformation("Authentificating waitng...");
                    break;

                case TwsWindowStatus.StartingApplication:
                    logger.LogInformation("Starting application waiting...");
                    break;

                case TwsWindowStatus.LoginInput:
                    WindowInfo pwi = new WindowInfo();
                    User32Methods.GetWindowInfo(state.Item2, ref pwi);
                    logger.LogDebug("type: {1}, status: {2}, rect: {3}, style: {4}, exstyle: {5}", pwi.WindowType, pwi.WindowStatus, pwi.WindowRect, pwi.Styles, pwi.ExStyles);

                    InputHelper.SendLoginAndPassword(state.Item2, option.Login, option.Password, logger);
                    break;

                case TwsWindowStatus.ReloginIsRequired:
                    // RestartTwsProcess();
                    InputHelper.SendExitApplicationFromReloginForm();
                    // return;
                    break;

                case TwsWindowStatus.ExistingSessionDetected:
                    InputHelper.SendExitApplicationExistingSessionDetectedForm();
                    // RestartTwsProcess();
                    // return;
                    break;

                case TwsWindowStatus.Success:
                    //logger.LogDebug("Tws Window Success");
                    break;

                case TwsWindowStatus.MainWindowIsNotDrawn:
                    logger.LogInformation("Waiting main window...");
                    break;

                default:
                    logger.LogError("Unwnown Tws Window status. Failed authentification. Please log in manually");
                    break;
                }
            }

            Thread.Sleep(TimeSpan.FromSeconds(2));
        }