/// <summary> /// 获取当前已激活的进程信息 /// </summary> /// <returns></returns> public ProgramInfoTemp GetForeProgramInfo() { try { var ForegHandle = WindowsAPI.GetForegroundWindow(); WindowsAPI.GetWindowThreadProcessId(ForegHandle, out int ProgramID); var ProcessObj = Process.GetProcessById(ProgramID); if (ProcessObj == null) { return(null); } var ResultObj = ProgramInfoList.FirstOrDefault(T1 => T1.Name == ProcessObj.ProcessName); if (ResultObj != null) { return(ResultObj); } var FileName = ProcessObj.Modules[0].FileName; var ForeImage = UniversalMethod.GetImageByFileName(FileName); var ForeImgHex = UniversalMethod.ByteArayToHex(ForeImage.ToByteArray()); ResultObj = new ProgramInfoTemp(); ResultObj.Name = ProcessObj.ProcessName; ResultObj.Img = ForeImage; ResultObj.ImgHex = ForeImgHex; ProgramInfoList.Add(ResultObj); return(ResultObj); } catch { return(null); } }
private void SelectProgram_button_MouseDown(object sender, MouseEventArgs e) { Task.Run(() => { while (Control.MouseButtons != MouseButtons.None) { var HandleInt = WindowsAPI.WindowFromPoint(Control.MousePosition.X, Control.MousePosition.Y); WindowsAPI.GetWindowThreadProcessId(new IntPtr(HandleInt), out int ProgramID); var ProcessObj = Process.GetProcessById(ProgramID); if (ProcessObj == null) { Thread.Sleep(100); continue; } this.Invoke(new Action(() => { try { var FaileName = ProcessObj.Modules[0].FileName; Target_pictureBox.Image = UniversalMethod.GetImageByFileName(FaileName); } catch { } Program_textBox.Text = ProcessObj.ProcessName; })); Thread.Sleep(100); } }); }
/// <summary> 选择文件路径时 /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SelectPath_button_Click(object sender, EventArgs e) { if (CurrentEntity == null) { return; } switch (CurrentEntity.ShortCutKeyType) { case 0: //文件/程序 SelectFilePath.Filter = "所有文件|*.*"; if (SelectFilePath.ShowDialog() == DialogResult.Cancel) { return; } Path_textBox.Text = SelectFilePath.FileName; Img_pictureBox.Image = UniversalMethod.GetImageByFileName(Path_textBox.Text); if (string.IsNullOrEmpty(Name_textBox.Text)) { Name_textBox.Text = Path.GetFileNameWithoutExtension(Path_textBox.Text); } break; } }
/// <summary> 将文件拖拽到窗口后 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_DragDrop(object sender, DragEventArgs e) { System.Array ArrayTemp = ((System.Array)e.Data.GetData(DataFormats.FileDrop)); if (ArrayTemp == null) { return; //不支持的格式直接返回 } List <string> FilePathList = new List <string>(); for (int i = 0; i < ArrayTemp.Length; i++) { FilePathList.Add(ArrayTemp.GetValue(i).ToString()); } #region 获取父ID,使新添加的记录与当前选中节点处于同一级别 string StrParentId = ""; TreeNode CurrentNode = ShortcutKey_otTreeView.SelectedNode; if (CurrentNode != null) { tShortCutKey CurrentEntity = tShortCutKeyDataSource.Where(T1 => T1.ShortCutKeyID == CurrentNode.Name).FirstOrDefault(); if (CurrentEntity != null) { StrParentId = CurrentEntity.ShortCutKeyID; } } #endregion 获取父ID,使新添加的记录与当前选中节点处于同一级别 foreach (string PathItem in FilePathList) { string StrFileName = Path.GetFileNameWithoutExtension(PathItem);//获取快捷键名称 int KeyNum = GetDefaultKey(StrParentId); string StrKeyNum = ""; if (KeyNum != -1) { StrKeyNum = KeyNum.ToString(); //获取默认键编号 } int FileType = 0; //设置打开类型 byte[] ImageByteArray = UniversalMethod.GetImageByFileName(PathItem).ToByteArray(); //获取文件图标 #region 获取快捷方式真实路径 string StrPath = PathItem; string StrExtension = Path.GetExtension(PathItem); if (!string.IsNullOrEmpty(StrExtension))//文件 { if (StrExtension == ".lnk") { WshShell ShellTemp = new WshShell(); IWshShortcut IWshShortcutTemp = (IWshShortcut)ShellTemp.CreateShortcut(PathItem); StrPath = IWshShortcutTemp.TargetPath; StrExtension = Path.GetExtension(StrPath); if (string.IsNullOrEmpty(StrExtension)) { FileType = 1; } } } else//文件夹 { FileType = 1; } Regex RegexTemp = new Regex(@"https{0,1}\:\/\/"); if (RegexTemp.Match(StrPath).Success)//是否是网址 { FileType = 2; } #endregion 获取快捷方式真实路径 #region 实例化AddData tShortCutKey AddData = new tShortCutKey() { ShortCutKeyName = StrFileName, ParentID = StrParentId, ShortCutKey = StrKeyNum, ShortCutKeyPath = StrPath, ShortCutKeyType = (byte)FileType, ShortCutKeyImg = ImageByteArray }; #endregion 实例化AddData string NewID = new ShortcutKeyManageService().AddShortCutKey(AddData); tShortCutKeyDataSource.Add(AddData); } InitKeyList(); }