/// <summary> /// 检查待注册的热键是否冲突,若不冲突则注册,否则返回false /// </summary> /// <param name="HKVI">HotKeyVisualItem</param> /// <param name="id"></param> /// <returns></returns> public static bool CheckAndRegisterHotKey(HotKeyVisualItem HKVI, object iParent, int id = -65536) { //定义用于标识状态的标识符 bool StatusAvailable = true; //检查热键对象的可用状态 if (HKVI.Available) { //未指定ID则按照当前所有已注册的热键ID顺延一位 if (id == -65536) { id = ++HotKey.CurrentID; } //转换对象格式,之后可以加个构造重载 HotKeyItem hki = new HotKeyItem(iParent, HKVI.KeyValue, HKVI.ModifiersValue, id, HotKeyItem.HotKeyParentType.Item); //查找ID冲突 foreach (HotKeyItem h in listOfApplicationHotKey) { if (hki.ID == h.ID) { //如果冲突则更改标识符 StatusAvailable = false; break; } } if (StatusAvailable) { //添加到热键集合 listOfApplicationHotKey.Add(hki); //注册热键 HotKey.RegisterHotKey(new System.Windows.Interop.WindowInteropHelper(WindowMain).Handle, hki.ID, hki.ModifiersValue, (uint)hki.KeyValue); return(true); } else { return(false); } } else { return(false); } }
/// <summary> /// 检查待注册的热键是否冲突,若不冲突则注册,否则返回false /// </summary> /// <param name="HKVI">HotKeyVisualItem</param> /// <param name="id"></param> /// <returns></returns> public static bool CheckAndRegisterHotKey(HotKeyVisualItem HKVI, object iParent, int id = -65536) { bool StatusAvailable = true; if (HKVI.Available) { if (id == -65536) { id = ++HotKey.CurrentID; } HotKeyItem hki = new HotKeyItem(iParent, HKVI.KeyValue, HKVI.ModifiersValue, id, HotKeyItem.HotKeyParentType.Item); foreach (HotKeyItem h in listOfApplicationHotKey) { if (hki.ID == h.ID) { StatusAvailable = false; break; } } if (StatusAvailable) { listOfApplicationHotKey.Add(hki); HotKey.RegisterHotKey(new System.Windows.Interop.WindowInteropHelper(WindowMain).Handle, hki.ID, hki.ModifiersValue, (uint)hki.KeyValue); return(true); } else { return(false); } } else { return(false); } }
public static void GetPlugins() { if (Directory.Exists(Manage.PluginsPath)) { //获取所有文件 string[] listFiles = Directory.GetFiles(Manage.PluginsPath); //遍历 foreach (string s in listFiles) { //找到类库 if (s.ToUpper().EndsWith(".DLL")) { //加载 Assembly asm = Assembly.LoadFrom(s); if (asm != null) { //获取类型名集合 Type[] types = asm.GetTypes(); foreach (Type t in types) { //找到类型名内含有入口方法的类型 if (t.GetMethod("AnythingPluginMain") != null) { //创建对象 object obj = asm.CreateInstance(t.FullName); //添加到集合 plugins.Add(obj); //创建对应的菜单项 MenuItem menuitem = new MenuItem(); //写菜单项名称 menuitem.Header = t.GetProperty("MdlName").GetValue(obj, null).ToString(); //检查是否要接管内部操作 if (t.GetProperty("ManageOperation").GetValue(obj, null).ToString() != "") { //接管网络浏览器 if (t.GetProperty("ManageOperation").GetValue(obj, null).ToString() == "Web") { Manage.MOWeb.IsUsed = true; Manage.MOWeb.MdlName = t.GetProperty("MdlName").GetValue(obj, null).ToString(); } //接管文件夹浏览 else if (t.GetProperty("ManageOperation").GetValue(obj, null).ToString() == "Folder") { Manage.MOFolder.IsUsed = true; Manage.MOFolder.MdlName = t.GetProperty("MdlName").GetValue(obj, null).ToString(); } } //检查插件是否申请了快捷键 if ((bool)t.GetProperty("ApplyForHotKey").GetValue(obj, null)) { string KeyGot = t.GetProperty("HotKey").GetValue(obj, null).ToString(); if (!string.IsNullOrEmpty(KeyGot)) { HotKeyVisualItem HKVI = new HotKeyVisualItem(); HKVI.HotKeysString = KeyGot; if (HKVI.Available) { Manage.CheckAndRegisterHotKey(HKVI, menuitem.Header.ToString()); } } } //菜单项添加事件 menuitem.Click += Menuitem_Click; //添加菜单项 Manage.WindowMain.Plugins.Items.Add(menuitem); } } } } } } }
/// <summary> /// 初始化操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { #region Register Hot Key Manage.WindowMainHandle = new WindowInteropHelper(this).Handle;; HotKeyVisualItem hkvi = new HotKeyVisualItem(); hkvi.HotKeysString = AppInfoOperations.GetHotKey(); if (hkvi.Available) { if (!HotKey.TestHotKey(3, System.Windows.Forms.Keys.D1, HotKey.QUICK_SEARCH_HOTKEY_ID, false)) { if (!HotKey.TestHotKey(3, System.Windows.Forms.Keys.D1, HotKey.QUICK_SEARCH_HOTKEY_ID, false)) { tipMainForm.ShowFixed(this, "Hot Key Register failed"); } } } else { if (!HotKey.TestHotKey(3, System.Windows.Forms.Keys.D1, HotKey.QUICK_SEARCH_HOTKEY_ID, false)) { tipMainForm.ShowFixed(this, "Hot Key Register failed"); } } //(uint)HotKey.KeyModifiers.Ctrl | (uint)HotKey.KeyModifiers.Alt hkvi = null; #endregion #region Initialize Visual Settings this.WindowState = WindowState.Normal; double ScreenWidth = SystemParameters.PrimaryScreenWidth; double ScreenHeight = SystemParameters.PrimaryScreenHeight; //获取位置 //并检查合法性 double readLeft = AppInfoOperations.GetLeft(); double readTop = AppInfoOperations.GetTop(); if (readLeft > 2) { this.Left = readLeft - 2; } else { this.Left = 0; } if (readTop > 1) { this.Top = readTop - 1; } else { this.Top = 0; } //获取宽高 double readWidth = AppInfoOperations.GetWidth(); double readHeight = AppInfoOperations.GetHeight(); //检查数值合法性 if (readWidth > ScreenWidth) { readWidth = ScreenWidth; } if (readHeight > ScreenHeight) { readHeight = ScreenHeight; } //应用宽高 this.Width = readWidth; this.Height = readHeight; #endregion #region Initialize Background Data //用于自动存储位置大小的开关指示 IsInformationsInitialized = true; //初始化后台数据 Manage.InitializeData(this); //初始化删除计时器 Manage.timer.Interval = TimeSpan.FromSeconds(3); Manage.timer.Stop(); Manage.timer.Tick += Timer_Tick; //其他 MELeave.RoutedEvent = Border.MouseLeaveEvent; MEEnter.RoutedEvent = Border.MouseEnterEvent; tipMainForm.Show(); //获取插件 Anything_wpf_main_.cls.Plugins.GetPlugins(); //关联事件处理 this.StateChanged += new EventHandler(animationInstance.Window_StateChanged); this.SizeChanged += new SizeChangedEventHandler(animationInstance.Window_SizeChanged); //设置窗体渐隐与显示 animationInstance.InitBdrStyle(ref this.bdrMain); //关闭加载窗体 Manage.WindowLoading.Close(); #endregion }
/// <summary> /// 初始化操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { wndProgressBar wndpb = new wndProgressBar(AllLoadHeader, AllLoadFooter, 100); #region Load language and register hotkey //加载语言 Manage.LoadingLanguage(); //注册热键 Manage.WindowMainHandle = new WindowInteropHelper(this).Handle;; HotKeyVisualItem hkvi = new HotKeyVisualItem(); if (hkvi.OuterGetKeys(AppInfoOperations.GetHotKey())) { if (!HotKey.TestHotKey(3, System.Windows.Forms.Keys.D1, HotKey.QUICK_SEARCH_HOTKEY_ID, false)) { tipMainForm.ShowFixed(this, this.HotKeyFailed); } } else { if (!HotKey.TestHotKey(3, System.Windows.Forms.Keys.D1, HotKey.QUICK_SEARCH_HOTKEY_ID, false)) { tipMainForm.ShowFixed(this, this.HotKeyFailed); } } hkvi = null; wndpb.Increase(25); #endregion #region Initialize Visual Settings this.WindowState = WindowState.Normal; double ScreenWidth = SystemParameters.PrimaryScreenWidth; double ScreenHeight = SystemParameters.PrimaryScreenHeight; //获取位置 //并检查合法性 double readLeft = AppInfoOperations.GetLeft(); double readTop = AppInfoOperations.GetTop(); if (readLeft > 2) { this.Left = readLeft - 2; } else { this.Left = 0; } if (readTop > 1) { this.Top = readTop - 1; } else { this.Top = 0; } //获取宽高 double readWidth = AppInfoOperations.GetWidth(); double readHeight = AppInfoOperations.GetHeight(); //检查数值合法性 if (readWidth > ScreenWidth) { readWidth = ScreenWidth; } if (readHeight > ScreenHeight) { readHeight = ScreenHeight; } //应用宽高 this.Width = readWidth; this.Height = readHeight; wndMainCB = new ControlBackground(Manage.CurrentPath + "Background\\", new Packer(this.bdrMainForm), ApplicationInformations.Anything.AppInfoOperations.GetBackgroundIntervalMilliseconds(), true); ClearSearch(); wndpb.Increase(25); #endregion #region Initialize Background Data //用于自动存储位置大小的开关指示 IsInformationsInitialized = true; //初始化后台数据 Manage.InitializeProgram(); wndpb.Increase(25); ////初始化删除计时器 //Manage.timer.Interval = TimeSpan.FromSeconds(3); //Manage.timer.Stop(); //Manage.timer.Tick += Timer_Tick; //其他 MELeave.RoutedEvent = Border.MouseLeaveEvent; MEEnter.RoutedEvent = Border.MouseEnterEvent; //获取插件 Class.Plugins.GetPlugins(); //关联事件处理 this.StateChanged += new EventHandler(animationInstance.Window_StateChanged); this.SizeChanged += new SizeChangedEventHandler(animationInstance.Window_SizeChanged); //设置窗体渐隐与显示 animationInstance.InitBdrStyle(ref this.bdrMain); //关闭加载窗体 //Manage.WindowLoading.Close(); wndpb.Increase(25); #endregion wndpb.Increase(); }