void setTTC(int f) { const int NCOLORS = 2; static int C_ID[NCOLORS] = { // tooltips bk + txt COLOR_INFOBK, COLOR_INFOTEXT }; static COLORREF C_SAVE[NCOLORS]; static bool changed; if (SAVE_3DC == f) { int n = 0; do C_SAVE[n] = GetSysColor(C_ID[n]); while (++n<NCOLORS); changed = false; return; } if (RESTORE_3DC == f || false == setTTColor) { if (changed) { SetSysColors(NCOLORS, C_ID, C_SAVE); changed = false; } return; } if (APPLY_3DC == f) { COLORREF C_CR[NCOLORS]; GradientItem *S1, *S2; S1 = S2 = &mSkin.windowLabelFocus; if (S1->parentRelative) S1 = &mSkin.windowTitleFocus; if (B_SOLID == S1->type) C_CR[0] = S1->Color; else C_CR[0] = mixcolors(S1->Color, S1->ColorTo); C_CR[1] = S2->TextColor; SetSysColors(NCOLORS, C_ID, C_CR); changed = true; } }
/* Change system color */ static VOID SetDesktopBackColor(HWND hwndDlg, DATA *pData) { INT iElement = COLOR_BACKGROUND; HKEY hKey; LONG result; TCHAR clText[16]; BYTE red, green, blue; DWORD dwDispostion; if( !SetSysColors( 1, &iElement, &g_GlobalData.desktop_color ) ) MessageBox(hwndDlg, TEXT("SetSysColor() failed!"), /* these error texts can need internationalization? */ TEXT("Error!"), MB_ICONSTOP ); result = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\\Colors"), 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDispostion ); if (result != ERROR_SUCCESS) { red = GetRValue(g_GlobalData.desktop_color); green = GetGValue(g_GlobalData.desktop_color); blue = GetBValue(g_GlobalData.desktop_color); /* Format string to be set to registry */ StringCbPrintf(clText, sizeof(clText), TEXT("%d %d %d"), red, green, blue); RegSetValueEx(hKey, TEXT("Background"), 0, REG_SZ, (BYTE *)clText, (lstrlen(clText) + 1) * sizeof(TCHAR)); RegCloseKey(hKey); } }
static VOID SetUserSysColors(VOID) { HKEY hKey; INT i; WCHAR szColor[25]; DWORD Type, Size; COLORREF crColor; LONG rc; TRACE("()\n"); rc = RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_COLORS, 0, KEY_QUERY_VALUE, &hKey); if (rc != ERROR_SUCCESS) { WARN("RegOpenKeyEx() failed with error %lu\n", rc); return; } for(i = 0; i < NUM_SYSCOLORS; i++) { Size = sizeof(szColor); rc = RegQueryValueEx(hKey, g_RegColorNames[i], NULL, &Type, (LPBYTE)szColor, &Size); if (rc == ERROR_SUCCESS && Type == REG_SZ) { crColor = StrToColorref(szColor); SetSysColors(1, &i, &crColor); } else WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(g_RegColorNames[i]), rc); } RegCloseKey(hKey); }
void BackgroundColor::SetColor(COLORREF col) { static const INT P_COLOR_DESKTOP[] = {COLOR_DESKTOP}; if (col == m_CurrentColor) return; if (SetSysColors(1, P_COLOR_DESKTOP, &col)) m_CurrentColor = col; }
static void DD_RestoreBkgndSettings() { if (g_saved_desktop_values) { int e=COLOR_DESKTOP; unsigned long c=g_saved_bkgnd_color; SetSysColors(1, &e, &c); // F*****G MESSAGE PUMP AND SETSYSCOLORS SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, g_saved_desktop_wallpaper, NULL); g_saved_desktop_values=0; } }
void InitSysColors(void) { char KeyNames[1024]; char KeyColor[128]; LPSTR lpKey; LPSTR lpFile; int n,ret; COLORREF sc; COLORREF rc; HDC hDC; lpFile = GetTwinFilename(); GetPrivateProfileString((LPSTR)"colors",NULL,NULL, KeyNames,1024,lpFile); hDC = GetDC(0); for(lpKey = KeyNames; *lpKey != 0; lpKey += strlen(lpKey) + 1) for(n=0; SysColorNames[n]; n++) if(strcasecmp(SysColorNames[n],lpKey) == 0) { sc = GetSysColor(n); ret = GetPrivateProfileString( (LPSTR)"colors", (LPSTR) lpKey, (LPSTR) 0, KeyColor, 128, lpFile); if (ret) { rc = GetStringColor(KeyColor); switch (n) { case COLOR_MENU: case COLOR_WINDOW: case COLOR_BTNFACE: case COLOR_HIGHLIGHT: case COLOR_MENUTEXT: case COLOR_WINDOWTEXT: case COLOR_CAPTIONTEXT: case COLOR_HIGHLIGHTTEXT: case COLOR_BTNTEXT: /* those cannot be dithered */ rc = GetNearestColor(hDC,rc); break; default: break; } SetSysColors(1,&n,&rc); break; } } ReleaseDC(0,hDC); }
Standard_EXPORTEXTERN long InterfaceGraphic_RealizePalette ( HDC hdc, HPALETTE hPal, BOOL fBkg, BOOL fUseStatic ) { int i; long retVal = 0; if ( fUseStatic ) { if ( !s_sysUse ) for ( i = 0; i < NB_STATIC_COLORS; ++i ) s_sysPal[ i ] = GetSysColor ( s_sysPalIdx[ i ] ); SetSystemPaletteUse ( hdc, fBkg ? SYSPAL_STATIC : SYSPAL_NOSTATIC ); if ( UnrealizeObject ( hPal ) && SelectPalette ( hdc, hPal, fBkg ) ) retVal = RealizePalette ( hdc ); if ( fBkg ) { SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPal ); s_sysUse = FALSE; } else { SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPalBW ); s_sysUse = TRUE; } // end else #pragma warning(push) #pragma warning(disable:4306) /* level 4 warning on cast of int to HWND in HWND_BROADCAST macro */ PostMessage ( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 ); #pragma warning(pop) } else { SelectPalette ( hdc, hPal, FALSE ); retVal = RealizePalette ( hdc ); } // end else return retVal; } // end RealizePaletteNow
__declspec( dllexport ) long InterfaceGraphic_RealizePalette ( HDC hdc, HPALETTE hPal, BOOL fBkg, BOOL fUseStatic ) { int i; long retVal = 0; if ( fUseStatic ) { if ( !s_sysUse ) for ( i = 0; i < NB_STATIC_COLORS; ++i ) s_sysPal[ i ] = GetSysColor ( s_sysPalIdx[ i ] ); SetSystemPaletteUse ( hdc, fBkg ? SYSPAL_STATIC : SYSPAL_NOSTATIC ); if ( UnrealizeObject ( hPal ) && SelectPalette ( hdc, hPal, fBkg ) ) retVal = RealizePalette ( hdc ); if ( fBkg ) { SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPal ); s_sysUse = FALSE; } else { SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPalBW ); s_sysUse = TRUE; } // end else PostMessage ( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 ); } else { SelectPalette ( hdc, hPal, FALSE ); retVal = RealizePalette ( hdc ); } // end else return retVal; } // end RealizePaletteNow
void CWallpaper::Restore() { if(!IsWallpaperRemoved) return; // Restore the original desktop wallpaper SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, 0, 0); // Restore the original desktop color int colorID = COLOR_BACKGROUND; SetSysColors(1, &colorID, &OriginalColor); IsWallpaperRemoved = false; }
static void apply_sysparams(void) { NONCLIENTMETRICSW nonclient_metrics; int i, cnt = 0; int colors_idx[sizeof(metrics) / sizeof(metrics[0])]; COLORREF colors[sizeof(metrics) / sizeof(metrics[0])]; nonclient_metrics.cbSize = sizeof(nonclient_metrics); SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(nonclient_metrics), &nonclient_metrics, 0); nonclient_metrics.iMenuWidth = nonclient_metrics.iMenuHeight = metrics[IDC_SYSPARAMS_MENU - IDC_SYSPARAMS_BUTTON].size; nonclient_metrics.iCaptionWidth = nonclient_metrics.iCaptionHeight = metrics[IDC_SYSPARAMS_ACTIVE_TITLE - IDC_SYSPARAMS_BUTTON].size; nonclient_metrics.iScrollWidth = nonclient_metrics.iScrollHeight = metrics[IDC_SYSPARAMS_SCROLLBAR - IDC_SYSPARAMS_BUTTON].size; memcpy(&(nonclient_metrics.lfMenuFont), &(metrics[IDC_SYSPARAMS_MENU_TEXT - IDC_SYSPARAMS_BUTTON].lf), sizeof(LOGFONTW)); memcpy(&(nonclient_metrics.lfCaptionFont), &(metrics[IDC_SYSPARAMS_ACTIVE_TITLE_TEXT - IDC_SYSPARAMS_BUTTON].lf), sizeof(LOGFONTW)); memcpy(&(nonclient_metrics.lfStatusFont), &(metrics[IDC_SYSPARAMS_TOOLTIP_TEXT - IDC_SYSPARAMS_BUTTON].lf), sizeof(LOGFONTW)); memcpy(&(nonclient_metrics.lfMessageFont), &(metrics[IDC_SYSPARAMS_MSGBOX_TEXT - IDC_SYSPARAMS_BUTTON].lf), sizeof(LOGFONTW)); SystemParametersInfoW(SPI_SETNONCLIENTMETRICS, sizeof(nonclient_metrics), &nonclient_metrics, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); for (i = 0; i < sizeof(metrics) / sizeof(metrics[0]); i++) if (metrics[i].color_idx != -1) { colors_idx[cnt] = metrics[i].color_idx; colors[cnt++] = metrics[i].color; } SetSysColors(cnt, colors_idx, colors); }
void CWallpaper::Remove() { if(IsWallpaperRemoved) return; // Black color... static const DWORD BlackColor = RGB(0,0,0); // Save the current background color OriginalColor = GetSysColor(COLOR_BACKGROUND); // Set the desktop background color to the wanted one int colorID = COLOR_BACKGROUND; COLORREF color = BlackColor; SetSysColors(1, &colorID, &color); // Remove the desktop wallpaper, without updating the registry char nullchar = 0; SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, &nullchar, 0); IsWallpaperRemoved = true; }
// ------------------------------------------------ // // FUNCTION: gui_SetSysColor( PA_PluginParameters params ) // // PURPOSE: Set the color of the specified display element. // // DATE: MJG 12/1/03 (3.5.6) // void gui_SetSysColor( PA_PluginParameters params ) { LONG_PTR returnValue; INT_PTR displayElement[1]; COLORREF rgbValue[1]; BYTE rValue, gValue, bValue; returnValue = 0; displayElement[0] = (INT_PTR) PA_GetLongParameter( params, 1); rValue = (BYTE) PA_GetLongParameter( params, 2); gValue = (BYTE) PA_GetLongParameter( params, 3); bValue = (BYTE) PA_GetLongParameter( params, 4); rgbValue[0] = RGB(rValue, gValue, bValue); returnValue = SetSysColors(1, displayElement, rgbValue); if(returnValue != 0) returnValue = 1; PA_ReturnLong( params, returnValue ); }
/********************************************************************************************* * * This is the window procedure for the main window. * * Message: Action: * ======== ======= * WM_CREATE save hInst for dialog box calls, and save menu and window colors * WM_DESTROY indicate that the window proc is complete * WM_PAINT print output message centered in client area * WM_SIZE save new client dimensions * WM_COMMAND IDM_LOCALTIME: display message box with local time * IDM_UPTIME: display message box with time system has been up * IDM_SHOWCOLORS: display message box with text representation of * menu text and background colors * IDM_CHANGECOLORS: change menu text and background colors * IDM_RESTORECOLORS: restore menu text and background colors to their * original values * IDM_SCRDIM: display message box with screen dimensions * IDM_BEEP: display beep dialog * IDM_EXIT: leave the program * *********************************************************************************************/ LRESULT CALLBACK WndProc(HWND hWnd, UINT messg, WPARAM wParam, LPARAM lParam) { static HINSTANCE hInst; // used for dialog box static BOOL bNeedToRestoreColors; // flag to do cleanup HDC hdc; // device context for painting PAINTSTRUCT ps; // paint structure for painting DWORD dElapsedTimeSysHasBeenUp; // time (ms) since system was booted DWORD dOtherTime; // another variable to hold time char lpstrOutString[256]; // string for message boxes SIZE mySize, *lpSize=&mySize; // used to calculate coordinates to center text SYSTEMTIME SysTime; // system time SYSTEMTIME *lpSysTime = &SysTime; // pointer to previous DWORD dwCheckColorInfo[2]; // holds color information DWORD dwNewColorInfo[2] = // colors to change (red windows, green menus) {RGB(255,0,0),RGB(0,255,0)}; static DWORD dwSavedColorInfo[2]= // saved colors {0,0}; static int iDisplayElements[2] = // elements to change {COLOR_MENUTEXT, COLOR_MENU}; int i; // temp int hsize,vsize,hres,vres; // screen dimensions switch (messg) { /* * WM_CREATE: get instance handle for later use putting up * dialog box. Get initial colors for windows and menus * so they can be restored upon exit (unless the user * remembers to do it). */ case WM_CREATE: hInst = ((LPCREATESTRUCT) lParam) -> hInstance; dwSavedColorInfo[0] = GetSysColor(COLOR_MENUTEXT); dwSavedColorInfo[1] = GetSysColor(COLOR_MENU); bNeedToRestoreColors = FALSE; break; /* * WM_DESTROY: If user forgot to restore colors, do it. Then * terminate this window. */ case WM_DESTROY: if (bNeedToRestoreColors) { SetSysColors(2,iDisplayElements,dwSavedColorInfo); bNeedToRestoreColors = FALSE; } PostQuitMessage(0); break; /* * WM_PAINT: Put the text string into the window, at the center * of the client area. */ case WM_PAINT: hdc = BeginPaint(hWnd,&ps); GetTextExtentPoint(hdc,lpstrHiWorld,strlen(lpstrHiWorld),lpSize); TextOut(hdc,(newX-(lpSize->cx))/2, (newY-(lpSize->cy))/2, lpstrHiWorld,strlen(lpstrHiWorld)); EndPaint(hWnd,&ps); break; /* * WM_SIZE: save new x and y coordinates to use later in * centering */ case WM_SIZE: newX = LOWORD(lParam); newY = HIWORD(lParam); break; /* * WM_COMMAND: see individual items */ case WM_COMMAND: switch (LOWORD(wParam)) { /* * IDM_LOCALTIME: Get the local time, put it into a string, * then output it via a message box */ case IDM_LOCALTIME: GetLocalTime(lpSysTime); sprintf(lpstrOutString,"Today is \n\t%02d/%02d/%02d\n and the time is \n\t%02d:%02d:%02d", lpSysTime->wMonth, lpSysTime->wDay, lpSysTime->wYear-1900, lpSysTime->wHour, lpSysTime->wMinute, lpSysTime->wSecond); MessageBox(hWnd,lpstrOutString,"Local time",MB_OK); break; /* * IDM_UPTIME: Get the current time, put it into a string, * then output it via a message box */ case IDM_UPTIME: dElapsedTimeSysHasBeenUp = GetCurrentTime(); dOtherTime = timeGetTime(); sprintf(lpstrOutString,"System has been up for:\n\t%d milliseconds (GetCurrentTime)\n\t%d milliseconds (timeGetTime)", dElapsedTimeSysHasBeenUp,dOtherTime); MessageBox(hWnd,lpstrOutString,"Time since system was booted",MB_OK); break; /* * IDM_SHOWCOLORS: Get the current menu text and menu background * colors. Put them into a text string then * output them via a message box. */ case IDM_SHOWCOLORS: i = 0; dwCheckColorInfo[0] = GetSysColor(COLOR_MENUTEXT); strcpy(lpstrOutString,"Menu text is "); i += strlen(lpstrOutString); RGB2Text(dwCheckColorInfo[0],&lpstrOutString[i]); dwCheckColorInfo[1] = GetSysColor(COLOR_MENU); strcat(lpstrOutString,"Menu background is "); i = strlen(lpstrOutString); RGB2Text(dwCheckColorInfo[1],&lpstrOutString[i]); MessageBox(hWnd,lpstrOutString,"Color Information",MB_OK); break; /* * IDM_CHANGECOLORS: Enable the "restore" menu item. Set flag to * ensure that we clean up, then change the * menu text and menu background colors. */ case IDM_CHANGECOLORS: EnableMenuItem(GetMenu(hWnd),IDM_RESTORECOLORS,MF_ENABLED|MF_BYCOMMAND); bNeedToRestoreColors = TRUE; SetSysColors(2,iDisplayElements,dwNewColorInfo); break; /* * IDM_RESTORECOLORS: Disable the "restore" menu item. Clear the * cleanup flag, then change the * menu text and menu background colors * back to their original values. */ case IDM_RESTORECOLORS: EnableMenuItem(GetMenu(hWnd),IDM_RESTORECOLORS,MF_GRAYED|MF_BYCOMMAND); bNeedToRestoreColors = FALSE; SetSysColors(2,iDisplayElements,dwSavedColorInfo); break; /* * IDM_SCRDIM: Get the screen dimensions, put them into a string, * then output it via a message box */ case IDM_SCRDIM: hdc = GetDC(hWnd); hsize = GetDeviceCaps(hdc,HORZSIZE); vsize = GetDeviceCaps(hdc,VERTSIZE); hres = GetDeviceCaps(hdc,HORZRES); vres = GetDeviceCaps(hdc,VERTRES); sprintf(lpstrOutString, "Horizontal size:\t\t%d mm\nVertical Size:\t\t%d mm\nHorizontal resolution:\t%d pixels\nVertical Resolution:\t%d pixels", hsize,vsize,hres,vres); ReleaseDC(hWnd,hdc); MessageBox(hWnd,lpstrOutString,"Screen Dimensions",MB_OK); break; /* * IDM_BEEP: Display beep dialog box. */ case IDM_BEEP: DialogBox(hInst,MAKEINTRESOURCE(BEEPDIALOG),hWnd,BeepDiaProc); break; /* * WM_DESTROY: If user forgot to restore colors, do it. Then * terminate this window. */ case IDM_EXIT: if (bNeedToRestoreColors) { SetSysColors(2,iDisplayElements,dwSavedColorInfo); bNeedToRestoreColors = FALSE; } PostQuitMessage(0); break; default: return(DefWindowProc(hWnd,messg,wParam,lParam)); } break; default: return(DefWindowProc(hWnd,messg,wParam,lParam)); } return(0L); }
/* Read back old settings after a theme was deactivated */ static void UXTHEME_RestoreSystemMetrics(void) { HKEY hKey; const struct BackupSysParam* bsp = backupSysParams; if (RegOpenKeyExW (HKEY_CURRENT_USER, szThemeManager, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { HKEY colorKey; /* read backed-up colors */ if (RegOpenKeyExW (hKey, strColorKey, 0, KEY_QUERY_VALUE, &colorKey) == ERROR_SUCCESS) { int i; COLORREF sysCols[NUM_SYS_COLORS]; int sysColsIndices[NUM_SYS_COLORS]; int sysColCount = 0; for (i = 0; i < NUM_SYS_COLORS; i++) { DWORD type; char colorStr[13]; DWORD count = sizeof(colorStr); if (RegQueryValueExA (colorKey, SysColorsNames[i], 0, &type, (LPBYTE) colorStr, &count) == ERROR_SUCCESS) { int r, g, b; if (sscanf (colorStr, "%d %d %d", &r, &g, &b) == 3) { sysColsIndices[sysColCount] = i; sysCols[sysColCount] = RGB(r, g, b); sysColCount++; } } } RegCloseKey (colorKey); SetSysColors (sysColCount, sysColsIndices, sysCols); } /* read backed-up other settings */ while (bsp->spiGet >= 0) { DWORD value; DWORD count = sizeof(value); DWORD type; if (RegQueryValueExW (hKey, bsp->keyName, 0, &type, (LPBYTE)&value, &count) == ERROR_SUCCESS) { SystemParametersInfoW (bsp->spiSet, 0, UlongToPtr(value), SPIF_UPDATEINIFILE); } bsp++; } /* read backed-up non-client metrics */ { NONCLIENTMETRICSW ncm; LOGFONTW iconTitleFont; DWORD count = sizeof(ncm); DWORD type; if (RegQueryValueExW (hKey, keyNonClientMetrics, 0, &type, (LPBYTE)&ncm, &count) == ERROR_SUCCESS) { SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, count, &ncm, SPIF_UPDATEINIFILE); } count = sizeof(iconTitleFont); if (RegQueryValueExW (hKey, keyIconTitleFont, 0, &type, (LPBYTE)&iconTitleFont, &count) == ERROR_SUCCESS) { SystemParametersInfoW (SPI_SETICONTITLELOGFONT, count, &iconTitleFont, SPIF_UPDATEINIFILE); } } RegCloseKey (hKey); } }