Example #1
0
        private void ActivatePreviousWindow(IntPtr hwnd = default(IntPtr))
        {
            if (hwnd == IntPtr.Zero)
            {
                hwnd = User32Windows.GetLastActiveWindow(hwndExcept: this.Handle, exceptNames: m_ExceptPasswordWindows).Handle;
            }

            User32Windows.SetForegroundWindow(hwnd);
        }
Example #2
0
        private void SendCommandToolForm_MouseHover(object sender, EventArgs e)
        {
            if (this.ActivateOnHover && !m_Activated)
            {
                if (this.Owner != null)
                {
                    var foreground = User32Windows.GetForegroundWindow();
                    User32Windows.SetForegroundWindow(this.Owner.Handle);
                    User32Windows.SetForegroundWindow(foreground);
                }

                User32Windows.SetForegroundWindow(this.Handle);
                this.m_Activated = true;
            }
        }
        private void runningAppsContextMenuStrip_Opening(object sender, CancelEventArgs e)
        {
            var runningWindows = User32Windows.GetDesktopWindows();

            RefreshWindowsLists(runningWindows);

            var backupMenuItems = BackupMenuItems();

            runningAppsContextMenuStrip.Items.Clear();
            var count = 0;

            for (int i = 0; i < m_RunningWindows.Count; i++)
            {
                if (m_RunningWindows[i].IsVisible)
                {
                    var title = m_RunningWindows[i].Title;
                    if (title == "Пуск" ||
                        title == "Program Manager" ||
                        title == "Windows Shell Experience Host")
                    {
                        m_RunningWindows.RemoveAt(i);
                        i--;
                        continue;
                    }

                    runningAppsContextMenuStrip.Items.Add(title, m_RunningWindows[i].Icon != null
                        ? m_RunningWindows[i].Icon.ToBitmap() : null);
                    var countMenu = count;
                    runningAppsContextMenuStrip.Items[count].Click += (senderMenu, eMenu) =>
                    {
                        IntPtr h = m_RunningWindows[countMenu].Handle;

                        User32Windows.SetForegroundWindow(h);
                        if (User32Windows.IsIconic(h))
                        {
                            User32Windows.ShowWindow(m_RunningWindows[countMenu].Handle, User32Windows.SW_RESTORE);
                        }
                    };

                    count++;
                }
            }

            RestoreMenuItems(backupMenuItems);
        }
Example #4
0
        private void TransparentWindowToolForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control)
            {
                m_CtrlKey = true;
                return;
            }
            if (e.Alt)
            {
                m_AltKey = true;
                return;
            }

            switch (e.KeyData)
            {
            case Keys.D0:
            case Keys.NumPad0:
                CheckFirstRun();
                byte transparency = 0;
                SetLayeredWindowAttributes(m_Handle, 0, transparency, LWA_ALPHA);
                break;

            case Keys.D1:
            case Keys.NumPad1:
                CheckFirstRun();
                SetLayeredWindowAttributes(m_Handle, 0, m_Transparency, LWA_ALPHA);
                break;

            case Keys.Up:
                User32Windows.SetForegroundWindow(m_Handle);
                Thread.Sleep(100);
                SendKeys.Send("{UP}");
                User32Windows.SetForegroundWindow(this.Handle);
                break;

            case Keys.Down:
                User32Windows.SetForegroundWindow(m_Handle);
                Thread.Sleep(100);
                SendKeys.Send("{DOWN}");
                User32Windows.SetForegroundWindow(this.Handle);
                break;
            }
        }
        private void ShowToolsOverOtherWindows()
        {
            // We need activate some window of our program,
            // otherwise tools cannot be activated and showed over other windows.

            var foreground = User32Windows.GetForegroundWindow();

            User32Windows.SetForegroundWindow(this.Handle);

            //

            foreach (var t in m_Tools)
            {
                User32Windows.SetForegroundWindow(t.Handle);
            }

            //

            User32Windows.SetForegroundWindow(foreground);
        }
Example #6
0
        private void ProcessWindows()
        {
            Point p = Cursor.Position;

            foreach (var h in m_TrackedWindows)
            {
                Rectangle r;
                User32Windows.GetWindowRect(h, out r);

                if (p.X >= r.X && p.X <= r.Width &&
                    p.Y >= r.Y && p.Y <= r.Height)
                {
                    var hCurrent = User32Windows.GetForegroundWindow();
                    if (hCurrent != h)
                    {
                        User32Windows.SetForegroundWindow(h);
                    }

                    break;
                }
            }
        }
Example #7
0
        private void TransparentWindowToolForm_MouseClick(object sender, MouseEventArgs e)
        {
            m_ClicksCount++;
            if (m_ClicksCount >= ClicksToShow)
            {
                if (User32Windows.IsIconic(m_Handle))
                {
                    User32Windows.ShowWindow(m_Handle, User32Windows.SW_RESTORE);
                }
                else
                {
                    User32Windows.ShowWindow(m_Handle, User32Windows.SW_SHOW);
                }

                User32Windows.SetForegroundWindow(m_Handle);
                if (!this.m_ActivateTarget)
                {
                    User32Windows.SetForegroundWindow(this.Handle);
                }

                m_ClicksCount = ClicksToShow;
            }
        }
        private void btnSendCommands_Click(object sender, EventArgs e)
        {
            this.TopMost = false;

            IntPtr hwnd = (IntPtr)int.Parse(txtHwnd.Text);

            if (!User32Windows.SetForegroundWindow(hwnd))
            {
                MessageBox.Show("Window not found. Try to refresh list.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Thread.Sleep(200);

            var commands = txtCommands.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None);

            for (int i = 0; i < commands.Length; i++)
            {
                Thread.Sleep(200);
                SendKeys.SendWait(commands[i]);
            }

            this.TopMost = true;
        }
Example #9
0
        private void ProcessClick()
        {
            if (!m_IsRunning)
            {
                return;
            }

            if (!User32Windows.IsWindow(m_HostWindowHwnd))
            {
                MessageBox.Show("Hosting window not found. Close the tool or set its hosting window.",
                                this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (this.m_SendCommandType == SendCommandType.ActivateWindow)
            {
                int handleTmp;
                if (int.TryParse(m_Commands, out handleTmp))
                {
                    var handle = (IntPtr)handleTmp;
                    if (User32Windows.IsIconic(handle))
                    {
                        User32Windows.ShowWindow(handle, User32Windows.SW_RESTORE);
                    }
                    User32Windows.SetForegroundWindow(handle);
                }
                else
                {
                    MessageBox.Show(String.Format("Window {0} not found.", m_Commands),
                                    this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }
            else if (this.m_SendCommandType == SendCommandType.ActivateLastN)
            {
                int lastN;
                if (int.TryParse(m_Commands, out lastN))
                {
                    var handle = IntPtr.Zero;

                    var windows = User32Windows.GetDesktopWindows(getIcons: false);

                    int currentProcId;
                    User32Windows.GetWindowThreadProcessId(this.Handle, out currentProcId);

                    if (lastN < windows.Count)
                    {
                        var i = 0;
                        for ( ; i < lastN; i++)
                        {
                            int procId;
                            User32Windows.GetWindowThreadProcessId(windows[i].Handle, out procId);
                            if (procId == currentProcId)
                            {
                                lastN++;
                                if (lastN == windows.Count)
                                {
                                    return;
                                }
                            }
                        }
                        handle = windows[i - 1].Handle;
                    }
                    else
                    {
                        return;
                    }

                    if (User32Windows.IsIconic(handle))
                    {
                        User32Windows.ShowWindow(handle, User32Windows.SW_RESTORE);
                    }
                    User32Windows.SetForegroundWindow(handle);
                }
                else
                {
                    MessageBox.Show(String.Format("Window {0} not found.", m_Commands),
                                    this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }

            User32Windows.SetForegroundWindow(m_HostWindowHwnd);

            string backup = null;

            if (this.m_SendCommandType == SendCommandType.Clipboard)
            {
                backup     = m_Commands;
                m_Commands = m_Commands == String.Empty ?
                             Clipboard.GetText() :
                             m_Commands.Replace("{clipboard}", Clipboard.GetText());
            }

            if (m_Commands == String.Empty)
            {
                return;
            }

            if (this.m_Sleep)
            {
                Thread.Sleep(m_SleepTimeout);
            }

            //
            // Working code (using SendKeys class).
            //
            var commands = m_Commands.Split(new string[] { "\r\n" }, StringSplitOptions.None);

            for (int i = 0; i < commands.Length; i++)
            {
                if (this.m_Sleep)
                {
                    Thread.Sleep(m_SleepTimeout);
                }

                SendKeys.SendWait(commands[i]);
            }

            if (this.m_SendCommandType == SendCommandType.Clipboard)
            {
                m_Commands = backup;
            }

            var lastWindow = User32Windows.GetLastActiveWindow(hwndExcept: this.Handle);

            User32Windows.SetForegroundWindow(lastWindow.Handle);

            //
            // Working code (using InputSimulator http://inputsimulator.codeplex.com/).
            //
            // var simulator = new InputSimulator();
            // simulator.Keyboard.TextEntry(m_Commands);
        }
Example #10
0
        private async void btnLoad_Click(object sender, EventArgs e)
        {
            ToggleDownloadProgress(true);

            var finishedSuccessfully = true;

            var list = txtUrl.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            var proxy    = txtProxy.Text;
            var login    = txtLogin.Text;
            var password = txtPassword.Text;

            using (WebClient wc = new WebClient())
            {
                if (chkUseProxy.Checked)
                {
                    WebProxy p = new WebProxy(proxy, true);
                    p.Credentials = new NetworkCredential(login, password);
                    WebRequest.DefaultWebProxy = p;
                    wc.Proxy = p;
                }
                else
                {
                    WebRequest.DefaultWebProxy = null;
                    wc.UseDefaultCredentials   = true;
                }

                if (txtSiteLogin.Text != String.Empty)
                {
                    wc.Credentials = new NetworkCredential(txtSiteLogin.Text, txtSitePassword.Text);
                }

                var filename = "";

                DownloadProgressChangedEventHandler progressTracker = (senderTracker, progressChangesArgs) =>
                {
                    var percent = progressChangesArgs.ProgressPercentage;

                    progressBar1.Value         = percent;
                    lblDownloadPercentage.Text = percent.ToString() + "% - " + filename;
                };

                wc.DownloadProgressChanged += progressTracker;

                foreach (var f in list)
                {
                    filename = Path.GetFileName(f);

                    try
                    {
                        await wc.DownloadFileTaskAsync(new Uri(f), Path.Combine(txtLocalPath.Text, filename));
                    }
                    catch (WebException exception)
                    {
                        txtUrl.Text += "\r\n\r\n** Error:\r\n" + exception.Message
                                       + "\r\n** Stack trace:\r\n" + exception.StackTrace
                                       + "\r\n** Response:\r\n" + exception.Response
                                       + (exception.InnerException != null ? "\r\n** Inner exception:\r\n" + exception.InnerException.ToString()
                                          + (exception.InnerException.InnerException != null ? "\r\n** Inner exception > Inner exception:\r\n" + exception.InnerException.InnerException.ToString() : "") : "")
                                       + "\r\n";

                        finishedSuccessfully = false;
                    }
                    catch (Exception exception)
                    {
                        txtUrl.Text += "\r\n\r\n** Error Other:\r\n" + exception.Message
                                       + "\r\n";

                        finishedSuccessfully = false;
                    }
                }
            }

            if (finishedSuccessfully)
            {
                if (User32Windows.IsIconic(this.Handle))
                {
                    User32Windows.ShowWindow(this.Handle, User32Windows.SW_RESTORE);
                }
                else
                {
                    User32Windows.ShowWindow(this.Handle, User32Windows.SW_SHOW);
                }
                User32Windows.SetForegroundWindow(this.Handle);

                MessageBox.Show("Successfully finished.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Finished with error(s).", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            ToggleDownloadProgress(false);
        }