Ejemplo n.º 1
0
        public static bool GetPathIcon(ref StringBuilder path, out Icon icon)
        {
            if (System.IO.File.Exists(path.ToString()))
            {
                WinAPI.Icon.SHFILEINFO shinfo = new WinAPI.Icon.SHFILEINFO();
                IntPtr pimgList = IntPtr.Zero;

                string filename = path.ToString();
                WinAPI.Icon.SHGetFileInfo(filename, 0, out shinfo, (uint)Marshal.SizeOf(typeof(WinAPI.Icon.SHFILEINFO)), WinAPI.Icon.SHGFI.SHGFI_SYSICONINDEX);

                WinAPI.Icon.SHIL currentshil = (WinAPI.Icon.SHIL)GHManager.Settings.Style.ItemList.UseIconSize;

                int rsult = WinAPI.Icon.SHGetImageList(currentshil, ref WinAPI.Icon.IID_IImageList, out pimgList);
                icon = Icon.FromHandle(WinAPI.Icon.ImageList_GetIcon(pimgList, shinfo.iIcon, 0));

                WinAPI.Icon.DestroyIcon(shinfo.hIcon);
                WinAPI.Icon.ImageList_Destroy(pimgList);
                shinfo.hIcon = IntPtr.Zero;
                pimgList     = IntPtr.Zero;

                return(true);
            }
            else
            {
                icon = null;
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// ハンドルからプロセスのアイコンを取得
        /// </summary>
        /// <param name="hwnd">ウィンドウハンドル</param>
        /// <param name="icon">アイコンの読み込み先</param>
        /// <returns></returns>
        public static bool GetProcessIcon(ref long hwnd, out Icon icon)
        {
            StringBuilder path = new StringBuilder(255);

            if (GetProcessPath(ref hwnd, out path))
            {
                WinAPI.Icon.SHFILEINFO shinfo = new WinAPI.Icon.SHFILEINFO();
                IntPtr pimgList = IntPtr.Zero;

                string filename = path.ToString();

                try {
                    WinAPI.Icon.SHGetFileInfo(filename, 0, out shinfo, (uint)Marshal.SizeOf(typeof(WinAPI.Icon.SHFILEINFO)), WinAPI.Icon.SHGFI.SHGFI_SYSICONINDEX);

                    WinAPI.Icon.SHIL currentshil = (WinAPI.Icon.SHIL)GHManager.Settings.Style.ItemList.UseIconSize;

                    int rsult = WinAPI.Icon.SHGetImageList(currentshil, ref WinAPI.Icon.IID_IImageList, out pimgList);
                    icon = Icon.FromHandle(WinAPI.Icon.ImageList_GetIcon(pimgList, shinfo.iIcon, 0));
                }
                catch (Exception e) {
                    Console.WriteLine("GetProcessIcon: " + e.Message);
                    icon = null;
                }

                WinAPI.Icon.DestroyIcon(shinfo.hIcon);
                WinAPI.Icon.ImageList_Destroy(pimgList);
                shinfo.hIcon = IntPtr.Zero;
                pimgList     = IntPtr.Zero;

                return(true);
            }
            else
            {
                icon = null;
                return(false);
            }
        }