コード例 #1
0
ファイル: GEDmillPlugin.cs プロジェクト: hazzik/GEDKeeper
        public override bool Startup(IHost host)
        {
            bool result = base.Startup(host);

            try {
                Assembly assembly = typeof(Plugin).Assembly;
                using (var appIcon = SDIcon.ExtractAssociatedIcon(assembly.Location)) {
                    Image bmp = appIcon.ToBitmap();
                    fIcon = new ImageHandler(bmp);
                }
            } catch (Exception ex) {
                Logger.WriteError("GEDmillPlugin.Startup()", ex);
                result = false;
            }
            return(result);
        }
コード例 #2
0
        private static ImageSource GetProcessIcon(string filePath)
        {
            IconImage icon    = IconImage.ExtractAssociatedIcon(filePath);
            Bitmap    bitmap  = icon.ToBitmap();
            IntPtr    hBitmap = bitmap.GetHbitmap();

            ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(
                hBitmap,
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            if (!DeleteObject(hBitmap))
            {
                throw new Win32Exception();
            }

            return(wpfBitmap);
        }
        private static Icon GetIconForFile(string filePath)
        {
            var defaultIcon = SystemIcons.WinLogo;
            var iconForFile = defaultIcon;

            try
            {
                if (string.IsNullOrWhiteSpace(filePath))
                {
                    iconForFile = DefaultIcons.FolderLarge;
                }
                else if (File.Exists(filePath))
                {
                    iconForFile = Icon.ExtractAssociatedIcon(filePath) ?? defaultIcon;
                }
            }
            catch
            {
                // Empty
                iconForFile = defaultIcon;
            }

            return(iconForFile);
        }