Skip to content

Instantly share code, notes, and snippets.

@ytoshima
Created June 26, 2014 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytoshima/42175512fd3062fefef5 to your computer and use it in GitHub Desktop.
Save ytoshima/42175512fd3062fefef5 to your computer and use it in GitHub Desktop.
Show or flip font smoothing setting using SystemParameterInfo API
/*
* shows font smoothing setting, which is true by default.
* flips font smoothing setting if "flip" was specified on command line.
* compilation: cl fontsmoothing.cpp user32.lib
*/
#include <windows.h>
#include <stdio.h>
BOOL fontSmoothingStatus()
{
BOOL theState = FALSE;
SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &theState, 0);
return theState;
}
BOOL flipFontSmoothing()
{
BOOL iState = fontSmoothingStatus();
BOOL newState = !iState;
printf("set param: %s\n", newState ? "true" : "false");
BOOL rv = SystemParametersInfo(SPI_SETFONTSMOOTHING,
newState, NULL, SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
if (rv == 0) {
DWORD lerr = GetLastError();
fprintf(stderr, "SystemParametersInfo(SPI_SETFONTSMOOTHING,...) failed, error code: %d %#x\n", lerr, lerr);
}
return fontSmoothingStatus();
}
#if 0
void setupConsole() {
if (!::AttachConsole(ATTACH_PARENT_PROCESS)) {
// open new console if this was not invoked in a console
::AllocConsole();
}
freopen("CON", "r", stdin); // assign stdin
freopen("CON", "w", stdout); // assign stdout
freopen("CON", "w", stderr); // assign stdout
}
void cleanupConsole() {
::FreeConsole();
}
int WINAPI WinMain(HINSTANCE hi, HINSTANCE hp, LPSTR cl, int cs) {
setupConsole();
printf("cl: %s, cs %d\n", cl, cs);
BOOL currentState = fontSmoothingStatus();
printf("current status: %s\n", currentState ? "true" : "false");
/*
BOOL newState = flipFontSmoothing();
printf("new status: %s\n", newState ? "true" : "false");
*/
cleanupConsole();
PostQuitMessage(0);
return 0;
}
#endif
int main(int argc, char *argv[]) {
BOOL currentState = fontSmoothingStatus();
printf("current status: %s\n", currentState ? "true" : "false");
BOOL doFlip = FALSE;
if (argc > 1) {
if (strncmp(argv[1], "flip", strlen("flip")) == 0) {
doFlip = TRUE;
} else {
fprintf(stderr, "E: unexpected argument: %s\n", argv[1]);
}
}
if (doFlip) {
BOOL newState = flipFontSmoothing();
printf("new status: %s\n", newState ? "true" : "false");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment