|
-
December 29th, 2008, 08:38 PM
#1
Icon item shell32
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
-
December 30th, 2008, 03:28 AM
#2
Re: Icon item shell32
the first part of your question is clear for me;
and i suggest this code to you:
Code:
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;
Last edited by toraj58; December 30th, 2008 at 03:45 AM.
Please rate my post if it was helpful for you.  Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
-
December 30th, 2008, 08:18 PM
#3
Re: Icon item shell32
Code:
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
-
December 31st, 2008, 04:02 AM
#4
Re: Icon item shell32
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.
Please rate my post if it was helpful for you.  Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|