Vancel
December 29th, 2008, 07:38 PM
I'd like to use an icon in shell32.dll. How can I use it with a click of my mouse to change icon for any particular text file I like ?
Thanks alot
Thanks alot
|
Click to See Complete Forum and Search --> : Icon item shell32 Vancel December 29th, 2008, 07:38 PM I'd like to use an icon in shell32.dll. How can I use it with a click of my mouse to change icon for any particular text file I like ? Thanks alot toraj58 December 30th, 2008, 02:28 AM the first part of your question is clear for me; and i suggest this code to you: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace shell32LoadIcon { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { int numOfIcons = 20;// i want to get 20 icons from shell32.dll IntPtr[] largeSizeIcons = new IntPtr[numOfIcons]; // small size icons IntPtr[] smallSizeIcons = new IntPtr[numOfIcons]; // large size icons ExtractIconEx("shell32.dll", 0, largeSizeIcons, smallSizeIcons, numOfIcons); Icon largeIcon = Icon.FromHandle(largeSizeIcons[15]); // loading icon in index 15 Icon smallIcon = Icon.FromHandle(smallSizeIcons[15]); button1.Image = largeIcon.ToBitmap(); } [DllImport("Shell32.dll")] public extern static int ExtractIconEx(string libName, int iconIndex, IntPtr[] largeIcon, IntPtr[] smallIcon, int nIcons); } } but the second part of your question is not clear for me. the code i suggested get 20 icons from shell32.dll (both small and large size) then load the icon resides in the 15 index of the collection (the large one) and assigne it to the image property of the button1 (first convet it to bitmap). don't forget to add this to the top of your code: using System.Runtime.InteropServices; :thumb: Vancel December 30th, 2008, 07:18 PM FileOpendialog f=new Fileopendialog(); if(f.Showdialog()==Dialogresult.OK) { file.currentIcon=myIcon } I's like to change a icon of i.e a tetx file by an icon i have in memory Thank you toraj58 December 31st, 2008, 03:02 AM it is not possible! changing icon of a text file (*.txt) is totally difference of changing the ICON of a EXE file or a folder. you can not change the icon of a single text file. it is only possible to change the icon of *.txt type files using registry keys. it means that the icon of all files with *.txt extenssion will be changed but it is dependent to the system you have channged it if you move to other system the icon of the *.txt files will base on the setting of that system in the registry. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |