Addin的

时间:2017-10-05 10:40:46

标签: custom-controls add-in enterprise-architect hotkeys registerhotkey

我目前正在开发Enterprise Architect插件,我真的需要使用一些自定义热键来满足用户的喜好。它通过使用本文中的功能正常工作:https://community.sparxsystems.com/community-resources/805-triggering-add-in-functionality-with-custom-hotkeys-in-enterprise-architect,但是通过这种使用自定义热键的方式,Enterprise Architect不断地大量使用处理器的一个核心 - >如果我删除addin dll,并从注册表中删除密钥,这个问题就会消失,我现在确定自定义热键功能会导致它。

任何人都可以通过在企业架构师插件中提供另一种使用自定义热键的方式来帮助我吗?现在正在寻找另一种解决方案,但尚未取得任何进展。

的Tamas

编辑...找到解决办法:修改InvisibleHotKeyForm.cs和Hotkey.cs

InvisibleHotKeyForm.cs修改: 删除" worker_DoWork"方法和

public partial class InvisibleHotKeyForm : Form
{
    private const double Button_MilliSec = 10.0;
    private readonly IEnumerable<Hotkey> _hotkeys;
    private readonly int _thisProcessId;
    private int _lastActiveProcessId;
    private readonly BackgroundWorker _worker;
    private System.Timers.Timer Timer_Button;

public InvisibleHotKeyForm(IEnumerable<Hotkey> hotkeys)
{
    InitializeComponent();

    this._thisProcessId = Process.GetCurrentProcess().Id;
    this._worker = new BackgroundWorker();
    this.Timer_Init(10.0);
    this._hotkeys = hotkeys;
    this._lastActiveProcessId = this._thisProcessId;
    Closing += (sender, eventArgs) => ((List<Hotkey>)_hotkeys).ForEach(key => key.Dispose());
}

private void Timer_Init(double Millisec)
{
    this.Timer_Button = new System.Timers.Timer();
    this.Timer_Button.Elapsed += new ElapsedEventHandler(OnTimedEvent);
    this.Timer_Button.Interval = Millisec;
    this.Timer_Button.Enabled = true;
}

private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
    int id = ActiveProcess.GetActiveProcess().Id;
    if (this._lastActiveProcessId == id)
        return;
    if (this._thisProcessId == id)
    {
        this.BeginInvoke((Delegate)new MethodInvoker(RegisterHotKeys));
    }
    else if (this._thisProcessId != id)
    {
        this.BeginInvoke((Delegate)new MethodInvoker(UnregisterHotKeys));
    }
    this._lastActiveProcessId = id;
}

。 。

和Hotkey.cs修改:

public class Hotkey : IDisposable
{
    public const int WM_HOTKEY_MSG_ID = 786;
    private Keys Key { get; set; }
    private Modifiers Modifiers { get; set; }
    public HotkeyHandler Handler { get; private set; }
    private int Id { get; set; }

private IWin32Window _registeredWindow;
private bool _registered;

public Hotkey(Keys key, Modifiers modifiers, HotkeyHandler handler)
{
    this._registeredWindow = (IWin32Window)null;
    this._registered = false;
    this.Key = key;
    this.Modifiers = modifiers;
    this.Handler = handler;
    Id = GetHashCode();
}

。 。

0 个答案:

没有答案