Пример #1
0
        protected static void ImgToShowSourcePropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d.GetType() == typeof(ImgButton))
            {
                try
                {
                    ImgButton ib = d as ImgButton;

//                    Console.WriteLine("Tada: {0} -> {1} ", e.NewValue, ib.IsEnabled);

                    System.Drawing.Icon   ic   = (System.Drawing.Icon)LaserControl.Properties.Resources.ResourceManager.GetObject(e.NewValue.ToString());
                    System.Drawing.Bitmap bmp  = ic.ToBitmap();
                    System.Drawing.Bitmap bmpD = MakeGrayscale3(bmp);

                    ib.ImgEnabled  = BitmapToImageSource(bmp);
                    ib.ImgDisabled = BitmapToImageSource(bmpD);

                    if (ib.IsEnabled)
                    {
                        ib.Data.ImageToDisplay = ib.ImgEnabled;
                    }
                    else
                    {
                        ib.Data.ImageToDisplay = ib.ImgDisabled;
                    }

                    ic.Dispose();
                }
                catch
                {
                    //Mache nichts
                }
            }
        }
Пример #2
0
        public static System.Drawing.Icon SmallIcon(string fileName)
        {
            if (MonoHelper.IsUnix)
            {
                return(System.Drawing.Icon.ExtractAssociatedIcon(fileName));
            }

            SHFILEINFO shinfo = new SHFILEINFO();

            if (NativeMethods.SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SMALLICON) == IntPtr.Zero)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            System.Drawing.Icon tmp = System.Drawing.Icon.FromHandle(shinfo.hIcon);

            try
            {
                System.Drawing.Icon res = (System.Drawing.Icon)tmp.Clone();
                tmp.Dispose();
                NativeMethods.DestroyIcon(shinfo.hIcon);
                return(res);
            }
            catch
            {}
            return(null);
        }
Пример #3
0
        protected static void ImgToShowSourcePropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d.GetType() == typeof(AGImage))
            {
                try
                {
                    AGImage ag = d as AGImage;

                    System.Drawing.Icon   ic   = (System.Drawing.Icon)LaserControl.Properties.Resources.ResourceManager.GetObject(e.NewValue.ToString());
                    System.Drawing.Bitmap bmp  = ic.ToBitmap();
                    System.Drawing.Bitmap bmpD = MakeGrayscale3(bmp);

                    ag.ImgEnabled  = BitmapToImageSource(bmp);
                    ag.ImgDisabled = BitmapToImageSource(bmpD);

                    ag.Source = ag.IsEnabled ? ag.ImgEnabled : ag.ImgDisabled;

                    ic.Dispose();
                }
                catch
                {
                    //Mache nichts
                }
            }
        }
Пример #4
0
 public override void Reset()
 {
     base.Reset();
     if (sdicon != null)
     {
         sdicon.Dispose();
         sdicon = null;
     }
 }
Пример #5
0
        public void Dispose()
        {
            //server.Stop();

            offIcon.Dispose();
            onIcon.Dispose();

            ni.MouseClick -= NotifyIcon_MouseClick;
            ni.Dispose();
        }
Пример #6
0
        /// <summary>
        /// Loads an Icon Error Checked.
        /// </summary>
        internal static System.Drawing.Icon _LoadIconErrorChecked(string resource, int Width, int Height)
        {
            int error = 0;

            System.Drawing.Icon      retIcon = null;
            System.IntPtr            hIcon   = System.IntPtr.Zero;
            System.Reflection.Module hMod    = null;
            try
            {
                hMod = System.Reflection.Assembly.GetEntryAssembly().GetModules()[0];
            }
            catch (System.Exception)
            {
            }
            if (hMod != null)
            {
                System.IntPtr hProc = System.Runtime.InteropServices.Marshal.GetHINSTANCE(hMod);
                hIcon = LoadImage(hProc, resource, (uint)Enums.LoadImageTypes.IMAGE_ICON, Width, Height, (uint)Enums.LoadImagefuLoad.LR_SHARED);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                if (error == 0 && hIcon != System.IntPtr.Zero)
                {
                    System.Drawing.Icon iconold = System.Drawing.Icon.FromHandle(hIcon);
                    retIcon = new System.Drawing.Icon(iconold, Width, Height);
                }
            }
            else
            {
                // Forms Designer hack.
                // Load from a *.resx if it exists, otherwise make one.
                if (!System.IO.File.Exists(ResourcesDir.resourcespath))
                {
                    System.Resources.ResXResourceWriter resx = new System.Resources.ResXResourceWriter(ResourcesDir.resourcespath);
                    System.IO.MemoryStream iconstream        = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(ResourcesDir.iconpath));
                    System.Drawing.Icon    icon2Dump         = new System.Drawing.Icon(iconstream);
                    resx.AddResource(GetFileBaseName(ResourcesDir.iconpath).Trim(".ico".ToCharArray()), icon2Dump);
                    icon2Dump.Dispose();
                    // write resource file.
                    resx.Dispose();
                }
                // now read it.
                System.Resources.ResXResourceSet resxSet = new System.Resources.ResXResourceSet(ResourcesDir.resourcespath);
                // hopefully this works.
                System.Drawing.Icon iconold = (System.Drawing.Icon)resxSet.GetObject(GetFileBaseName(ResourcesDir.iconpath).Trim(".ico".ToCharArray()));
                retIcon = new System.Drawing.Icon(iconold, Width, Height);
                hIcon   = retIcon.Handle;
                resxSet.Dispose();
            }
            if (hIcon == System.IntPtr.Zero)
            {
                MessageManager.ShowError("LoadImage returned Error Code: " + error + ".", "Error!");
            }
            return(retIcon);
        }
Пример #7
0
        private void AddProfile_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog exe_filedlg = new Microsoft.Win32.OpenFileDialog();

            exe_filedlg.DefaultExt = ".exe";
            exe_filedlg.Filter     = "Executable Files (*.exe)|*.exe;";

            Nullable <bool> result = exe_filedlg.ShowDialog();

            if (result.HasValue && result == true)
            {
                string filename = System.IO.Path.GetFileName(exe_filedlg.FileName.ToLowerInvariant());

                if (Global.LightingStateManager.Events.ContainsKey(filename))
                {
                    if (Global.LightingStateManager.Events[filename] is GameEvent_Aurora_Wrapper)
                    {
                        Global.LightingStateManager.Events.Remove(filename);
                    }
                    else
                    {
                        MessageBox.Show("Profile for this application already exists.");
                        return;
                    }
                }

                GenericApplication gen_app_pm = new GenericApplication(filename);
                gen_app_pm.Initialize();
                ((GenericApplicationSettings)gen_app_pm.Settings).ApplicationName = Path.GetFileNameWithoutExtension(filename);

                System.Drawing.Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(exe_filedlg.FileName.ToLowerInvariant());

                if (!System.IO.Directory.Exists(gen_app_pm.GetProfileFolderPath()))
                {
                    System.IO.Directory.CreateDirectory(gen_app_pm.GetProfileFolderPath());
                }

                using (var icon_asbitmap = ico.ToBitmap())
                {
                    icon_asbitmap.Save(Path.Combine(gen_app_pm.GetProfileFolderPath(), "icon.png"), System.Drawing.Imaging.ImageFormat.Png);
                }
                ico.Dispose();

                Global.LightingStateManager.RegisterEvent(gen_app_pm);
                ConfigManager.Save(Global.Configuration);
                GenerateProfileStack(filename);
            }
        }
Пример #8
0
        private void AddProfile_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Window_ProcessSelection dialog = new Window_ProcessSelection {
                CheckCustomPathExists = true, ButtonLabel = "Add Profile", Title = "Add Profile"
            };

            if (dialog.ShowDialog() == true && !string.IsNullOrWhiteSpace(dialog.ChosenExecutablePath))   // do not need to check if dialog is already in excluded_programs since it is a Set and only contains unique items by definition

            {
                string filename = Path.GetFileName(dialog.ChosenExecutablePath.ToLowerInvariant());

                if (Global.LightingStateManager.Events.ContainsKey(filename))
                {
                    if (Global.LightingStateManager.Events[filename] is GameEvent_Aurora_Wrapper)
                    {
                        Global.LightingStateManager.Events.Remove(filename);
                    }
                    else
                    {
                        MessageBox.Show("Profile for this application already exists.");
                        return;
                    }
                }

                GenericApplication gen_app_pm = new GenericApplication(filename);
                gen_app_pm.Initialize();
                ((GenericApplicationSettings)gen_app_pm.Settings).ApplicationName = Path.GetFileNameWithoutExtension(filename);

                System.Drawing.Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(dialog.ChosenExecutablePath.ToLowerInvariant());

                if (!Directory.Exists(gen_app_pm.GetProfileFolderPath()))
                {
                    Directory.CreateDirectory(gen_app_pm.GetProfileFolderPath());
                }

                using (var icon_asbitmap = ico.ToBitmap())
                {
                    icon_asbitmap.Save(Path.Combine(gen_app_pm.GetProfileFolderPath(), "icon.png"), System.Drawing.Imaging.ImageFormat.Png);
                }
                ico.Dispose();

                Global.LightingStateManager.RegisterEvent(gen_app_pm);
                ConfigManager.Save(Global.Configuration);
                GenerateProfileStack(filename);
            }
        }
Пример #9
0
        private void AddProfile_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog exe_filedlg = new Microsoft.Win32.OpenFileDialog();

            exe_filedlg.DefaultExt = ".exe";
            exe_filedlg.Filter     = "Executable Files (*.exe)|*.exe;";

            Nullable <bool> result = exe_filedlg.ShowDialog();

            if (result.HasValue && result == true)
            {
                string filename = System.IO.Path.GetFileName(exe_filedlg.FileName.ToLowerInvariant());

                if (Global.Configuration.additional_profiles.ContainsKey(filename))
                {
                    System.Windows.MessageBox.Show("Profile for this application already exists.");
                }
                else
                {
                    GenericApplicationProfileManager gen_app_pm = new GenericApplicationProfileManager(filename);

                    System.Drawing.Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(exe_filedlg.FileName.ToLowerInvariant());

                    if (!System.IO.Directory.Exists(gen_app_pm.GetProfileFolderPath()))
                    {
                        System.IO.Directory.CreateDirectory(gen_app_pm.GetProfileFolderPath());
                    }

                    using (var icon_asbitmap = ico.ToBitmap())
                    {
                        icon_asbitmap.Save(Path.Combine(gen_app_pm.GetProfileFolderPath(), "icon.png"), System.Drawing.Imaging.ImageFormat.Png);
                    }
                    ico.Dispose();

                    Global.Configuration.additional_profiles.Add(filename, gen_app_pm);
                    ConfigManager.Save(Global.Configuration);
                    GenerateProfileStack();
                }

                this.content_grid.Children.Clear();
                this.content_grid.Children.Add(new Profiles.Generic_Application.Control_GenericApplication(filename));

                current_color    = desktop_color_scheme;
                transitionamount = 0.0f;
            }
        }
Пример #10
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (icon != null)
         {
             icon.TrayBalloonTipClicked -= icon_TrayBalloonTipClicked;
             icon.TrayLeftMouseDown     -= icon_TrayMouseDown;
             icon.TrayRightMouseDown    -= icon_TrayMouseDown;
             icon.Dispose();
             icon = null;
         }
         if (_icon != null)
         {
             _icon.Dispose();
             _icon = null;
         }
     }
 }
Пример #11
0
        public static BitmapSource IconCreate(this string filepath)
        {
            if (filepath != null)
            {
                try
                {
                    using System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(filepath);
                    BitmapSource bitmapsource = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    icon.Dispose();

                    if (bitmapsource.CanFreeze)
                    {
                        bitmapsource.Freeze();
                    }
                    return(bitmapsource);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            return(null);
        }
Пример #12
0
        ////////////////////////////////////////////////////////////////////////////
        protected override Cursor Read(ContentReader input, Cursor existingInstance)
        {
            if (existingInstance == null)
            {
                int    count = input.ReadInt32();
                byte[] data  = input.ReadBytes(count);

                string path = Path.GetTempFileName();
                File.WriteAllBytes(path, data);
                string tPath = Path.GetTempFileName();
                using (System.Drawing.Icon i = System.Drawing.Icon.ExtractAssociatedIcon(path))
                {
                    using (System.Drawing.Bitmap b = i.ToBitmap())
                    {
                        b.Save(tPath, System.Drawing.Imaging.ImageFormat.Png);
                        b.Dispose();
                    }

                    i.Dispose();
                }
                //TODO: Replace with xml based solution for getting hotspot and size instead
                IntPtr handle = NativeMethods.LoadCursor(path);
                System.Windows.Forms.Cursor c = new System.Windows.Forms.Cursor(handle);
                Vector2 hs = new Vector2(c.HotSpot.X, c.HotSpot.Y);
                int     w  = c.Size.Width;
                int     h  = c.Size.Height;
                c.Dispose();
                File.Delete(path);

                return(new Cursor(tPath, hs, w, h));
            }
            else
            {
            }

            return(existingInstance);
        }
Пример #13
0
        ////////////////////////////////////////////////////////////////////////////
        protected override Cursor Read(ContentReader input, Cursor existingInstance)
        {
            if (existingInstance == null)
            {
                int    count = input.ReadInt32();
                byte[] data  = input.ReadBytes(count);

                string path = Path.GetTempFileName();
                File.WriteAllBytes(path, data);
                string tPath = Path.GetTempFileName();

                using (System.Drawing.Icon i = System.Drawing.Icon.ExtractAssociatedIcon(path))
                {
                    using (System.Drawing.Bitmap b = i.ToBitmap())
                    {
                        b.Save(tPath, System.Drawing.Imaging.ImageFormat.Png);
                        b.Dispose();
                    }

                    i.Dispose();
                }

                Vector2 hs = Vector2.Zero;
                int     w  = 32;
                int     h  = 32;

                File.Delete(path);

                return(new Cursor(null, hs, w, h));
            }
            else
            {
            }

            return(existingInstance);
        }
Пример #14
0
        private static ImageSource CreateBitmapIcon(string fullName)
        {
            BitmapSource img = null;

            System.Drawing.Icon icon = null;
            Int32Rect           rect;

            try
            {
                icon = ShFileInfo.GetLargeIcon(fullName);
                rect = new Int32Rect(0, 0, icon.Width, icon.Height);
                img  = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, rect, BitmapSizeOptions.FromEmptyOptions());
                img.Freeze();
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
            finally
            {
                icon?.Dispose();
            }
            return(img);
        }