Issue #19: added automatic cloning of windows requiring attention (flashing).

This commit is contained in:
Lorenz Cuno Klopfenstein 2013-11-09 14:47:56 +01:00
parent c347634c30
commit c794df3ade
6 changed files with 70 additions and 9 deletions

View file

@ -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());
}
/// <summary>
@ -37,6 +37,7 @@ namespace OnTopReplica {
Register(new WindowKeeper(), form);
Register(new HotKeyManager(), form);
Register(new GroupSwitchManager(), form);
Register(new FlashCloner(), form);
}
/// <summary>

View file

@ -0,0 +1,35 @@
using OnTopReplica.Native;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnTopReplica.MessagePumpProcessors {
/// <summary>
/// Automatically clones windows that are flashing.
/// </summary>
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() {
}
}
}

View file

@ -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);
/// <summary>
/// Registers the WM_ID for a window message.

View file

@ -130,6 +130,7 @@
<SubType>Form</SubType>
</Compile>
<Compile Include="MessagePumpManager.cs" />
<Compile Include="MessagePumpProcessors\FlashCloner.cs" />
<Compile Include="MessagePumpProcessors\GroupSwitchManager.cs" />
<Compile Include="IMessagePumpProcessor.cs" />
<Compile Include="MessagePumpProcessors\BaseMessagePumpProcessor.cs" />

View file

@ -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);

View file

@ -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() {