Пример #1
0
 private static bool IsResourceCategory(UserPreferenceCategory category)
 {
     if (category != UserPreferenceCategory.Accessibility && category != UserPreferenceCategory.Color)
     {
         return(category == UserPreferenceCategory.VisualStyle);
     }
     return(true);
 }
Пример #2
0
 public UserPreferenceChangedEventArgs(UserPreferenceCategory category)
 {
     this.mycategory = category;
 }
 // Constructors
 public UserPreferenceChangedEventArgs(UserPreferenceCategory category)
 {
 }
		public UserPreferenceChangingEventArgs (UserPreferenceCategory category)
		{
			this.mycategory = category;
		}
Пример #5
0
        public static void SendMessageOnUserPreferenceChanged(UserPreferenceCategory category)
        {
            IntPtr window = GetHWnd();

            WM     msg;
            IntPtr wParam;

            if (category == UserPreferenceCategory.Color)
            {
                msg    = WM.SYSCOLORCHANGE;
                wParam = IntPtr.Zero;
            }
            else
            {
                msg = WM.SETTINGCHANGE;

                if (category == UserPreferenceCategory.Accessibility)
                {
                    wParam = (IntPtr)SPI.SETHIGHCONTRAST;
                }
                else if (category == UserPreferenceCategory.Desktop)
                {
                    wParam = (IntPtr)SPI.SETDESKWALLPAPER;
                }
                else if (category == UserPreferenceCategory.Icon)
                {
                    wParam = (IntPtr)SPI.ICONHORIZONTALSPACING;
                }
                else if (category == UserPreferenceCategory.Mouse)
                {
                    wParam = (IntPtr)SPI.SETDOUBLECLICKTIME;
                }
                else if (category == UserPreferenceCategory.Keyboard)
                {
                    wParam = (IntPtr)SPI.SETKEYBOARDDELAY;
                }
                else if (category == UserPreferenceCategory.Menu)
                {
                    wParam = (IntPtr)SPI.SETMENUDROPALIGNMENT;
                }
                else if (category == UserPreferenceCategory.Power)
                {
                    wParam = (IntPtr)SPI.SETLOWPOWERACTIVE;
                }
                else if (category == UserPreferenceCategory.Screensaver)
                {
                    wParam = (IntPtr)SPI.SETMENUDROPALIGNMENT;
                }
                else if (category == UserPreferenceCategory.Window)
                {
                    wParam = (IntPtr)SPI.SETMENUDROPALIGNMENT;
                }
                else
                {
                    throw new NotImplementedException($"Not implemented category {category}.");
                }
            }

            // Call with reflect to immediately send the message.
            SendMessageW(window, msg | WM.REFLECT, wParam, IntPtr.Zero);
        }
 public UserPreferenceChangingEventArgs(UserPreferenceCategory category)
 {
     this.category = category;
 }
        public void SignalsUserPreferenceEventsSynchronously(int message, int uiAction, string area, UserPreferenceCategory expectedCategory)
        {
            bool changing = false, changed = false;

            UserPreferenceChangingEventArgs    changingArgs = null;
            UserPreferenceChangingEventHandler changingHandler = (o, e) =>
            {
                changingArgs = e;
                changing     = true;
            };

            UserPreferenceChangedEventArgs    changedArgs = null;
            UserPreferenceChangingEventArgs   changingDuringChanged = null;
            UserPreferenceChangedEventHandler changedHandler = (o, e) =>
            {
                changedArgs           = e;
                changingDuringChanged = changingArgs;
                changed = true;
            };

            SystemEvents.UserPreferenceChanging += changingHandler;
            SystemEvents.UserPreferenceChanged  += changedHandler;


            try
            {
                SendReflectedMessage(message, uiAction, area);
                Assert.True(changing);
                Assert.NotNull(changingArgs);
                Assert.Equal(expectedCategory, changingArgs.Category);

                Assert.True(changed);
                Assert.NotNull(changedArgs);
                Assert.Equal(expectedCategory, changedArgs.Category);

                // changed must follow changing for the same category
                Assert.NotNull(changingDuringChanged);
                Assert.Equal(expectedCategory, changingDuringChanged.Category);
            }
            finally
            {
                SystemEvents.UserPreferenceChanging -= changingHandler;
                SystemEvents.UserPreferenceChanged  -= changedHandler;
            }
        }
        public void SignalsUserPreferenceEventsAsynchronously(int message, int uiAction, string area, UserPreferenceCategory expectedCategory)
        {
            var changing = new AutoResetEvent(false);
            var changed  = new AutoResetEvent(false);

            UserPreferenceChangingEventArgs    changingArgs    = null;
            UserPreferenceChangingEventHandler changingHandler = (o, e) =>
            {
                changingArgs = e;
                changing.Set();
            };

            UserPreferenceChangedEventArgs    changedArgs           = null;
            UserPreferenceChangingEventArgs   changingDuringChanged = null;
            UserPreferenceChangedEventHandler changedHandler        = (o, e) =>
            {
                changedArgs           = e;
                changingDuringChanged = changingArgs;
                changed.Set();
            };

            SystemEvents.UserPreferenceChanging += changingHandler;
            SystemEvents.UserPreferenceChanged  += changedHandler;

            try
            {
                SendMessage(message, uiAction, area);
                Assert.True(changing.WaitOne(PostMessageWait));
                Assert.NotNull(changingArgs);
                Assert.Equal(expectedCategory, changingArgs.Category);

                Assert.True(changed.WaitOne(PostMessageWait));
                Assert.NotNull(changedArgs);
                Assert.Equal(expectedCategory, changedArgs.Category);

                // changed must follow changing for the same category
                Assert.NotNull(changingDuringChanged);
                Assert.Equal(expectedCategory, changingDuringChanged.Category);
            }
            finally
            {
                SystemEvents.UserPreferenceChanging -= changingHandler;
                SystemEvents.UserPreferenceChanged  -= changedHandler;
                changing.Dispose();
                changed.Dispose();
            }
        }
        public void ProfessionalColorTable_ChangeUserPreferences_GetColor_ReturnsExpected(UserPreferenceCategory category)
        {
            using RemoteInvokeHandle invokerHandle = RemoteExecutor.Invoke(() =>
            {
                // Simulate a SystemEvents.UserPreferenceChanged event.
                var table   = new ProfessionalColorTable();
                Color color = table.ButtonSelectedHighlight;
                SystemEventsHelper.SendMessageOnUserPreferenceChanged(category);
                Assert.Equal(color, table.ButtonSelectedHighlight);
            });

            // verify the remote process succeeded
            Assert.Equal(0, invokerHandle.ExitCode);
        }
 public UserPreferenceChangedEventArgs(UserPreferenceCategory category)
 {
     this.category = category;
 }
Пример #11
0
 // Constructors
 public UserPreferenceChangingEventArgs(UserPreferenceCategory category)
 {
 }
 public UserPreferenceChangedEventArgs(UserPreferenceCategory category)
 {
     throw new NotImplementedException();
 }