0

The following code (in a Firefox extension) toggles the value of the "FontSmoothing" Registry-Key.

let regFontSmooth = Components.classes["@mozilla.org/windows-registry-key;1"].createInstance(Components.interfaces.nsIWindowsRegKey);
regFontSmooth.open(regFontSmooth.ROOT_KEY_CURRENT_USER, "Control Panel\\Desktop", regFontSmooth.ACCESS_ALL);
regFontSmooth.writeStringValue("FontSmoothing", regFontSmooth.readStringValue("FontSmoothing") == 0 ? 2 : 0);
regFontSmooth.close();

How do I apply the changes immediately (without a reboot or restarting Windows Explorer)?

Thank you.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
Yaron
  • 71
  • 9
  • You don't? That's not how the windows registry works. – Mike 'Pomax' Kamermans Jul 03 '15 at 22:10
  • What do you mean "You don't?"? Can't I do that in Win 7? Thanks. – Yaron Jul 04 '15 at 00:55
  • http://stackoverflow.com/questions/7567387/c-sharp-how-to-change-windows-registry-and-take-effect-immediately has a more detailed answer. – Mike 'Pomax' Kamermans Jul 04 '15 at 01:40
  • The reference to the SystemParametersInfo function is really helpful. Thank you. – Yaron Jul 04 '15 at 14:29
  • @Mike, Thanks again. I really appreciate it. This code works: Components.utils.import("resource://gre/modules/ctypes.jsm"); let lib = ctypes.open("user32.dll"); let fontSmooth = lib.declare("SystemParametersInfoW", ctypes.winapi_abi, ctypes.bool, ctypes.unsigned_int, ctypes.unsigned_int, ctypes.voidptr_t, ctypes.unsigned_int); fontSmooth(0x004B, true, ctypes.voidptr_t(0), 0); // 0x004B = SPI_SETFONTSMOOTHING. true/false = toggle font smoothing. lib.close(); – Yaron Jul 04 '15 at 19:40
  • Many thanks to Noitidart. – Yaron Jul 04 '15 at 19:41
  • if you now have working code, with either posting that as answer to your own question, or (if you feel the other question covered everything completely) deleting your question. – Mike 'Pomax' Kamermans Jul 05 '15 at 17:16

1 Answers1

0

The following code toggles Font Smoothing.

Components.utils.import("resource://gre/modules/ctypes.jsm"); let lib = ctypes.open("user32.dll"); let fontSmooth = lib.declare("SystemParametersInfoW", ctypes.winapi_abi, ctypes.bool, ctypes.unsigned_int, ctypes.unsigned_int, ctypes.voidptr_t, ctypes.unsigned_int); fontSmooth(0x004B, true, ctypes.voidptr_t(0), 0); // 0x004B = SPI_SETFONTSMOOTHING. true/false = toggle font smoothing. lib.close(); 
Yaron
  • 71
  • 9