private void SetFirstMenuItem(ToolStripItemCollection passMenu) { if (m_Passwords.Count == 0) { return; } var lastWindow = User32Windows.GetLastActiveWindow(hwndExcept: this.Handle, exceptNames: m_ExceptPasswordWindows); var maxMenuLength = 40; var title = lastWindow.Title.Length >= maxMenuLength ? lastWindow.Title.Substring(0, maxMenuLength - 3) + "..." : lastWindow.Title; if (passMenu.Count == 0) { passMenu.Add(title); } else { ((ToolStripMenuItem)passMenu[0]).Text = title; } if (lastWindow.Icon != null) { ((ToolStripMenuItem)passMenu[0]).Image = lastWindow.Icon.ToBitmap(); } ((ToolStripMenuItem)passMenu[0]).ForeColor = Color.FromArgb(112, 112, 112); }
private void txtHwnd_Leave(object sender, EventArgs e) { if (m_TrackingIsRunning) { return; } var hwnd = (IntPtr)int.Parse(txtHwnd.Text); if (User32Windows.IsWindow(hwnd)) { Hwnd = hwnd; btnStartStop.Enabled = true; btnStartStop.Text = "Start"; chkTrackModalWindow.Enabled = true; m_TrackingIsValid = true; } else { Hwnd = IntPtr.Zero; btnStartStop.Enabled = false; } DisplayTitle(); }
public SendCommandsForm(IntPtr hwnd) : this() { m_HostedWindowHwnd = hwnd; txtTitle.Text = User32Windows.GetWindowText(m_HostedWindowHwnd, 255); }
private void GetCharacteristics() { User32Windows.GetWindowRect(m_Hwnd, out m_WindowRect); txtCurrentLeft.Text = m_WindowRect.Left.ToString(); txtCurrentTop.Text = m_WindowRect.Top.ToString(); txtCurrentWidth.Text = (m_WindowRect.Width - m_WindowRect.Left).ToString(); txtCurrentHeight.Text = (m_WindowRect.Height - m_WindowRect.Top).ToString(); }
private void ActivatePreviousWindow(IntPtr hwnd = default(IntPtr)) { if (hwnd == IntPtr.Zero) { hwnd = User32Windows.GetLastActiveWindow(hwndExcept: this.Handle, exceptNames: m_ExceptPasswordWindows).Handle; } User32Windows.SetForegroundWindow(hwnd); }
private void RefreshWindowsLists(List <DesktopWindow> runningWindows) { List <IntPtr> hwnds = null; List <IntPtr> hwndsParam = null; if (!m_RefreshFull) { hwnds = (from w in m_RunningWindows select w.Handle).ToList(); hwndsParam = (from w in runningWindows select w.Handle).ToList(); } foreach (var window in runningWindows) { if (m_RefreshFull) { if (m_RunningWindows.Contains(window)) { continue; } } else { var index = hwnds.IndexOf(window.Handle); if (index >= 0) { m_RunningWindows[index].Title = User32Windows.GetWindowText(window.Handle, 255); continue; } } m_RunningWindows.Add(window); } for (int i = 0; i < m_RunningWindows.Count; i++) { var window = m_RunningWindows[i]; if (m_RefreshFull) { if (!runningWindows.Contains(window)) { m_RunningWindows.RemoveAt(i); i--; } } else { if (!hwndsParam.Contains(window.Handle)) { m_RunningWindows.RemoveAt(i); i--; } } } }
private void ShowCalendar(bool topmost = false) { CalendarForm calendar = new CalendarForm(); calendar.SetLocationAndSize(this); calendar.TopMost = topmost; calendar.Show(); User32Windows.ShowWindow(this.Handle, User32Windows.SW_RESTORE); }
private void DisplayTitle() { if (Hwnd != IntPtr.Zero) { lblTitle.Text = User32Windows.GetWindowText(Hwnd, 255); } else { lblTitle.Text = "-"; } }
private void SetLocation() { DataTable dt = new DataTable(); int left = txtNewLeft.Text != "" ? (int)dt.Compute(txtNewLeft.Text, "") : m_WindowRect.Left; int top = txtNewTop.Text != "" ? (int)dt.Compute(txtNewTop.Text, "") : m_WindowRect.Top; int width = txtNewWidth.Text != "" ? (int)dt.Compute(txtNewWidth.Text, "") : m_WindowRect.Width - m_WindowRect.Left; int height = txtNewHeight.Text != "" ? (int)dt.Compute(txtNewHeight.Text, "") : m_WindowRect.Height - m_WindowRect.Top; User32Windows.SetWindowPos(m_Hwnd, User32Windows.HWND_TOP, left, top, width, height, User32Windows.SWP_NOZORDER); GetCharacteristics(); }
private void GetWindowInfo() { m_HostedWindowHwnd = (IntPtr)int.Parse(txtHwnd.Text); StringBuilder title = new StringBuilder(255); if (User32Windows.IsWindow(m_HostedWindowHwnd)) { User32Windows.GetWindowText(m_HostedWindowHwnd, title, title.Capacity + 1); } txtTitle.Text = title.ToString(); }
private void MainForm_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { if (!m_Minimize) { User32Windows.ShowWindow(this.Handle, User32Windows.SW_RESTORE); } else { m_Minimize = false; } } }
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); }
private void InitializeAdditionalComponents() { // The panel for moving the form by any point. this.panel1 = new TransparentDraggablePanel(this) { Name = "panel1", Location = new System.Drawing.Point(0, 0), Size = this.Size, TabIndex = 1, Locked = m_Locked }; var title = User32Windows.GetWindowText(m_Handle, 255); this.Text = "Transparent - " + title; var icon = User32Windows.GetIcon(m_Handle); if (icon != null) { this.pictureBox1.Image = icon.ToBitmap(); } this.Controls.Add(this.panel1); panel1.BringToFront(); if (IsWindows10()) { this.panel1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.TransparentWindowToolForm_MouseWheel); } else { this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.TransparentWindowToolForm_MouseWheel); } this.panel1.DoubleClick += new System.EventHandler(this.TransparentWindowToolForm_DoubleClick); this.panel1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.TransparentWindowToolForm_MouseClick); this.LocationChanged += (sender, e) => { m_ClicksCount = ClicksToShow - 2; }; }
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); }
private string GetPin(string pinCaption, string pinPrompt) { m_PinForm = (PinForm)User32Windows.GetForm(m_PinForm, typeof(PinForm)); m_PinForm.StartPosition = FormStartPosition.Manual; if (this.Visible) { m_PinForm.DesktopLocation = this.DesktopLocation; } m_PinForm.Text = pinCaption; m_PinForm.Prompt = pinPrompt; m_PinForm.Pin = ""; DialogResult result = m_PinForm.ShowDialog(); if (result != DialogResult.OK) { return(""); } return(m_PinForm.Pin); }
public TrackWindowTitleForm(IntPtr?hwnd = null, Func <string> info = null, Size?size = null, ContentAlignment alignment = ContentAlignment.MiddleLeft, int refreshInterval = 1000) { InitializeComponent(); m_Properties.BackColor = this.BackColor; m_Properties.ForeColor = this.ForeColor; m_Properties.BorderColor = Color.FromArgb(128, 255, 128); m_Properties.Font = this.label1.Font; m_Properties.Height = this.Height; m_Properties.Width = this.Width; m_Properties.BorderWidth = 1; m_Properties.Interval = 1; m_Hwnd = hwnd ?? IntPtr.Zero; if (hwnd != null) { info = () => User32Windows.GetWindowText(m_Hwnd, 255); } if (info != null) { this.m_Info = info; } m_FormSize = size ?? Size.Empty; if (size != null) { m_Properties.Width = m_FormSize.Width; m_Properties.Height = m_FormSize.Height; } m_InfoTextAlign = alignment; m_RefreshInterval = refreshInterval; InitializeAdditionalComponents(); }
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; } } }
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 StartTracking() { if (Hwnd == IntPtr.Zero || !User32Windows.IsWindow(Hwnd)) { MessageBox.Show("No window is selected.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } m_StartTime = DateTime.Now; m_WindowIsHung = IsHungAppWindow(m_Hwnd) || m_TrackModalWindow; var msg = "• Start tracking" + " [" + Hwnd.ToString() + "] \"" + User32Windows.GetWindowText(Hwnd, 255) + "\"" + "\r\n" + FormatTime(m_StartTime) + " the program is " + (m_WindowIsHung ? "hung" : "accessible") + "."; Log(msg); WindowColors(); chkTrackModalWindow.Enabled = false; timer1.Start(); }
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; }
public SendCommandToolForm(IntPtr hwnd, string commands) { InitializeComponent(); var refreshIntervalStr = ConfigurationManager.AppSettings.Get("CommandToolRefreshInterval"); this.timer1.Interval = int.Parse(refreshIntervalStr); m_HostWindowHwnd = hwnd; m_Commands = commands; StringBuilder title = new StringBuilder(255); try { User32Windows.GetWindowText(m_HostWindowHwnd, title, title.Capacity + 1); m_HostWindowTitle = title.ToString(); } catch { } Text = "Send Command - " + title.ToString(); toolTip1.SetToolTip(this, Text); }
private void CalculateCoordinates() { Rectangle rHost; User32Windows.GetWindowRect(m_HostWindowHwnd, out rHost); if (m_AnchorH == AnchorHorizontal.Left) { m_HostWindowOffsetX = this.Location.X - rHost.Left; } else { m_HostWindowOffsetX = this.Location.X - rHost.Width; } if (m_AnchorV == AnchorVertical.Top) { m_HostWindowOffsetY = this.Location.Y - rHost.Top; } else { m_HostWindowOffsetY = this.Location.Y - rHost.Height; } }
private void TransparentWindowToolForm_DoubleClick(object sender, EventArgs e) { User32Windows.ShowWindow(m_Handle, User32Windows.SW_HIDE); m_ClicksCount = 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); }
private void ProcessTracking() { if (!User32Windows.IsWindow(Hwnd)) { timer1.Stop(); m_TrackingIsRunning = false; btnStartStop.Text = "Start"; } string message = String.Empty; var now = DateTime.Now; var wasRunnind = now - m_StartTime; var running = FormatTime(wasRunnind); var runningClock = FormatTime(wasRunnind, false); if (!m_TrackingIsRunning) { message = FormatTime(now) + " the " + (m_TrackModalWindow ? "modal window" : "program") + " is closed now and was in the previous state: " + running + "."; m_WindowIsHung = false; this.m_TrackingIsValid = false; this.btnStartStop.Text = "Close"; lblLabelPlusClock.Text = "Hwnd:"; } else { lblLabelPlusClock.Text = runningClock; if (m_TrackModalWindow) { return; } else if (IsHungAppWindow(Hwnd) && !m_WindowIsHung) { m_WindowIsHung = true; // The Windows OS detects hung window after 5 seconds. var fiveSeconds = new TimeSpan(0, 0, 5); m_StartTime = now - fiveSeconds; wasRunnind -= fiveSeconds; message = FormatTime(now) + " the program is hung now and was in the previous state: " + running + "."; } else if (!IsHungAppWindow(Hwnd) && m_WindowIsHung) { m_WindowIsHung = false; m_StartTime = now; message = FormatTime(now) + " the program is accessible now and was in the previous state: " + FormatTime(wasRunnind) + "."; } } if (message != String.Empty) { Log(message); WindowColors(); if (!m_TrackingIsRunning) { Log("Please close this window."); } } }
private void CheckToolDisplaying() { if (!m_IsRunning) { return; } IntPtr foreWindow = User32Windows.GetForegroundWindow(); var title = User32Windows.GetWindowText(foreWindow, 255); bool matchesTitlePattern = false; if (((foreWindow == m_HostWindowHwnd || foreWindow == this.Handle) && !User32Windows.IsIconic(m_HostWindowHwnd)) || (title == m_HostWindowTitle && m_RunOnAllWindowsWithSameTitle) || (m_TitlePattern != String.Empty && (matchesTitlePattern = m_TitleRegex.IsMatch(title)))) { // if ((foreWindow != m_HostWindowHwnd) && (foreWindow != this.Handle)) // { // int pidFore, pidThis; // User32Windows.GetWindowThreadProcessId(foreWindow, out pidFore); // User32Windows.GetWindowThreadProcessId(this.Handle, out pidThis); // if (pidFore == pidThis) // { // return; // } // // m_HostWindowHwnd = foreWindow; // m_HostWindowTitle = title; // if (!matchesTitlePattern) // { // CalculateCoordinates(); // } // } Rectangle rHost; User32Windows.GetWindowRect(m_HostWindowHwnd, out rHost); int newX = 0, newY = 0; if (m_AnchorH == AnchorHorizontal.Left) { newX = rHost.Left + m_HostWindowOffsetX; } else { newX = rHost.Width + m_HostWindowOffsetX; } if (m_AnchorV == AnchorVertical.Top) { newY = rHost.Top + m_HostWindowOffsetY; } else { newY = rHost.Height + m_HostWindowOffsetY; } if ((this.Location.X != newX) || (this.Location.Y != newY)) { this.Location = new Point(newX, newY); } if (!this.Visible) { Task.Delay(timer1.Interval).ContinueWith(t => this.Show()); } } else if ((!m_RunOnAllWindowsWithSameTitle) && (!User32Windows.IsWindow(m_HostWindowHwnd))) { if (this.Exit != null) { this.Exit.Invoke(this, new ToolEventArgs() { Title = m_HostWindowTitle }); } this.Close(); } else if (User32Windows.IsIconic(m_HostWindowHwnd)) { this.Hide(); } else { Rectangle rForeWindow; User32Windows.GetWindowRect(foreWindow, out rForeWindow); var r = this.RectangleToScreen(this.DisplayRectangle); var contains = RectangleContains(rForeWindow, r) || RectangleIntersects(rForeWindow, r); int processId, ptocessIdThis; User32Windows.GetWindowThreadProcessId(foreWindow, out processId); User32Windows.GetWindowThreadProcessId(this.Handle, out ptocessIdThis); if (this.Visible && m_AutoHide && contains && (processId != ptocessIdThis)) { this.Hide(); } } }
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); }
private void propertiesToolStripMenuItem_Click(object sender, EventArgs e) { var settingsForm = new SendCommandToolPropertiesForm() { HostHwnd = this.m_HostWindowHwnd, ToolWidht = this.Size.Width, ToolHeight = this.Size.Height, AnchorH = m_AnchorH, AnchorV = m_AnchorV, Commands = m_Commands, CommandType = m_SendCommandType, Sleep = m_Sleep, SleepTimeout = m_SleepTimeout, RunOnAllWindowsWithSameTitle = m_RunOnAllWindowsWithSameTitle, ToolLeft = this.Location.X, ToolTop = this.Location.Y, BorderColor = this.m_PenNormal.Color, BorderHoverColor = this.m_PenHover.Color, TitlePattern = this.m_TitlePattern, ActivateOnHover = this.ActivateOnHover }; var result = settingsForm.ShowDialog(); if (result == DialogResult.OK) { this.m_HostWindowHwnd = settingsForm.HostHwnd; this.Size = new Size(settingsForm.ToolWidht, settingsForm.ToolHeight); this.m_AnchorH = settingsForm.AnchorH; this.m_AnchorV = settingsForm.AnchorV; this.m_DrawRectangle = new Rectangle(0, 0, this.Size.Width - 1, this.Size.Height - 1); this.m_Commands = settingsForm.Commands; this.m_SendCommandType = settingsForm.CommandType; if (this.m_SendCommandType == SendCommandType.ActivateWindow) { int handle; if (int.TryParse(m_Commands, out handle)) { if (User32Windows.IsWindow((IntPtr)handle)) { if (this.BackgroundImagePath != string.Empty) { var q = MessageBox.Show("The tool already has an background icon,\novervrite?", "Background icon", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (q == DialogResult.No) { return; } } var icon = User32Windows.GetIcon((IntPtr)handle); if (icon != null) { this.BackgroundImage = icon.ToBitmap(); } } } } this.m_Sleep = settingsForm.Sleep; this.m_SleepTimeout = settingsForm.SleepTimeout; this.m_RunOnAllWindowsWithSameTitle = settingsForm.RunOnAllWindowsWithSameTitle; this.m_TitlePattern = settingsForm.TitlePattern; this.Location = new Point(settingsForm.ToolLeft, settingsForm.ToolTop); this.m_PenNormal.Color = settingsForm.BorderColor; this.m_PenHover.Color = settingsForm.BorderHoverColor; if (m_TitlePattern != String.Empty) { m_TitleRegex = new Regex(m_TitlePattern); } else { m_TitleRegex = null; } this.ActivateOnHover = settingsForm.ActivateOnHover; } }