예제 #1
0
        private void btnAddAction_Click(object sender, EventArgs e)
        {
            Action            = new Data.Action();
            Action.ActionType = (ActionType)Enum.Parse(typeof(ActionType), cboxActionType.Text.Replace(" ", ""));

            switch (cboxActionType.Text)
            {
            case "Open Application":
                Action.ActionData = new object[]
                {
                    cboxActionValue.Text,
                    txtActionOptions.Text
                };
                break;

            case "Rename Window":
                if (txtActionOptions.Text == "")
                {
                    MessageBox.Show("You can't leave the input empty!");
                    return;
                }
                Action.ActionData = new object[]
                {
                    windows[cboxActionValue.SelectedIndex],
                    txtActionOptions.Text
                };
                break;

            case "Close Application":
                Action.ActionData = new object[]
                {
                    cboxActionValue.Text
                };
                break;

            case "Black Screen":
                MessageBox.Show(this, "Warning: Press F5 to exit the blackscreen", "HideNow", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Action.ActionData = new object[]
                {
                };
                break;

            default:
                Action.ActionData = new object[]
                {
                    windows[cboxActionValue.SelectedIndex]
                };
                break;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
예제 #2
0
        public static void TakeAction(Action action)
        {
            var data = (object[])action.ActionData;

            if (action.ActionType == ActionType.MinimizeWindow)
            {
                try
                {
                    var window = (Window)data[0];
                    WindowHide.Minimize(window);
                }
                catch (Exception ex)
                {
                    Log.WriteLog("ERROR: " + ex.ToString());
                }
            }

            else if (action.ActionType == ActionType.RenameWindow)
            {
                try
                {
                    var window = (Window)data[0];
                    var name   = (string)data[1];
                    NativeMethods.SetWindowText(window.Handle, name);
                }
                catch (Exception ex)
                {
                    Log.WriteLog("ERROR: " + ex.ToString());
                }
            }

            else if (action.ActionType == ActionType.ShowWindow)
            {
                try
                {
                    var window = (Window)data[0];
                    NativeMethodsHelper.ForceBringWindowToTop(window.Handle);
                }
                catch (Exception ex)
                {
                    Log.WriteLog("ERROR: " + ex.ToString());
                }
            }

            else if (action.ActionType == ActionType.OpenApplication)
            {
                try
                {
                    var path = (string)data[0];
                    var args = (string)data[1];
                    Process.Start(path, args);
                }
                catch (Exception ex)
                {
                    Log.WriteLog("ERROR: " + ex.ToString());
                }
            }

            else if (action.ActionType == ActionType.CloseApplication)
            {
                try
                {
                    var name       = (string)data[0];
                    var string_pid = name.Substring(4, name.IndexOf("|") - 4);
                    var pid        = int.Parse(string_pid);
                    var process    = Process.GetProcessById(pid);

                    if (process != null)
                    {
                        process.Kill();
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteLog("ERROR: " + ex.ToString());
                }
            }

            else if (action.ActionType == ActionType.CloseWindow)
            {
                try
                {
                    var window = (Window)data[0];
                    foreach (var process in Process.GetProcesses())
                    {
                        if (process.MainWindowHandle == window.Handle)
                        {
                            process.Kill();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteLog("ERROR: " + ex.ToString());
                }
            }

            else if (action.ActionType == ActionType.BlackScreen)
            {
                MiscHelper.TurnOffMonitor();
                try
                {
                }
                catch (Exception ex)
                {
                    Log.WriteLog("ERROR: " + ex.ToString());
                }
            }
        }