From c794df3aded42426561227d8735f971b398fb45b Mon Sep 17 00:00:00 2001 From: Lorenz Cuno Klopfenstein Date: Sat, 9 Nov 2013 14:47:56 +0100 Subject: [PATCH] Issue #19: added automatic cloning of windows requiring attention (flashing). --- OnTopReplica/MessagePumpManager.cs | 3 +- .../MessagePumpProcessors/FlashCloner.cs | 35 +++++++++++++++++++ OnTopReplica/Native/HookMethods.cs | 9 +++-- OnTopReplica/OnTopReplica.csproj | 1 + OnTopReplica/ThumbnailPanel.cs | 4 +-- OnTopReplica/WindowHandle.cs | 27 ++++++++++++-- 6 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 OnTopReplica/MessagePumpProcessors/FlashCloner.cs diff --git a/OnTopReplica/MessagePumpManager.cs b/OnTopReplica/MessagePumpManager.cs index 6d91797..af897af 100644 --- a/OnTopReplica/MessagePumpManager.cs +++ b/OnTopReplica/MessagePumpManager.cs @@ -15,7 +15,7 @@ namespace OnTopReplica { _processors[processor.GetType()] = processor; processor.Initialize(form); - Log.Write("Registered message pump processor: {0}", processor.GetType()); + Log.Write("Registered message pump processor {0}", processor.GetType()); } /// @@ -37,6 +37,7 @@ namespace OnTopReplica { Register(new WindowKeeper(), form); Register(new HotKeyManager(), form); Register(new GroupSwitchManager(), form); + Register(new FlashCloner(), form); } /// diff --git a/OnTopReplica/MessagePumpProcessors/FlashCloner.cs b/OnTopReplica/MessagePumpProcessors/FlashCloner.cs new file mode 100644 index 0000000..d72df47 --- /dev/null +++ b/OnTopReplica/MessagePumpProcessors/FlashCloner.cs @@ -0,0 +1,35 @@ +using OnTopReplica.Native; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OnTopReplica.MessagePumpProcessors { + + /// + /// Automatically clones windows that are flashing. + /// + class FlashCloner : BaseMessagePumpProcessor { + + public override bool Process(ref System.Windows.Forms.Message msg) { + if (true && + msg.Msg == HookMethods.WM_SHELLHOOKMESSAGE) { + int hookCode = msg.WParam.ToInt32(); + + if (hookCode == HookMethods.HSHELL_FLASH) { + IntPtr flashHandle = msg.LParam; + + Form.SetThumbnail(new WindowHandle(flashHandle), null); + } + } + + return false; + } + + protected override void Shutdown() { + + } + + } + +} diff --git a/OnTopReplica/Native/HookMethods.cs b/OnTopReplica/Native/HookMethods.cs index 273bb7f..e90f864 100644 --- a/OnTopReplica/Native/HookMethods.cs +++ b/OnTopReplica/Native/HookMethods.cs @@ -22,11 +22,14 @@ namespace OnTopReplica.Native { private set; } - public const int HSHELL_WINDOWACTIVATED = 4; - public const int HSHELL_RUDEAPPACTIVATED = HSHELL_WINDOWACTIVATED | HSHELL_HIGHBIT; const int HSHELL_HIGHBIT = 0x8000; - public const int HSHELL_WINDOWDESTROYED = 2; + public const int HSHELL_WINDOWCREATED = 1; + public const int HSHELL_WINDOWDESTROYED = 2; + public const int HSHELL_WINDOWACTIVATED = 4; + public const int HSHELL_REDRAW = 6; + public const int HSHELL_RUDEAPPACTIVATED = (HSHELL_WINDOWACTIVATED | HSHELL_HIGHBIT); + public const int HSHELL_FLASH = (HSHELL_REDRAW | HSHELL_HIGHBIT); /// /// Registers the WM_ID for a window message. diff --git a/OnTopReplica/OnTopReplica.csproj b/OnTopReplica/OnTopReplica.csproj index 16aad2e..6205031 100644 --- a/OnTopReplica/OnTopReplica.csproj +++ b/OnTopReplica/OnTopReplica.csproj @@ -130,6 +130,7 @@ Form + diff --git a/OnTopReplica/ThumbnailPanel.cs b/OnTopReplica/ThumbnailPanel.cs index f6135f3..0121304 100644 --- a/OnTopReplica/ThumbnailPanel.cs +++ b/OnTopReplica/ThumbnailPanel.cs @@ -203,14 +203,14 @@ namespace OnTopReplica { _thumbnail = null; } - //Get form and register thumbnail on it + //Attempt to get top level Form from Control Form owner = this.TopLevelControl as Form; if (owner == null) throw new Exception("Internal error: ThumbnailPanel.TopLevelControl is not a Form."); _labelGlass.Visible = false; - //Register new thumbnail, disable regioning directly and refresh + //Register new thumbnail, update regioning directly and refresh thumbnail _thumbnail = DwmManager.Register(owner, handle.Handle); _currentRegion = region; _regionEnabled = (region != null); diff --git a/OnTopReplica/WindowHandle.cs b/OnTopReplica/WindowHandle.cs index e2d4851..d2b2cc6 100644 --- a/OnTopReplica/WindowHandle.cs +++ b/OnTopReplica/WindowHandle.cs @@ -95,11 +95,33 @@ namespace OnTopReplica { #region Object override public override string ToString() { + var sb = new StringBuilder(); + sb.AppendFormat("#{0}", _handle); + + if (!string.IsNullOrWhiteSpace(_title) || !string.IsNullOrWhiteSpace(_class)) { + sb.Append(" ("); + if (!string.IsNullOrWhiteSpace(_title)) { + sb.AppendFormat("title '{0}'", _title); + if (!string.IsNullOrWhiteSpace(_class)) { + sb.Append(", "); + } + } + if (!string.IsNullOrWhiteSpace(_class)) { + sb.AppendFormat("class {0}", _class); + } + sb.Append(")"); + } + + return sb.ToString(); + if (string.IsNullOrWhiteSpace(_title)) { return string.Format("#{0}", _handle.ToInt64()); } - else { + else if (string.IsNullOrWhiteSpace(_class)) { return string.Format("#{0} ({1})", _handle.ToInt64(), _title); + } + else { + return string.Format("#{0} ({1}, class {2})", _handle.ToInt64(), _title, _class); } } @@ -108,11 +130,10 @@ namespace OnTopReplica { return true; System.Windows.Forms.IWin32Window win = obj as System.Windows.Forms.IWin32Window; - if (win == null) return false; - return (win.Handle == _handle); + return (_handle.Equals(win.Handle)); } public override int GetHashCode() {