Beispiel #1
0
        internal static Bitmap GetImageFromExe(string Filename)
        {
            try
            {
                //Bitmap bResult = new Bitmap(GetIconForFile(Filename, ShellIconSize.LargeIcon).ToBitmap(), new Size(128, 128));
                Bitmap bResult = System.Drawing.Icon.ExtractAssociatedIcon(Filename).ToBitmap();

                try
                {
                    TsudaKageyu.IconExtractor iE = new TsudaKageyu.IconExtractor(Filename);
                    if (iE.FileName != null)
                    {
                        List <Icon> lIcons = TsudaKageyu.IconUtil.Split(iE.GetIcon(0)).ToList();
                        //Max Size 64px...
                        var ico = lIcons.Where(t => t.Height <= 64 & t.ToBitmap().PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb).OrderByDescending(t => t.Height).FirstOrDefault();
                        if (ico != null)
                        {
                            return(ico.ToBitmap());
                        }
                        else
                        {
                            return(bResult);
                        }
                    }
                }
                catch { }

                return(bResult);
                //return System.Drawing.Icon.ExtractAssociatedIcon(Filename).ToBitmap();
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
        public static System.Drawing.Bitmap GetImageFromExe(string Filename)
        {
            try
            {
                System.Drawing.Bitmap bResult = System.Drawing.Icon.ExtractAssociatedIcon(Filename).ToBitmap();

                try
                {
                    TsudaKageyu.IconExtractor iE = new TsudaKageyu.IconExtractor(Filename);
                    if (iE.FileName != null)
                    {
                        List <System.Drawing.Icon> lIcons = TsudaKageyu.IconUtil.Split(iE.GetIcon(0)).ToList();
                        //Max Size 128px...
                        var ico = lIcons.Where(t => t.Height <= 128 && t.ToBitmap().PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb).OrderByDescending(t => t.Height).FirstOrDefault();
                        if (ico != null)
                        {
                            return(ico.ToBitmap());
                        }
                        else
                        {
                            return(bResult);
                        }
                    }
                }
                catch { }

                return(bResult);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #3
0
        public AppHolder(String exePath, String arguments) : base()
        {
            if (!IsDotNetProcess(exePath))
            {
                Console.WriteLine(exePath + " is not a compatable program");
                Dispose();
                return;
            }
            ProcessStartInfo info = new ProcessStartInfo(exePath, arguments);

            try
            {
                info.UseShellExecute        = false;
                info.CreateNoWindow         = true;
                info.RedirectStandardInput  = false;
                info.RedirectStandardOutput = true;
                info.RedirectStandardError  = false;
                info.WindowStyle            = ProcessWindowStyle.Hidden;
                pro = Process.Start(info);
                pro.WaitForInputIdle();
                pro.Exited += Exited;
                while (pro.MainWindowHandle == null || pro.MainWindowHandle == IntPtr.Zero)
                {
                    ;
                }
                SetParent(pro.MainWindowHandle, GuestArea.Handle);
                do
                {
                    GetClientRect(pro.MainWindowHandle, ref siz);
                } while (siz.Width == 0 && siz.Height == 0);
                // WS_POPUP style and add WS_CHILD style
                const UInt32 WS_POPUP = 0x80000000, WS_CHILD = 0x40000000;
                uint         style = (UInt32)GetWindowLong(pro.MainWindowHandle, -16);
                //style = (style & ~(WS_POPUP)) | WS_CHILD;
                SetWindowLong(pro.MainWindowHandle, -16, style);
                //int GWL_STYLE = (-16);
                //uint WS_VISIBLE = 0x10000000;
                //SetWindowLong(pro.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                MoveWindow(pro.MainWindowHandle, 0, 0, siz.Width, siz.Height, true);
                Size                = new Size(siz.Width + lefts.Width + rights.Width, siz.Height + programtopbar.Height + bottoms.Height + 0);
                this.Maximise      += Max;
                this.DoubleBuffered = true;
                base.Resize        += resizing;
                this.Closing       += Exited;
                //info.WindowStyle = ProcessWindowStyle.Hidden

                //    do {
                //        //ProjectChicagoObjects.modCommunication.Nap(400, false)
                //        SetParent(pro.MainWindowHandle, GuestArea.Handle);
                //        GetClientRect(pro.MainWindowHandle, ref siz);
                //    // MessageBox.Show(siz.ToString)
                //    //    Console.WriteLine(siz)
                //    }while ( siz.Width == 0 && siz.Height == 0);
                //    //  Console.WriteLine("c")
                //    pro.BeginOutputReadLine();
                //MessageBox.Show(Graphics.FromHwnd(pro.MainWindowHandle).DpiX & "," & Graphics.FromHwnd(pro.MainWindowHandle).DpiY)
                //Size = new Size(siz.Width + lefts.Width + rights.Width, siz.Height + programtopbar.Height + bottoms.Height + 0); //Graphics.FromHwnd(pro.MainWindowHandle).DpiX, Graphics.FromHwnd(pro.MainWindowHandle).DpiY)             REMOVE EXTRAS AND SEE IF IT WORKS
                // SetWindowPos(pro.MainWindowHandle, 0, panGuestMod.PointToScreen(panGuestMod.Location).X, panGuestMod.PointToScreen(panGuestMod.Location).Y, panGuestMod.Width, panGuestMod.Height, 64) //MoveWindow(pro.MainWindowHandle, panGuestMod.PointToScreen(panGuestMod.Location).X, panGuestMod.PointToScreen(panGuestMod.Location).Y, panGuestMod.Width, panGuestMod.Height, true)
                //   Console.WriteLine("Title")
                Text = pro.MainWindowTitle;
                TsudaKageyu.IconExtractor i = new TsudaKageyu.IconExtractor(pro.StartInfo.FileName);
                // in
                if (i.Count > 0)
                {
                    programIcon.Image = new Bitmap(i.GetIcon(i.Count - 1).ToBitmap(), 16, 16);
                }
                else
                {
                    programIcon.Image = new Bitmap(com.prepareImage(com.toSystemPath(com.Config.GetConfig("windows", "GenericAppIco").Setting)), 16, 16);                                                                                              // New TsudaKageyu.IconUtil //pro.StartInfo.FileName).ToBitmap
                }
            }
            catch (Exception ex) {
                Debug.WriteLine(ex.ToString());
            }
        }
        public Bitmap addImage(string strPath, string strCurrentDir)
        {
            string strFilPath = strPath;

            try
            {
                if (OSIco != null)
                {
                    if (System.IO.Directory.Exists(strPath) == true && (new DirectoryInfo(strPath)).Name.EndsWith("‰ƒ"))//DrivePath
                    {
                        return(DriveIcon(strPath));
                    }
                    if (System.IO.Directory.Exists(strPath) == true && strPath == strCurrentDir)//Open Directory
                    {
                        return(com.prepareImage(Bitmap.FromHicon(OSIco[68].Handle), FollowPallet));
                    }
                    if (System.IO.Directory.Exists(strPath) == true && strPath != strCurrentDir)//Directory
                    {
                        return(com.prepareImage(Bitmap.FromHicon(OSIco[69].Handle), FollowPallet));
                    }
                    Int32 intIconIndex;
                    if (strPath.Contains(',') && Int32.TryParse(strPath.Split(',').Last(), out intIconIndex))                       //Icon Extraction
                    {
                        return(Bitmap.FromHicon(TsudaKageyu.IconUtil.Split(new Icon(strPath.Split(',')[0]))[intIconIndex].Handle)); //, true);
                    }
                    if (!System.IO.File.Exists(strPath))                                                                            //Error
                    {
                        return(com.prepareImage(Bitmap.FromHicon(OSIco[52].Handle), FollowPallet));
                    }
                    if (strPath.EndsWith("lnk", true, System.Globalization.CultureInfo.CurrentUICulture))
                    {
                        Bitmap   ink = new Bitmap(1, 1);
                        Graphics g   = Graphics.FromImage(ink);
                        ShortCut lnk = new ShortCut(strPath);
                        if (ink.Width + ink.Height == 2)
                        {
                            ink = new Bitmap(addImage(com.toSystemPath(lnk.TargetFile), ""), 32, 32);
                        }
                        if (!(File.ReadAllLines(strFilPath).Count() >= 5 && File.ReadAllLines(strFilPath)[4] == "Sys"))
                        {
                            g.DrawImage(Bitmap.FromHicon(OSIco[29].Handle), 0, ink.Height - OSIco[29].Height);
                        }
                        return(com.prepareImage(ink, FollowPallet));
                    }
                    if (strPath.EndsWith("U95exe", true, System.Globalization.CultureInfo.CurrentUICulture) || strPath.EndsWith("U95com", true, System.Globalization.CultureInfo.CurrentUICulture))
                    {
                        return(null);// Properties.Resources.Attention;
                    }
                    if ((ViewType == ExplorerType.ControlPanel && strPath.EndsWith("cpl", true, System.Globalization.CultureInfo.CurrentUICulture)) || strPath.EndsWith("exe", true, System.Globalization.CultureInfo.CurrentUICulture))
                    {
                        TsudaKageyu.IconExtractor i = new TsudaKageyu.IconExtractor(strPath); // addImage(CDrivePath & File.ReadAllLines(strPath).First, "")
                                                                                              // MessageBox.Show(strPath)
                        if (i.Count > 0)
                        {
                            return(com.prepareImage(i.GetIcon(i.Count - 1).ToBitmap(), FollowPallet));
                        }
                        else
                        {
                            return(com.prepareImage(Bitmap.FromHicon(OSIco[70].Handle), FollowPallet));  // Return setSetting.OSIco(Int(ReadAllLines(strPath).Last)).ToBitmap
                        }
                    }
                    if (strPath.EndsWith(".U95ico", true, System.Globalization.CultureInfo.CurrentUICulture))
                    {
                        return(com.prepareImage(strPath));
                    }
                    if (strPath.EndsWith(".txt", true, System.Globalization.CultureInfo.CurrentUICulture))
                    {
                        return(com.prepareImage(Bitmap.FromHicon(OSIco[42].Handle), FollowPallet));
                    }
                    if (strPath.EndsWith(".msi", true, System.Globalization.CultureInfo.CurrentUICulture))
                    {
                        return(com.prepareImage(Bitmap.FromHicon(OSIco[46].Handle), FollowPallet));
                    }
                    return(com.prepareImage(Bitmap.FromHicon(OSIco[0].Handle), FollowPallet));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            if (strFilPath.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase))
            {
                return(ScaleImage(strFilPath, 48, 48));
            }
            if ((OSIco == null) || OSIco.Count() < 1)
            {
                return((Bitmap)FileIcon.GetLargeIcon(strFilPath));
            }
            else
            {
                return(null);
            }
        }