private void CmdBrowse_Click(object sender, System.EventArgs e) { uint TheIndex = 0; // For The Icon OpenFileDialog MyDia = new OpenFileDialog(); MyDia.Title = "Choose File To Execute"; MyDia.Filter = "All Supported Files|*.exe;*.com;*.bat;*.vbs;*.js;*.wsf|Executable Files(*.exe)|*.exe|Batch & Com Files(*.bat)(*.com)|*.bat;*.com|Scribt Files (*.vbs)(*.js)(*.wsf)|*.vbs;*.js;*.wsf|All Files (*.*)|*.*"; if (MyDia.ShowDialog(this) == DialogResult.OK) { FileInfo MyFile = new FileInfo(MyDia.FileName); TxtCommandAddEdit.Text = MyDia.FileName; pictureBox1.Image = null; //Empty It First pictureBox1.Image = Bitmap.FromHicon //Get It From handle ( ClsAPICalls.GetExtensionIcon(this.Handle, TxtCommandAddEdit.Text, ref TheIndex) ); if (TxtNameAddEdit.Text == "") //Try To Insert name if the user didn't yet { // PUT THE FILE NAME IN TXTNAME TxtNameAddEdit.Text = MyFile.Name.Remove(MyFile.Name.Length - 4, 4); } } }
/// <summary> /// This Method takes the path to the file and then returns its icon handle HICON /// </summary> /// <param name="TheIconPath">Path To File</param> /// <returns>The Icon Handle</returns> internal IntPtr AHandle(string TheIconPath) { IntPtr GlobalIntPtr = IntPtr.Zero; uint GlobalImageIndex = 0; return (ClsAPICalls.GetExtensionIcon(GlobalIntPtr, AnalyzeIt(TheIconPath), ref GlobalImageIndex)); }
/// <summary> /// To Read The File Icon /// </summary> void ReadImage() { try { uint TheIndex = 0; IconBox.Image = null; IconBox.Image = Bitmap.FromHicon ( ClsAPICalls.GetExtensionIcon(this.Handle, TxtTaskManager.Text, ref TheIndex) ); } catch { TxtTaskManager.Text = "Unable To Read The File Icon"; } }