コード例 #1
0
		Gdk.Pixbuf GetIcon (string filename, uint size)
		{
			var shinfo = new Win32.SHFILEINFO ();
			Win32.SHGetFileInfo (filename, Win32.FILE_ATTRIBUTES_NORMAL, ref shinfo, (uint)Marshal.SizeOf (shinfo), Win32.SHGFI_USEFILEATTRIBUTES | Win32.SHGFI_ICON | Win32.SHGFI_ICONLOCATION | Win32.SHGFI_TYPENAME | size);
			if (shinfo.iIcon == 0) {
				Win32.DestroyIcon (shinfo.hIcon);
				return null;
			}
			var icon = Icon.FromHandle (shinfo.hIcon);
			string key = shinfo.iIcon + " - " + shinfo.szDisplayName + " - " + icon.Width;

			Gdk.Pixbuf pix;
			if (!icons.TryGetValue (key, out pix)) {
				pix = CreateFromResource (icon.ToBitmap ());
				icons[key] = pix;
			}
			Win32.DestroyIcon (shinfo.hIcon);
			return pix;
		}
コード例 #2
0
        Gdk.Pixbuf GetIcon(string filename, uint size)
        {
            var shinfo = new Win32.SHFILEINFO();

            Win32.SHGetFileInfo(filename, Win32.FILE_ATTRIBUTES_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_USEFILEATTRIBUTES | Win32.SHGFI_ICON | Win32.SHGFI_ICONLOCATION | Win32.SHGFI_TYPENAME | size);
            if (shinfo.iIcon == 0)
            {
                Win32.DestroyIcon(shinfo.hIcon);
                return(null);
            }
            var    icon = Icon.FromHandle(shinfo.hIcon);
            string key  = shinfo.iIcon + " - " + shinfo.szDisplayName + " - " + icon.Width;

            Gdk.Pixbuf pix;
            if (!icons.TryGetValue(key, out pix))
            {
                pix        = CreateFromResource(icon.ToBitmap());
                icons[key] = pix;
            }
            Win32.DestroyIcon(shinfo.hIcon);
            return(pix);
        }