mirror of
https://github.com/LorenzCK/OnTopReplica.git
synced 2024-06-03 11:04:32 +12:00
Refactore MessagePumpManager to improve performance (no more reflection on startup).
This commit is contained in:
parent
dcc218366f
commit
7128038eb0
|
@ -4,6 +4,7 @@ using System.Text;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using OnTopReplica.Native;
|
using OnTopReplica.Native;
|
||||||
|
using OnTopReplica.MessagePumpProcessors;
|
||||||
|
|
||||||
namespace OnTopReplica {
|
namespace OnTopReplica {
|
||||||
class MessagePumpManager : IDisposable {
|
class MessagePumpManager : IDisposable {
|
||||||
|
@ -12,6 +13,15 @@ namespace OnTopReplica {
|
||||||
|
|
||||||
public MainForm Form { get; private set; }
|
public MainForm Form { get; private set; }
|
||||||
|
|
||||||
|
private void Register(IMessagePumpProcessor processor, MainForm form) {
|
||||||
|
_processors[processor.GetType()] = processor;
|
||||||
|
processor.Initialize(form);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine("Registered message pump processor: {0}", processor.GetType());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instantiates all message pump processors and registers them on the main form.
|
/// Instantiates all message pump processors and registers them on the main form.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -29,18 +39,10 @@ namespace OnTopReplica {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var t in Assembly.GetExecutingAssembly().GetTypes()) {
|
//Register message pump processors
|
||||||
if (typeof(IMessagePumpProcessor).IsAssignableFrom(t) && !t.IsAbstract) {
|
Register(new WindowKeeper(), form);
|
||||||
var instance = (IMessagePumpProcessor)Activator.CreateInstance(t);
|
Register(new HotKeyManager(), form);
|
||||||
instance.Initialize(form);
|
Register(new GroupSwitchManager(), form);
|
||||||
|
|
||||||
_processors[t] = instance;
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
Console.WriteLine("Registered message pump processor: {0}", t);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using OnTopReplica.Native;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace OnTopReplica.MessagePumpProcessors {
|
|
||||||
class TitleSetter : BaseMessagePumpProcessor {
|
|
||||||
|
|
||||||
const string Title = "OnTopReplica";
|
|
||||||
|
|
||||||
public override bool Process(ref Message msg) {
|
|
||||||
switch (msg.Msg) {
|
|
||||||
case WM.GETTEXT: {
|
|
||||||
Console.WriteLine("GetText");
|
|
||||||
int maxLen = msg.WParam.ToInt32();
|
|
||||||
byte[] strBytes = Encoding.UTF8.GetBytes(Title);
|
|
||||||
byte[] termBytes = new byte[strBytes.Length + 1];
|
|
||||||
strBytes.CopyTo(termBytes, 0);
|
|
||||||
termBytes[strBytes.Length] = 0;
|
|
||||||
|
|
||||||
Marshal.Copy(termBytes, 0, msg.LParam, Math.Min(maxLen, Title.Length + 1));
|
|
||||||
}
|
|
||||||
goto case WM.GETTEXTLENGTH;
|
|
||||||
|
|
||||||
case WM.GETTEXTLENGTH:
|
|
||||||
Console.WriteLine("GetTextLength");
|
|
||||||
msg.Result = (IntPtr)Title.Length;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Shutdown() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -124,7 +124,6 @@
|
||||||
<Compile Include="MessagePumpProcessors\GroupSwitchManager.cs" />
|
<Compile Include="MessagePumpProcessors\GroupSwitchManager.cs" />
|
||||||
<Compile Include="IMessagePumpProcessor.cs" />
|
<Compile Include="IMessagePumpProcessor.cs" />
|
||||||
<Compile Include="MessagePumpProcessors\BaseMessagePumpProcessor.cs" />
|
<Compile Include="MessagePumpProcessors\BaseMessagePumpProcessor.cs" />
|
||||||
<None Include="MessagePumpProcessors\TitleSetter.cs" />
|
|
||||||
<Compile Include="MessagePumpProcessors\WindowKeeper.cs" />
|
<Compile Include="MessagePumpProcessors\WindowKeeper.cs" />
|
||||||
<Compile Include="Native\ErrorMethods.cs" />
|
<Compile Include="Native\ErrorMethods.cs" />
|
||||||
<Compile Include="Native\HookMethods.cs" />
|
<Compile Include="Native\HookMethods.cs" />
|
||||||
|
@ -149,6 +148,7 @@
|
||||||
<Compile Include="SidePanels\GroupSwitchPanel.Designer.cs">
|
<Compile Include="SidePanels\GroupSwitchPanel.Designer.cs">
|
||||||
<DependentUpon>GroupSwitchPanel.cs</DependentUpon>
|
<DependentUpon>GroupSwitchPanel.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="StartupOptions\Options.cs" />
|
||||||
<Compile Include="StoredRegionComparer.cs" />
|
<Compile Include="StoredRegionComparer.cs" />
|
||||||
<Compile Include="Native\WindowsSevenMethods.cs" />
|
<Compile Include="Native\WindowsSevenMethods.cs" />
|
||||||
<None Include="Native\CommonControls.cs" />
|
<None Include="Native\CommonControls.cs" />
|
||||||
|
|
Loading…
Reference in a new issue