public bool RegisterNewInstance()
        {
            // Get guid of the executing assembly
             Assembly assembly = Assembly.GetExecutingAssembly();
             GuidAttribute guidAttribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
             string guid = guidAttribute.Value;

             // Create mutext
             this.mutex = new Mutex(false, guid);

             // Register notify message
             if (notifyInstanceMessage == 0) {
            notifyInstanceMessage = User32Interop.RegisterWindowMessage(notifyMessageName);
             }

             // Wait on the mutext, false return value means that another instance is running
             if (!this.mutex.WaitOne(0, false)) {
            if (notifyInstanceMessage != 0) {
               User32Interop.PostMessage((IntPtr)User32Interop.HWND_BROADCAST, notifyInstanceMessage, 0, 0);
            }
            return false;
             }

             // Create a window to receive notifications
             if (this.siWindow == null) {
            this.siWindow = new SIWindow(this);
             }
             return true;
        }
示例#2
0
 public HotKeyManager()
 {
     this.registredKeys = new Dictionary<Keys, int>();
      this.window = new HotKeyWindow(this);
 }