바보 같은 질문이라면 용서를 구합니다. 하지만 아래에 게시 할 코드를 어떻게 사용할 수 있는지 정말 알아야합니다. 양식에서 복사했습니다. 폴더/파일 아이콘 오버레이를 구현하고 싶습니다. 그래서 검색하는 동안 아래 코드를 발견했습니다.아이콘 오버레이 C#
public sealed class ShellInterop
{
private ShellInterop()
{
}
[DllImport("shell32.dll")]
public static extern void SHChangeNotify(int eventID, uint flags, IntPtr item1, IntPtr item2);
}
[ComVisible(false)]
[ComImport]
[Guid("0C6C4200-C589-11D0-999A-00C04FD655E1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IShellIconOverlayIdentifier
{
[PreserveSig]
int IsMemberOf([MarshalAs(UnmanagedType.LPWStr)]string path, uint attributes);
[PreserveSig]
int GetOverlayInfo(
IntPtr iconFileBuffer,
int iconFileBufferSize,
out int iconIndex,
out uint flags);
[PreserveSig]
int GetPriority(out int priority);
}
[ComVisible(true)]
[Guid("B8FA9E43-38E6-4654-8A13-FF905AD22CE5")]
public class MyIconOverlay : IShellIconOverlayIdentifier
{
#region IShellIconOverlayIdentifier Members
public int IsMemberOf(string path, uint attributes)
{
//Show everything with icon overlay
return 0; // S_OK
}
public int GetOverlayInfo(IntPtr iconFileBuffer, int
iconFileBufferSize,
out int iconIndex, out uint flags)
{
System.Diagnostics.Debug.WriteLine(string.Format("GetOverlayInfo::{0}", iconFileBuffer));
System.Diagnostics.Debug.WriteLine(string.Format("GetOverlayInfo::{0}", iconFileBufferSize));
string fname = @"c:\NormalIcon.ico";
int bytesCount = System.Text.Encoding.Unicode.GetByteCount(fname);
System.Diagnostics.Debug.WriteLine(string.Format("GetOverlayInfo::{0}", bytesCount));
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(fname);
if (bytes.Length + 2 < iconFileBufferSize)
{
for (int i = 0; i < bytes.Length; i++)
{
Marshal.WriteByte(iconFileBuffer, i, bytes[i]);
}
//write the "\0\0"
Marshal.WriteByte(iconFileBuffer, bytes.Length, 0);
Marshal.WriteByte(iconFileBuffer, bytes.Length + 1, 0);
}
iconIndex = 0;
flags = 1; // ISIOI_ICONFILE
return 0; // S_OK
}
public int GetPriority(out int priority)
{
priority = 0; // 0-100 (0 is highest priority)
return 0; // S_OK
}
#endregion
#region Registry
[ComRegisterFunction]
public static void Register(Type t)
{
RegistryKey rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\_"
+ t.Name);
rk.SetValue(string.Empty, t.GUID.ToString("B").ToUpper());
rk.Close();
ShellInterop.SHChangeNotify(0x08000000, 0, IntPtr.Zero, IntPtr.Zero);
}
[ComUnregisterFunction]
public static void Unregister(Type t)
{
Registry.LocalMachine.DeleteSubKeyTree(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\_"
+ t.Name);
ShellInterop.SHChangeNotify(0x08000000, 0, IntPtr.Zero, IntPtr.Zero);
}
#endregion
}
아무에게 나 설명 할 수 있으면 제발. 상황에 따라 사용자가 특수 폴더 아래에 만드는 파일과 폴더의 아이콘 오버레이를 구현해야합니다.
감사
코드의 어떤 부분을 이해하지 못합니까? –
방금 아이콘 오버레이를 구현하는 데이 코드를 어떻게 사용할 수 있습니까? 내 말은, 나는 특별한 폴더가 있고, 그 특별한 폴더에 파일이나 폴더를 넣으면 SVN과 같이 각 파일/폴더에 아이콘이 적용되어야한다. 이를 위해이 코드를 어떻게 사용할 수 있습니까? –