示例#1
0
        public static bool PickColor(Window owner, ref Color color)
        {
            var cs = new CHOOSECOLOR();

            cs.lStructSize  = Marshal.SizeOf(typeof(CHOOSECOLOR));
            cs.lpCustColors = Marshal.AllocHGlobal(64);
            Marshal.Copy(new byte[64], 0, cs.lpCustColors, 64);
            cs.hwndOwner = new WindowInteropHelper(owner).Handle;
            cs.rgbResult = (uint)color.R | (uint)color.G << 8 | (uint)color.B << 16;
            cs.Flags     = 1;

            byte[] buf;

            try
            {
                string s = App.Settings.Current.Windows.CustomColors;
                if (!string.IsNullOrEmpty(s))
                {
                    buf = Convert.FromBase64String(s);
                    Marshal.Copy(buf, 0, cs.lpCustColors, 64);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Loading custom colors failed: " + ex.Message);
            }

            bool result = ChooseColor(ref cs);

            if (result)
            {
                color = Color.FromRgb((byte)(cs.rgbResult),
                                      (byte)(cs.rgbResult >> 8),
                                      (byte)(cs.rgbResult >> 16));
            }

            buf = new byte[64];
            Marshal.Copy(cs.lpCustColors, buf, 0, 64);
            Marshal.FreeHGlobal(cs.lpCustColors);
            App.Settings.Current.Windows.CustomColors = Convert.ToBase64String(buf);

            return(true);
        }
示例#2
0
		public static bool PickColor(Window owner, ref Color color)
		{
			var cs = new CHOOSECOLOR();
			cs.lStructSize = Marshal.SizeOf(typeof(CHOOSECOLOR));
			cs.lpCustColors = Marshal.AllocHGlobal(64);
			Marshal.Copy(new byte[64], 0, cs.lpCustColors, 64);
			cs.hwndOwner = new WindowInteropHelper(owner).Handle;
			cs.rgbResult = (uint)color.R | (uint)color.G << 8 | (uint)color.B << 16;
			cs.Flags = 1;

			byte[] buf;

			try
			{
				string s = App.Settings.Current.Windows.CustomColors;
				if (!string.IsNullOrEmpty(s))
				{
					buf = Convert.FromBase64String(s);
					Marshal.Copy(buf, 0, cs.lpCustColors, 64);
				}
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine("Loading custom colors failed: " + ex.Message);
			}

			bool result = ChooseColor(ref cs);
			if (result)
			{
				color = Color.FromRgb((byte)(cs.rgbResult),
					(byte)(cs.rgbResult >> 8),
					(byte)(cs.rgbResult >> 16));
			}

			buf = new byte[64];
			Marshal.Copy(cs.lpCustColors, buf, 0, 64);
			Marshal.FreeHGlobal(cs.lpCustColors);
			App.Settings.Current.Windows.CustomColors = Convert.ToBase64String(buf);

			return true;
		}
示例#3
0
 private static extern bool ChooseColor(ref CHOOSECOLOR pChooseColor);
示例#4
0
		private static extern bool ChooseColor(ref CHOOSECOLOR pChooseColor);