void processLogic_OnLocationChanged(Win32Window window) { bool display = true; foreach (var item in flowPanel.Controls) { TaskbarButton button = item as TaskbarButton; if (button == null) { continue; } SecondDisplayProcess proc = button.Tag as SecondDisplayProcess; if (proc == null) { continue; } if (Native.IsFullScreen(proc.Handle, CurrentScreen.Bounds)) { display = false; break; } } if (this.Visible && !display) { this.Hide(); this.IsHidden = true; DisplayStartMenu(); } else if (!this.Visible && display) { this.Show(); this.IsHidden = false; DisplayStartMenu(); } // remote desktop window shows in primary taskbar after restoring from full screen - we need to hide it again if (!TaskbarPropertiesManager.Instance.Properties.MirrorButtons && flowPanel.ButtonExists(window)) { WindowManager.Instance.ReDeleteTab(window.Handle.ToInt32()); } }
void tsmiUnpin_Click(object sender, System.EventArgs e) { var menu = sender as ToolStripMenuItem; var strip = menu.Owner as ContextMenuStrip; TaskbarButton button = strip.SourceControl as TaskbarButton; if (button != null) { SecondDisplayProcess proc = button.Tag as SecondDisplayProcess; var pa = PinnedManager.Instance.Unpin(ProcessUtil.GetProcessByWindowHandle(proc.Handle)); flowPanel.RemovePinnedButton(pa); } else { var app = (strip.SourceControl as TaskbarPinnedButton).Tag as PinnedApp; PinnedManager.Instance.Unpin(app); flowPanel.RemovePinnedButton(app); } }
private void ShowLivePreview(TaskbarButton button, bool show) { if (!ShowPreview()) { return; } if (show) { SecondDisplayProcess proc = button.Tag as SecondDisplayProcess; AeroDecorator.Instance.LivePreview(proc.Handle, true); this.BringToFront(); this._closeForm.BringToFront(); } else { _delayedActionPreview.Cancel(); SecondDisplayProcess proc = _button.Tag as SecondDisplayProcess; AeroDecorator.Instance.LivePreview(proc.Handle, false); } }
/// <summary> /// Move window from one screen to another /// </summary> public void MoveWindowBetweenScreens(Win32Window window, Screen source, Screen target) { if (window.IsMinimized && !target.Primary) { MoveToSecondary(window); SecondDisplayProcess proc = CachedProcesses.Get(window.Handle.ToInt32()); if (proc != null) { proc.MoveToScreenOnFirstShow = target; } } else { Rectangle r = window.Bounds; int dx = r.Left - source.WorkingArea.Left; int dy = r.Top - source.WorkingArea.Top; Native.SetWindowPos(window.Handle, IntPtr.Zero, target.WorkingArea.Left + dx, target.WorkingArea.Top + dy, r.Width, r.Height, 0); } }
public void MoveWindowBetweenScreens(IntPtr hwnd, Screen source, Screen target) { if (Native.IsIconic(hwnd) && !target.Primary) { MoveProgramToSecondary(hwnd); SecondDisplayProcess proc = CachedProcesses.Get(hwnd.ToInt32()); if (proc != null) { proc.MoveToScreenOnFirstShow = target; } } else { RECT r; Native.GetWindowRect(hwnd, out r); int dx = r.left - source.WorkingArea.Left; int dy = r.top - source.WorkingArea.Top; Native.SetWindowPos(hwnd, IntPtr.Zero, target.WorkingArea.Left + dx, target.WorkingArea.Top + dy, r.right - r.left, r.bottom - r.top, 0); } }
void tsmiPin_Click(object sender, System.EventArgs e) { var menu = sender as ToolStripMenuItem; var strip = menu.Owner as ContextMenuStrip; var button = strip.SourceControl as Button; SecondDisplayProcess proc = button.Tag as SecondDisplayProcess; try { var pa = PinnedManager.Instance.Pin(ProcessUtil.GetProcessByWindowHandle(proc.Handle)); flowPanel.AddPinnedButton(pa, processMenu); } catch { try { var pa = PinnedManager.Instance.Unpin(ProcessUtil.GetProcessByWindowHandle(proc.Handle)); flowPanel.RemovePinnedButton(pa); } catch { } MessageBox.Show("There was an error trying to pin this application to the taskbar.", "Dual Monitor", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void LaunchProcess(SecondDisplayProcess proc, Screen currentScreen) { LaunchProcess(proc.Path, proc.Arguments, currentScreen); }
public void LaunchProcess(SecondDisplayProcess proc) { LaunchProcess(proc.Path); }
private void processMenu_Opening(object sender, CancelEventArgs e) { if (tooltipManager.ToolTipWindow.Visible) { tooltipManager.ToolTipWindow.ForceHide(); } ContextMenuStrip menu = sender as ContextMenuStrip; BaseTaskbarButton baseButton = menu.SourceControl as BaseTaskbarButton; baseButton.Hover = true; if (menu.SourceControl is TaskbarButton) { TaskbarButton button = menu.SourceControl as TaskbarButton; SecondDisplayProcess proc = button.Tag as SecondDisplayProcess; tsmiLaunch.Image = proc.SmallIcon.ConvertToBitmap(false); Process p = ProcessUtil.GetProcessByWindowHandle(proc.Handle); ProcessModule module = p.MainModule; if (module != null) { string fileDescription = System.Diagnostics.FileVersionInfo.GetVersionInfo(module.FileName).FileDescription; tsmiLaunch.Text = string.IsNullOrEmpty(fileDescription) ? (module.FileName ?? p.MainWindowTitle) : fileDescription.Clamp(Constants.MaxProgramNameLength); tsmiLaunch.Tag = new ProcessFullPath { FileName = module.FileName, Arguments = ProcessUtil.GetCommandLineArguments(module.ModuleName) }; tsmiLaunch.Visible = true; if (PinnedManager.Instance.IsPinned(p)) { tsmiPin.Visible = false; tsmiUnpin.Visible = true; } else { tsmiPin.Visible = true; tsmiUnpin.Visible = false; } } else { tsmiLaunch.Visible = false; tsmiPin.Visible = false; tsmiUnpin.Visible = false; } tsmiCloseWindow.Visible = true; } else { TaskbarPinnedButton pinnedButton = menu.SourceControl as TaskbarPinnedButton; PinnedApp app = pinnedButton.Tag as PinnedApp; tsmiCloseWindow.Visible = false; tsmiLaunch.Image = app.Icon.ResizeBitmap(ButtonConstants.SmallIconSize, ButtonConstants.SmallIconSize); tsmiLaunch.Text = string.IsNullOrEmpty(app.Name) ? "Unknown application" : app.Name.Clamp(Constants.MaxProgramNameLength); tsmiLaunch.Tag = new ProcessFullPath { FileName = app.Path, Arguments = app.Arguments }; tsmiLaunch.Visible = !string.IsNullOrEmpty(app.Path); if (PinnedManager.Instance.IsPinned(app)) { tsmiPin.Visible = false; tsmiUnpin.Visible = true; } else { tsmiPin.Visible = true; tsmiUnpin.Visible = false; } } }
private void panelTitle_Paint(object sender, PaintEventArgs e) { SecondDisplayProcess proc = _button.Tag as SecondDisplayProcess; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; bool showLivePreview = ShowPreview(); bool isVisualTheme = Native.IsThemeActive() != 0; if (_panelHover) { if (isVisualTheme) { GraphicsPath path = RoundedRectangle.Create(new Rectangle(0, 0, panelTitle.Width - 1, panelTitle.Height - 1), 3, RoundedRectangle.RectangleCorners.All); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.FillPath(Theme.TooltipBackground, path); e.Graphics.DrawPath(Theme.TooltipBorder, path); } else { ButtonBorderDecorator.DrawSingle(e.Graphics, 0, 0, panelTitle.Width - 1, panelTitle.Height - 1); } if (_overCloseButton) { _closeForm.Draw(DualMonitor.Properties.Resources.close_hover); } else { _closeForm.Draw(DualMonitor.Properties.Resources.close); } } if (proc == null) { return; } if (!showLivePreview) { if (proc.SmallIcon != null) { e.Graphics.DrawIcon(proc.SmallIcon, new Rectangle(ThumbnailConstants.IconMargin, 9, ThumbnailConstants.IconSize, ThumbnailConstants.IconSize)); } if (proc.Title != null) { e.Graphics.DrawString(proc.Title, this.Font, _fontColor, new RectangleF(ThumbnailConstants.LiveIconMargin + 5 + ThumbnailConstants.IconSize, 9f, panelTitle.Width - (ThumbnailConstants.IconMargin + 5 + ThumbnailConstants.IconSize) * 2, this.Font.Height), _appTitleStringFormat); } } else { if (proc.SmallIcon != null) { e.Graphics.DrawIcon(proc.SmallIcon, new Rectangle(ThumbnailConstants.LiveIconMargin, 7, ThumbnailConstants.IconSize, ThumbnailConstants.IconSize)); } if (proc.Title != null) { e.Graphics.DrawString(proc.Title, this.Font, _fontColor, new RectangleF(ThumbnailConstants.LiveIconMargin + 5 + ThumbnailConstants.IconSize, 9f, panelTitle.Width - (ThumbnailConstants.LiveIconMargin + 5 + ThumbnailConstants.IconSize) * 2, this.Font.Height), _appTitleStringFormat); } } }
public void Show(TaskbarButton button) { CancelHide(); PanelHover = true; if (button == _button) { return; } SecondDisplayProcess proc = button.Tag as SecondDisplayProcess; _button = button; if (_thumbnail != null) { _thumbnail.Dispose(); _thumbnail = null; } CalculateBounds(proc); this.StartPosition = FormStartPosition.Manual; Rectangle parentBounds = button.Parent.RectangleToScreen(button.Bounds); Screen buttonScreen = proc.Screen; var taskbarLocation = TaskbarPropertiesManager.Instance.Properties.GetTaskbarLocation(buttonScreen.DeviceName); if (taskbarLocation == Native.ABEdge.Top || taskbarLocation == Native.ABEdge.Bottom) { int x = (parentBounds.Left + parentBounds.Width / 2) - this.Width / 2; if (x < buttonScreen.WorkingArea.Left) { x = buttonScreen.WorkingArea.Left; } if (x + this.Width > buttonScreen.WorkingArea.Right) { x = buttonScreen.WorkingArea.Right - this.Width; } int y = taskbarLocation == Native.ABEdge.Bottom ? (parentBounds.Top - this.Height) : parentBounds.Bottom; this.Location = new Point(x, y); } else { int x = taskbarLocation == Native.ABEdge.Left ? parentBounds.Right : (parentBounds.Left - this.Width); int y = (parentBounds.Top + parentBounds.Height / 2) - this.Height / 2; if (y < buttonScreen.WorkingArea.Top) { y = buttonScreen.WorkingArea.Top; } if (y + this.Height > buttonScreen.WorkingArea.Bottom) { y = buttonScreen.WorkingArea.Bottom - this.Height; } this.Location = new Point(x, y); } _buttonRectangle = new Rectangle(panelTitle.Width - ThumbnailConstants.IconMargin - ThumbnailConstants.CloseButWidth, 10, ThumbnailConstants.CloseButWidth, ThumbnailConstants.CloseButWidth); if (this.Visible) { this.Refresh(); } else { this.Visible = true; } _closeForm.Show(); Point location = panelTitle.PointToScreen(new Point(panelTitle.Width - ThumbnailConstants.IconMargin - ThumbnailConstants.CloseButWidth, 10)); _closeForm.Left = location.X; _closeForm.Top = location.Y; _closeForm.Draw(DualMonitor.Properties.Resources.close); ShowDefaultTooltip(); }
/// <summary> /// Add a new button to the taskbar /// </summary> /// <param name="process">Window wrapper</param> /// <param name="tooltipManager">Reference to the tooltip manager</param> /// <param name="processMenu">Button's context menu</param> public void AddButton(SecondDisplayProcess process, ToolTipManager tooltipManager, ContextMenuStrip processMenu) { // multiple windows messages call this method, in the same thread. // so we need to ignore same message when repeated if (_lastAddButtonHandle == process.Handle) { return; } _lastAddButtonHandle = process.Handle; TaskbarButton button = _taskbarButtons.Find(tb => { var sdp = (tb.Tag as SecondDisplayProcess); return(sdp.Handle == process.Handle); }); if (button != null) { _lastAddButtonHandle = IntPtr.Zero; return; } // can't use locks since the thread is the same //if (_syncEvent.WaitOne(500)) { button = _taskbarButtons.Find(tb => { var sdp = (tb.Tag as SecondDisplayProcess); return(sdp.Handle == process.Handle); }); if (button != null) { _lastAddButtonHandle = IntPtr.Zero; //_syncEvent.Release(); return; } button = new TaskbarButton(tooltipManager); button.Tag = process; _taskbarButtons.Add(button); //_syncEvent.Release(); } /* * else * { * _lastAddButtonHandle = IntPtr.Zero; * return; * } */ _lastAddButtonHandle = IntPtr.Zero; this.SuspendLayout(); try { this.Controls.Add(button); } catch (Win32Exception e) { var p = System.Diagnostics.Process.GetCurrentProcess(); if (MessageBox.Show(string.Format("Err: {1}{0}Thread Count: {2}{0}Handle Count: {3}", Environment.NewLine, e.Message, p.Threads.Count, p.HandleCount), "Error", MessageBoxButtons.YesNo) == DialogResult.Yes) { Debugger.Break(); } _taskbarButtons.Remove(button); this.ResumeLayout(); return; } button.AutoSize = false; button.Text = process.Title; if (process.Icon != null) { button.Image = (IsBig ? process.Icon : process.SmallIcon).ConvertToBitmap(IsBig); } button.Padding = new System.Windows.Forms.Padding(0); button.Margin = new System.Windows.Forms.Padding(0); button.ShowLabel = TaskbarPropertiesManager.Instance.Properties.ShowLabels; button.SetDefaultHeight(); button.ContextMenuStrip = processMenu; _groups.AddToGroup(process.Path, button); ArrangeButtons(); this.ResumeLayout(); button.Refresh(); }