├── screenshots ├── image1.jpg ├── image2.jpg ├── image3.jpg └── main_window.jpg ├── WindowsThemeColorFixer ├── ColorConvert.h ├── ColorConvert.cpp ├── DwmColorLibrary.h ├── DwmColorLibrary.cpp ├── WindowsThemeColorFixer.rc ├── res │ ├── WindowsThemeColorFixer.ico │ └── WindowsThemeColorFixer.rc2 ├── stdafx.cpp ├── targetver.h ├── Common.h ├── WindowsThemeColorFixer.h ├── WindowsThemeColorApi.h ├── resource.h ├── stdafx.h ├── WindowsThemeColorFixerDlg.h ├── Common.cpp ├── WindowsThemeColorFixer.vcxproj.filters ├── WindowsThemeColorFixer.cpp ├── WindowsThemeColorApi.cpp ├── WindowsThemeColorFixer.vcxproj └── WindowsThemeColorFixerDlg.cpp ├── README.md ├── LICENSE ├── WindowsThemeColorFixer.sln └── .gitignore /screenshots/image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/screenshots/image1.jpg -------------------------------------------------------------------------------- /screenshots/image2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/screenshots/image2.jpg -------------------------------------------------------------------------------- /screenshots/image3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/screenshots/image3.jpg -------------------------------------------------------------------------------- /screenshots/main_window.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/screenshots/main_window.jpg -------------------------------------------------------------------------------- /WindowsThemeColorFixer/ColorConvert.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/WindowsThemeColorFixer/ColorConvert.h -------------------------------------------------------------------------------- /WindowsThemeColorFixer/ColorConvert.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/WindowsThemeColorFixer/ColorConvert.cpp -------------------------------------------------------------------------------- /WindowsThemeColorFixer/DwmColorLibrary.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/WindowsThemeColorFixer/DwmColorLibrary.h -------------------------------------------------------------------------------- /WindowsThemeColorFixer/DwmColorLibrary.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/WindowsThemeColorFixer/DwmColorLibrary.cpp -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorFixer.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/WindowsThemeColorFixer/WindowsThemeColorFixer.rc -------------------------------------------------------------------------------- /WindowsThemeColorFixer/res/WindowsThemeColorFixer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/WindowsThemeColorFixer/res/WindowsThemeColorFixer.ico -------------------------------------------------------------------------------- /WindowsThemeColorFixer/res/WindowsThemeColorFixer.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongyang219/WindowsThemeColorFixer/HEAD/WindowsThemeColorFixer/res/WindowsThemeColorFixer.rc2 -------------------------------------------------------------------------------- /WindowsThemeColorFixer/stdafx.cpp: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.cpp : 只包括标准包含文件的源文件 3 | // WindowsThemeColorFixer.pch 将作为预编译标头 4 | // stdafx.obj 将包含预编译类型信息 5 | 6 | #include "stdafx.h" 7 | 8 | 9 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WindowsThemeColorFixer 2 | ## 截图 3 | 4 | 截图 5 | 6 | ## 简介 7 | 8 | 在 Windows10 1809 及后面的版本中,如果你在”个性化“>”颜色“中设置了”从我的背景中自动选取一种主题颜色“的话,那么自动获取的颜色全部都是非常深的颜色,这在浅色主题中显得尤其违和。 9 | 10 | 如下图所示: 11 | 12 | 桌面截图 13 | 14 | 这个问题是从Windows10 1809版本开始的,这似乎是微软有意这么做的,但是我完全无法理解微软这么做的意义是什么。 15 | 16 | 为了解决这个问题,我开发了这个小工具,它可以在系统主题色改变时获取主题颜色,并增加其亮度,再修改系统的主题色为增加亮度后的颜色。 17 | 18 | 如图所示: 19 | 20 | 桌面截图2 21 | 22 | 从上图可以看到,窗口标题栏的颜色已经被调整到正常颜色了。 23 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class CCommon 3 | { 4 | public: 5 | CCommon(); 6 | ~CCommon(); 7 | 8 | static COLORREF GetWindowsThemeColor(); 9 | static bool SetWindowsThemeColor(COLORREF color); 10 | 11 | //当前是否启动“从我的背景自动选取一种主题色” 12 | static bool IsAutoColor(); 13 | 14 | static COLORREF DWColorToCOLORREF(DWORD dwColor); 15 | static DWORD COLORREFToDWColor(COLORREF color); 16 | 17 | static bool IsSystemLightTheme(); 18 | static bool IsAppLightTheme(); 19 | 20 | static bool IsColorSimilar(COLORREF color1, COLORREF color2); 21 | 22 | protected: 23 | static DWORD GetRegisgerDWordValue(LPCTSTR path, LPCTSTR item_name); 24 | }; 25 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorFixer.h: -------------------------------------------------------------------------------- 1 | 2 | // WindowsThemeColorFixer.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CWindowsThemeColorFixerApp: 15 | // 有关此类的实现,请参阅 WindowsThemeColorFixer.cpp 16 | // 17 | 18 | class CWindowsThemeColorFixerApp : public CWinApp 19 | { 20 | public: 21 | CWindowsThemeColorFixerApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | public: 29 | void SetAutoRun(bool auto_run); 30 | bool GetAutoRun(); 31 | 32 | private: 33 | std::wstring m_module_path; 34 | std::wstring m_module_path_reg; 35 | 36 | DECLARE_MESSAGE_MAP() 37 | }; 38 | 39 | extern CWindowsThemeColorFixerApp theApp; 40 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorApi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace WindowsThemeColorApi 4 | { 5 | struct DWMCOLORIZATIONPARAMS { 6 | DWORD dwColor; 7 | DWORD dwAfterglow; 8 | DWORD dwColorBalance; 9 | DWORD dwAfterglowBalance; 10 | DWORD dwBlurBalance; 11 | DWORD dwGlassReflectionIntensity; 12 | DWORD dwOpaqueBlend; 13 | }; 14 | 15 | struct IMMERSIVE_COLOR_PREFERENCE { 16 | COLORREF color1; 17 | COLORREF color2; 18 | }; 19 | 20 | void InitWindowsThemeColorApi(); 21 | COLORREF GetDwmColorizationColor(); 22 | void SetDwmColorizationColor(COLORREF color); 23 | COLORREF GetAccentColor(); 24 | void SetAccentColor(COLORREF color, bool newAccentAlgorithmWorkaround = false); 25 | bool IsNewAutoColorAccentAlgorithm(); 26 | void SetAutoColorAccentAlgorithm(bool bNewAlgorithm); 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 zhongyang219 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 WindowsThemeColorFixer.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_WINDOWSTHEMECOLORFIXER_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDR_MENU1 130 11 | #define IDC_REDUCE_COLOR_CHECK 1000 12 | #define IDC_BUTTON1 1001 13 | #define IDC_BUTTON2 1002 14 | #define IDC_ADJUST_COLOR_BUTTON 1002 15 | #define IDC_AUTO_RUN_CHECK 1003 16 | #define IDC_HIDE_MAIN_WINDOW_CHECK 1004 17 | #define IDC_STATIC_VERSION 1005 18 | #define IDC_STATIC_COPYRIGHT 1006 19 | #define IDC_ADJUST_ONLY_LIGHT_MODE_CHECK 1007 20 | #define IDC_CHECK2 1008 21 | #define IDC_ENHANCED_CHECK 1008 22 | #define IDC_COUNT_STATIC 1009 23 | #define IDC_COUNT_STATIC2 1010 24 | #define ID_SETTINGS 32771 25 | #define ID_1_32772 32772 26 | #define ID_MENU_EXIT 32773 27 | 28 | // Next default values for new objects 29 | // 30 | #ifdef APSTUDIO_INVOKED 31 | #ifndef APSTUDIO_READONLY_SYMBOLS 32 | #define _APS_NEXT_RESOURCE_VALUE 132 33 | #define _APS_NEXT_COMMAND_VALUE 32774 34 | #define _APS_NEXT_CONTROL_VALUE 1010 35 | #define _APS_NEXT_SYMED_VALUE 101 36 | #endif 37 | #endif 38 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.102 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WindowsThemeColorFixer", "WindowsThemeColorFixer\WindowsThemeColorFixer.vcxproj", "{EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}.Debug|x64.ActiveCfg = Debug|x64 17 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}.Debug|x64.Build.0 = Debug|x64 18 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}.Debug|x86.ActiveCfg = Debug|Win32 19 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}.Debug|x86.Build.0 = Debug|Win32 20 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}.Release|x64.ActiveCfg = Release|x64 21 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}.Release|x64.Build.0 = Release|x64 22 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}.Release|x86.ActiveCfg = Release|Win32 23 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1C6D7724-F2A5-46A8-9F1F-E8C6B38AE1F9} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/stdafx.h: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.h : 标准系统包含文件的包含文件, 3 | // 或是经常使用但不常更改的 4 | // 特定于项目的包含文件 5 | 6 | #pragma once 7 | 8 | #ifndef VC_EXTRALEAN 9 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 10 | #endif 11 | 12 | #include "targetver.h" 13 | 14 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 15 | 16 | // 关闭 MFC 对某些常见但经常可放心忽略的警告消息的隐藏 17 | #define _AFX_ALL_WARNINGS 18 | 19 | #include // MFC 核心组件和标准组件 20 | #include // MFC 扩展 21 | 22 | 23 | #include // MFC 自动化类 24 | 25 | 26 | 27 | #ifndef _AFX_NO_OLE_SUPPORT 28 | #include // MFC 对 Internet Explorer 4 公共控件的支持 29 | #endif 30 | #ifndef _AFX_NO_AFXCMN_SUPPORT 31 | #include // MFC 对 Windows 公共控件的支持 32 | #endif // _AFX_NO_AFXCMN_SUPPORT 33 | 34 | #include // 功能区和控件条的 MFC 支持 35 | 36 | 37 | //用于获取系统主题颜色 38 | #pragma comment(lib,"Dwmapi.lib") 39 | 40 | #include 41 | 42 | #define WM_NOTIFYICON (WM_USER+1001) 43 | 44 | 45 | 46 | 47 | #ifdef _UNICODE 48 | #if defined _M_IX86 49 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 50 | #elif defined _M_X64 51 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 52 | #else 53 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 54 | #endif 55 | #endif 56 | 57 | #define TIMER_ID 1234 58 | 59 | #define APP_NAME L"WindowsThemeColorFixer" 60 | #define VERSION L"1.12" //程序版本 61 | #define COMPILE_DATE L"2025/02/07" 62 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorFixerDlg.h: -------------------------------------------------------------------------------- 1 | 2 | // WindowsThemeColorFixerDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | #include "DwmColorLibrary.h" 7 | 8 | // CWindowsThemeColorFixerDlg 对话框 9 | class CWindowsThemeColorFixerDlg : public CDialog 10 | { 11 | // 构造 12 | public: 13 | CWindowsThemeColorFixerDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_WINDOWSTHEMECOLORFIXER_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | bool m_auto_adjust_color{ true }; 29 | bool m_hide_main_window_when_start{ false }; 30 | bool m_adjust_only_light_mode{ false }; 31 | bool m_enhanced_mode{ false }; 32 | CDwmColorLibrary m_dwm_lib; 33 | 34 | NOTIFYICONDATA m_ntIcon; //通知区域图标 35 | CMenu m_menu; 36 | 37 | bool m_first_start{ true }; //初始时为true,在定时器第一次启动后置为flase 38 | int m_color_adjust_count{}; //已调整颜色的次数 39 | 40 | void LoadConfig(); 41 | void SaveConfig() const; 42 | 43 | void SetOpaque(int opaque); //设置不透明度 44 | 45 | COLORREF GetThemeColor(); 46 | void SetThemeColor(COLORREF color); 47 | void DoAdjustThemeColor(); 48 | 49 | static UINT AdjustThemeColorThreadCallback(LPVOID dwUser); //调整主题颜色的线程函数 50 | bool m_adjust_color_required{ false }; //线程中需要调整主题颜色标志,当需要调整主题颜色时置为true,调整一次主题颜色时置为false 51 | 52 | // 生成的消息映射函数 53 | virtual BOOL OnInitDialog(); 54 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 55 | afx_msg void OnPaint(); 56 | afx_msg HCURSOR OnQueryDragIcon(); 57 | DECLARE_MESSAGE_MAP() 58 | public: 59 | afx_msg void OnBnClickedReduceColorCheck(); 60 | afx_msg void OnTimer(UINT_PTR nIDEvent); 61 | afx_msg void OnBnClickedButton1(); 62 | // afx_msg void OnBnClickedButton2(); 63 | afx_msg void OnBnClickedAdjustColorButton(); 64 | afx_msg void OnSettings(); 65 | protected: 66 | afx_msg LRESULT OnNotifyicon(WPARAM wParam, LPARAM lParam); 67 | public: 68 | afx_msg void OnAppAbout(); 69 | afx_msg void OnClose(); 70 | afx_msg void OnMenuExit(); 71 | afx_msg void OnDestroy(); 72 | protected: 73 | afx_msg LRESULT OnTaskbarcreated(WPARAM wParam, LPARAM lParam); 74 | public: 75 | afx_msg void OnColorizationColorChanged(DWORD dwColorizationColor, BOOL bOpacity); 76 | afx_msg void OnBnClickedHideMainWindowCheck(); 77 | afx_msg BOOL OnQueryEndSession(); 78 | afx_msg void OnBnClickedAutoRunCheck(); 79 | afx_msg void OnBnClickedAdjustOnlyLightModeCheck(); 80 | afx_msg void OnBnClickedEnhancedCheck(); 81 | }; 82 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/Common.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Common.h" 3 | #include "WindowsThemeColorApi.h" 4 | 5 | 6 | CCommon::CCommon() 7 | { 8 | } 9 | 10 | 11 | CCommon::~CCommon() 12 | { 13 | } 14 | 15 | COLORREF CCommon::GetWindowsThemeColor() 16 | { 17 | DWORD crColorization; 18 | BOOL fOpaqueBlend; 19 | COLORREF theme_color{}; 20 | HRESULT result = DwmGetColorizationColor(&crColorization, &fOpaqueBlend); 21 | if (result == S_OK) 22 | { 23 | BYTE r, g, b; 24 | r = (crColorization >> 16) % 256; 25 | g = (crColorization >> 8) % 256; 26 | b = crColorization % 256; 27 | theme_color = RGB(r, g, b); 28 | } 29 | return theme_color; 30 | } 31 | 32 | bool CCommon::SetWindowsThemeColor(COLORREF color) 33 | { 34 | CRegKey key; 35 | if (key.Open(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\DWM")) == ERROR_SUCCESS) 36 | { 37 | DWORD accent_color{ 0xff000000 | color }; 38 | if (key.SetDWORDValue(_T("AccentColor"), accent_color) == ERROR_SUCCESS) 39 | return true; 40 | } 41 | return false; 42 | } 43 | 44 | 45 | bool CCommon::IsAutoColor() 46 | { 47 | CRegKey key; 48 | if (key.Open(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\History")) == ERROR_SUCCESS) 49 | { 50 | DWORD auto_color{}; 51 | if (key.QueryDWORDValue(_T("AutoColor"), auto_color) == ERROR_SUCCESS) 52 | return (auto_color != 0); 53 | } 54 | return false; 55 | } 56 | 57 | COLORREF CCommon::DWColorToCOLORREF(DWORD dwColor) 58 | { 59 | BYTE r, g, b; 60 | r = (dwColor >> 16) % 256; 61 | g = (dwColor >> 8) % 256; 62 | b = dwColor % 256; 63 | return RGB(r, g, b); 64 | } 65 | 66 | DWORD CCommon::COLORREFToDWColor(COLORREF color) 67 | { 68 | DWORD dw_color = 0; 69 | BYTE r, g, b; 70 | r = GetRValue(color); 71 | g = GetGValue(color); 72 | b = GetBValue(color); 73 | 74 | dw_color = (r << 16); 75 | dw_color |= (g << 8); 76 | dw_color |= b; 77 | return dw_color; 78 | } 79 | 80 | bool CCommon::IsSystemLightTheme() 81 | { 82 | return GetRegisgerDWordValue(_T("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"), _T("SystemUsesLightTheme")) != 0; 83 | } 84 | 85 | bool CCommon::IsAppLightTheme() 86 | { 87 | return GetRegisgerDWordValue(_T("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"), _T("AppsUseLightTheme")) != 0; 88 | } 89 | 90 | static bool ColorValueSimilar(BYTE val1, BYTE val2) 91 | { 92 | return std::abs(val1 - val2) < 4; 93 | } 94 | 95 | bool CCommon::IsColorSimilar(COLORREF color1, COLORREF color2) 96 | { 97 | BYTE r1 = GetRValue(color1); 98 | BYTE g1 = GetGValue(color1); 99 | BYTE b1 = GetBValue(color1); 100 | BYTE r2 = GetRValue(color2); 101 | BYTE g2 = GetGValue(color2); 102 | BYTE b2 = GetBValue(color2); 103 | 104 | return ColorValueSimilar(r1, r2) && ColorValueSimilar(g1, g2) && ColorValueSimilar(b1, b2); 105 | } 106 | 107 | DWORD CCommon::GetRegisgerDWordValue(LPCTSTR path, LPCTSTR item_name) 108 | { 109 | CRegKey key; 110 | if (key.Open(HKEY_CURRENT_USER, path) == ERROR_SUCCESS) 111 | { 112 | DWORD data{}; 113 | if (key.QueryDWORDValue(item_name, data) == ERROR_SUCCESS) 114 | return data; 115 | } 116 | return 0; 117 | 118 | } 119 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorFixer.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {b2dadb00-105c-4da4-8037-2e8e305700f7} 18 | 19 | 20 | {fcc2cf4f-4e3a-43e5-b5de-8fc074bd53ef} 21 | 22 | 23 | {e4ff66ed-5424-47b6-abe3-5d050e978e33} 24 | 25 | 26 | {d37996ae-2b5d-4c63-8638-a90256031299} 27 | 28 | 29 | {352fa9aa-01fe-4430-a9cc-b969ccf6f829} 30 | 31 | 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 头文件 41 | 42 | 43 | 头文件 44 | 45 | 46 | 头文件 47 | 48 | 49 | 公共的类\Common 50 | 51 | 52 | 公共的类\ColorConvert 53 | 54 | 55 | 公共的类\WindowsThemeColorApi 56 | 57 | 58 | 公共的类\DwmColorLibrary 59 | 60 | 61 | 62 | 63 | 源文件 64 | 65 | 66 | 源文件 67 | 68 | 69 | 源文件 70 | 71 | 72 | 公共的类\Common 73 | 74 | 75 | 公共的类\ColorConvert 76 | 77 | 78 | 公共的类\WindowsThemeColorApi 79 | 80 | 81 | 公共的类\DwmColorLibrary 82 | 83 | 84 | 85 | 86 | 资源文件 87 | 88 | 89 | 90 | 91 | 资源文件 92 | 93 | 94 | 95 | 96 | 资源文件 97 | 98 | 99 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorFixer.cpp: -------------------------------------------------------------------------------- 1 | 2 | // WindowsThemeColorFixer.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "WindowsThemeColorFixer.h" 7 | #include "WindowsThemeColorFixerDlg.h" 8 | #include "WindowsThemeColorApi.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CWindowsThemeColorFixerApp 16 | 17 | BEGIN_MESSAGE_MAP(CWindowsThemeColorFixerApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CWindowsThemeColorFixerApp 构造 23 | 24 | CWindowsThemeColorFixerApp::CWindowsThemeColorFixerApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CWindowsThemeColorFixerApp 对象 35 | 36 | CWindowsThemeColorFixerApp theApp; 37 | 38 | 39 | // CWindowsThemeColorFixerApp 初始化 40 | 41 | BOOL CWindowsThemeColorFixerApp::InitInstance() 42 | { 43 | #ifndef _DEBUG 44 | //检查是否已有实例正在运行 45 | HANDLE hMutex = ::CreateMutex(NULL, TRUE, _T("WindowsThemeColorFixer-LXyKFwXObQB7iCQJ")); 46 | if (hMutex != NULL) 47 | { 48 | if (GetLastError() == ERROR_ALREADY_EXISTS) 49 | { 50 | SHMessageBoxCheck(NULL, _T("已经有一个程序正在运行!"), NULL, MB_OK | MB_ICONWARNING, IDOK, _T("dznkvc7u3iaw7yanrmf9rxks8kufzlwr")); 51 | return FALSE; 52 | } 53 | } 54 | #endif 55 | 56 | 57 | wchar_t path[MAX_PATH]; 58 | GetModuleFileNameW(NULL, path, MAX_PATH); 59 | m_module_path = path; 60 | if (m_module_path.find(L' ') != std::wstring::npos) 61 | { 62 | //如果路径中有空格,则在程序路径前后添加双引号 63 | m_module_path_reg = L'\"'; 64 | m_module_path_reg += m_module_path; 65 | m_module_path_reg += L'\"'; 66 | } 67 | else 68 | { 69 | m_module_path_reg = m_module_path; 70 | } 71 | 72 | WindowsThemeColorApi::InitWindowsThemeColorApi(); 73 | 74 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 75 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 76 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 77 | INITCOMMONCONTROLSEX InitCtrls; 78 | InitCtrls.dwSize = sizeof(InitCtrls); 79 | // 将它设置为包括所有要在应用程序中使用的 80 | // 公共控件类。 81 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 82 | InitCommonControlsEx(&InitCtrls); 83 | 84 | CWinApp::InitInstance(); 85 | 86 | 87 | AfxEnableControlContainer(); 88 | 89 | // 创建 shell 管理器,以防对话框包含 90 | // 任何 shell 树视图控件或 shell 列表视图控件。 91 | CShellManager *pShellManager = new CShellManager; 92 | 93 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 94 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 95 | 96 | // 标准初始化 97 | // 如果未使用这些功能并希望减小 98 | // 最终可执行文件的大小,则应移除下列 99 | // 不需要的特定初始化例程 100 | // 更改用于存储设置的注册表项 101 | // TODO: 应适当修改该字符串, 102 | // 例如修改为公司或组织名 103 | SetRegistryKey(_T("Apps By ZhongYang")); 104 | 105 | CWindowsThemeColorFixerDlg dlg; 106 | m_pMainWnd = &dlg; 107 | INT_PTR nResponse = dlg.DoModal(); 108 | if (nResponse == IDOK) 109 | { 110 | // TODO: 在此放置处理何时用 111 | // “确定”来关闭对话框的代码 112 | } 113 | else if (nResponse == IDCANCEL) 114 | { 115 | // TODO: 在此放置处理何时用 116 | // “取消”来关闭对话框的代码 117 | } 118 | else if (nResponse == -1) 119 | { 120 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 121 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 122 | } 123 | 124 | // 删除上面创建的 shell 管理器。 125 | if (pShellManager != nullptr) 126 | { 127 | delete pShellManager; 128 | } 129 | 130 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 131 | ControlBarCleanUp(); 132 | #endif 133 | 134 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 135 | // 而不是启动应用程序的消息泵。 136 | return FALSE; 137 | } 138 | 139 | 140 | void CWindowsThemeColorFixerApp::SetAutoRun(bool auto_run) 141 | { 142 | CRegKey key; 143 | //打开注册表项 144 | if (key.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run")) != ERROR_SUCCESS) 145 | { 146 | return; 147 | } 148 | if (auto_run) //写入注册表项 149 | { 150 | if (key.SetStringValue(APP_NAME, m_module_path_reg.c_str()) != ERROR_SUCCESS) 151 | { 152 | return; 153 | } 154 | } 155 | else //删除注册表项 156 | { 157 | //删除前先检查注册表项是否存在,如果不存在,则直接返回 158 | wchar_t buff[256]; 159 | ULONG size{ 256 }; 160 | if (key.QueryStringValue(APP_NAME, buff, &size) != ERROR_SUCCESS) 161 | return; 162 | if (key.DeleteValue(APP_NAME) != ERROR_SUCCESS) 163 | { 164 | return; 165 | } 166 | } 167 | } 168 | 169 | bool CWindowsThemeColorFixerApp::GetAutoRun() 170 | { 171 | CRegKey key; 172 | if (key.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run")) != ERROR_SUCCESS) 173 | { 174 | //打开注册表“Software\\Microsoft\\Windows\\CurrentVersion\\Run”失败,则返回false 175 | return false; 176 | } 177 | wchar_t buff[256]; 178 | ULONG size{ 256 }; 179 | if (key.QueryStringValue(APP_NAME, buff, &size) == ERROR_SUCCESS) //如果找到了APP_NAME键 180 | { 181 | return (m_module_path_reg == buff); //如果APP_NAME的值是当前程序的路径,就返回true,否则返回false 182 | } 183 | else 184 | { 185 | return false; //没有找到APP_NAME键,返回false 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorApi.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "WindowsThemeColorApi.h" 3 | 4 | namespace WindowsThemeColorApi 5 | { 6 | static HRESULT(WINAPI *DwmGetColorizationParameters)(DWMCOLORIZATIONPARAMS *color); 7 | static HRESULT(WINAPI *DwmSetColorizationParameters)(DWMCOLORIZATIONPARAMS *color, UINT unknown); 8 | 9 | static HRESULT(WINAPI *GetUserColorPreference)(IMMERSIVE_COLOR_PREFERENCE *pcpPreference, bool fForceReload); 10 | static HRESULT(WINAPI *SetUserColorPreference)(const IMMERSIVE_COLOR_PREFERENCE *cpcpPreference, bool fForceCommit); 11 | 12 | static const COLORREF predefinedColors[] = { 13 | 0x0000B9FF, 0x005648E7, 0x00D77800, 0x00BC9900, 14 | 0x0074757A, 0x00767676, 0x00008CFF, 0x002311E8, 15 | 0x00B16300, 0x009A7D2D, 0x00585A5D, 0x00484A4C, 16 | 0x000C63F7, 0x005E00EA, 0x00D88C8E, 0x00C3B700, 17 | 0x008A7668, 0x007E7969, 0x001050CA, 0x005200C3, 18 | 0x00D6696B, 0x00878303, 0x006B5C51, 0x0059544A, 19 | 0x00013BDA, 0x008C00E3, 0x00B86487, 0x0094B200, 20 | 0x00737C56, 0x00647C64, 0x005069EF, 0x007700BF, 21 | 0x00A94D74, 0x00748501, 0x00606848, 0x00545E52, 22 | 0x003834D1, 0x00B339C2, 0x00C246B1, 0x006ACC00, 23 | 0x00058249, 0x00457584, 0x004343FF, 0x0089009A, 24 | 0x00981788, 0x003E8910, 0x00107C10, 0x005F737E, 25 | }; 26 | 27 | void InitWindowsThemeColorApi() 28 | { 29 | HMODULE hDwmApi = LoadLibrary(L"dwmapi.dll"); 30 | ATLENSURE_THROW(hDwmApi, AtlHresultFromLastError()); 31 | 32 | DwmGetColorizationParameters = reinterpret_cast(GetProcAddress(hDwmApi, (LPCSTR)127)); 33 | ATLENSURE_THROW(DwmGetColorizationParameters, AtlHresultFromLastError()); 34 | 35 | DwmSetColorizationParameters = reinterpret_cast(GetProcAddress(hDwmApi, (LPCSTR)131)); 36 | ATLENSURE_THROW(DwmSetColorizationParameters, AtlHresultFromLastError()); 37 | 38 | HMODULE hUxTheme = LoadLibrary(L"uxtheme.dll"); 39 | ATLENSURE_THROW(hUxTheme, AtlHresultFromLastError()); 40 | 41 | GetUserColorPreference = reinterpret_cast(GetProcAddress(hUxTheme, "GetUserColorPreference")); 42 | ATLENSURE_THROW(GetUserColorPreference, AtlHresultFromLastError()); 43 | 44 | SetUserColorPreference = reinterpret_cast(GetProcAddress(hUxTheme, (LPCSTR)122)); 45 | ATLENSURE_THROW(SetUserColorPreference, AtlHresultFromLastError()); 46 | } 47 | 48 | COLORREF GetDwmColorizationColor() 49 | { 50 | HRESULT hr; 51 | 52 | DWMCOLORIZATIONPARAMS dwmColor; 53 | hr = DwmGetColorizationParameters(&dwmColor); 54 | ATLENSURE_SUCCEEDED(hr); 55 | 56 | COLORREF retReversed = dwmColor.dwColor & 0x00FFFFFF; 57 | return RGB(GetBValue(retReversed), GetGValue(retReversed), GetRValue(retReversed)); 58 | } 59 | 60 | void SetDwmColorizationColor(COLORREF color) 61 | { 62 | HRESULT hr; 63 | 64 | DWMCOLORIZATIONPARAMS dwmColor; 65 | hr = DwmGetColorizationParameters(&dwmColor); 66 | ATLENSURE_SUCCEEDED(hr); 67 | 68 | DWORD dwNewColor = (((0xC4) << 24) | ((GetRValue(color)) << 16) | ((GetGValue(color)) << 8) | (GetBValue(color))); 69 | dwmColor.dwColor = dwNewColor; 70 | dwmColor.dwAfterglow = dwNewColor; 71 | 72 | hr = DwmSetColorizationParameters(&dwmColor, 0); 73 | ATLENSURE_SUCCEEDED(hr); 74 | } 75 | 76 | COLORREF GetAccentColor() 77 | { 78 | HRESULT hr; 79 | 80 | IMMERSIVE_COLOR_PREFERENCE immersiveColorPref; 81 | hr = GetUserColorPreference(&immersiveColorPref, 0); 82 | ATLENSURE_SUCCEEDED(hr); 83 | 84 | return immersiveColorPref.color2 & 0x00FFFFFF; 85 | } 86 | 87 | void SetAccentColor(COLORREF color, bool newAccentAlgorithmWorkaround) 88 | { 89 | HRESULT hr; 90 | 91 | IMMERSIVE_COLOR_PREFERENCE immersiveColorPref; 92 | hr = GetUserColorPreference(&immersiveColorPref, 0); 93 | ATLENSURE_SUCCEEDED(hr); 94 | 95 | color &= 0x00FFFFFF; 96 | 97 | if(newAccentAlgorithmWorkaround) 98 | { 99 | // This is a hack to make NewAutoColorAccentAlgorithm actually work: 100 | // if the color is one of the predefined colors, change it slightly. 101 | 102 | for(int i = 0; i < _countof(predefinedColors); i++) 103 | { 104 | if(color == predefinedColors[i]) 105 | { 106 | color = RGB(GetRValue(color), GetGValue(color), GetBValue(color) + 1); 107 | break; 108 | } 109 | } 110 | } 111 | 112 | immersiveColorPref.color2 = color; 113 | 114 | hr = SetUserColorPreference(&immersiveColorPref, 1); 115 | ATLENSURE_SUCCEEDED(hr); 116 | } 117 | 118 | bool IsNewAutoColorAccentAlgorithm() 119 | { 120 | DWORD dwError; 121 | 122 | CRegKey key; 123 | dwError = key.Open(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", KEY_READ); 124 | if(dwError == ERROR_FILE_NOT_FOUND || dwError == ERROR_PATH_NOT_FOUND) 125 | { 126 | return true; 127 | } 128 | 129 | ATLENSURE_SUCCEEDED(AtlHresultFromWin32(dwError)); 130 | 131 | DWORD dw; 132 | dwError = key.QueryDWORDValue(L"UseNewAutoColorAccentAlgorithm", dw); 133 | if(dwError == ERROR_FILE_NOT_FOUND || dwError == ERROR_PATH_NOT_FOUND) 134 | { 135 | return true; 136 | } 137 | 138 | ATLENSURE_SUCCEEDED(AtlHresultFromWin32(dwError)); 139 | 140 | bool newAutoColorAccentAlgorithm = dw != 0; 141 | 142 | if(!newAutoColorAccentAlgorithm) 143 | { 144 | // For predefined colors, the new algorithm is always used. 145 | 146 | COLORREF accentColor = GetAccentColor(); 147 | 148 | for(int i = 0; i < _countof(predefinedColors); i++) 149 | { 150 | if(accentColor == predefinedColors[i]) 151 | { 152 | newAutoColorAccentAlgorithm = true; 153 | break; 154 | } 155 | } 156 | } 157 | 158 | return newAutoColorAccentAlgorithm; 159 | } 160 | 161 | void SetAutoColorAccentAlgorithm(bool bNewAlgorithm) 162 | { 163 | DWORD dwError; 164 | 165 | CRegKey key; 166 | dwError = key.Create(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent"); 167 | ATLENSURE_SUCCEEDED(AtlHresultFromWin32(dwError)); 168 | 169 | if(bNewAlgorithm) 170 | { 171 | dwError = key.DeleteValue(L"UseNewAutoColorAccentAlgorithm"); 172 | if(dwError != ERROR_FILE_NOT_FOUND && dwError != ERROR_PATH_NOT_FOUND) 173 | { 174 | ATLENSURE_SUCCEEDED(AtlHresultFromWin32(dwError)); 175 | } 176 | } 177 | else 178 | { 179 | dwError = key.SetDWORDValue(L"UseNewAutoColorAccentAlgorithm", 0); 180 | ATLENSURE_SUCCEEDED(AtlHresultFromWin32(dwError)); 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorFixer.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {EEF8B6AD-1F11-410C-8754-3AC79BCC61EA} 24 | MFCProj 25 | WindowsThemeColorFixer 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | Dynamic 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | Dynamic 43 | 44 | 45 | Application 46 | true 47 | v143 48 | Unicode 49 | Dynamic 50 | 51 | 52 | Application 53 | false 54 | v143 55 | true 56 | Unicode 57 | Dynamic 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | true 79 | 80 | 81 | true 82 | 83 | 84 | false 85 | 86 | 87 | false 88 | 89 | 90 | 91 | Use 92 | Level3 93 | Disabled 94 | true 95 | WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) 96 | 97 | 98 | Windows 99 | 100 | 101 | false 102 | true 103 | _DEBUG;%(PreprocessorDefinitions) 104 | 105 | 106 | 0x0804 107 | _DEBUG;%(PreprocessorDefinitions) 108 | $(IntDir);%(AdditionalIncludeDirectories) 109 | 110 | 111 | 112 | 113 | Use 114 | Level3 115 | Disabled 116 | true 117 | _WINDOWS;_DEBUG;%(PreprocessorDefinitions) 118 | 119 | 120 | Windows 121 | 122 | 123 | false 124 | true 125 | _DEBUG;%(PreprocessorDefinitions) 126 | 127 | 128 | 0x0804 129 | _DEBUG;%(PreprocessorDefinitions) 130 | $(IntDir);%(AdditionalIncludeDirectories) 131 | 132 | 133 | 134 | 135 | Use 136 | Level3 137 | MaxSpeed 138 | true 139 | true 140 | true 141 | WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) 142 | 143 | 144 | Windows 145 | true 146 | true 147 | 148 | 149 | false 150 | true 151 | NDEBUG;%(PreprocessorDefinitions) 152 | 153 | 154 | 0x0804 155 | NDEBUG;%(PreprocessorDefinitions) 156 | $(IntDir);%(AdditionalIncludeDirectories) 157 | 158 | 159 | 160 | 161 | Use 162 | Level3 163 | MaxSpeed 164 | true 165 | true 166 | true 167 | _WINDOWS;NDEBUG;%(PreprocessorDefinitions) 168 | 169 | 170 | Windows 171 | true 172 | true 173 | 174 | 175 | false 176 | true 177 | NDEBUG;%(PreprocessorDefinitions) 178 | 179 | 180 | 0x0804 181 | NDEBUG;%(PreprocessorDefinitions) 182 | $(IntDir);%(AdditionalIncludeDirectories) 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | Create 202 | Create 203 | Create 204 | Create 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /WindowsThemeColorFixer/WindowsThemeColorFixerDlg.cpp: -------------------------------------------------------------------------------- 1 | 2 | // WindowsThemeColorFixerDlg.cpp: 实现文件 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "WindowsThemeColorFixer.h" 7 | #include "WindowsThemeColorFixerDlg.h" 8 | #include "afxdialogex.h" 9 | #include "Common.h" 10 | #include "ColorConvert.h" 11 | #include 12 | #include "WindowsThemeColorApi.h" 13 | 14 | #ifdef _DEBUG 15 | #define new DEBUG_NEW 16 | #endif 17 | 18 | 19 | // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 20 | 21 | class CAboutDlg : public CDialogEx 22 | { 23 | public: 24 | CAboutDlg(); 25 | 26 | // 对话框数据 27 | #ifdef AFX_DESIGN_TIME 28 | enum { IDD = IDD_ABOUTBOX }; 29 | #endif 30 | 31 | protected: 32 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 33 | 34 | // 实现 35 | protected: 36 | DECLARE_MESSAGE_MAP() 37 | public: 38 | virtual BOOL OnInitDialog(); 39 | }; 40 | 41 | CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) 42 | { 43 | } 44 | 45 | void CAboutDlg::DoDataExchange(CDataExchange* pDX) 46 | { 47 | CDialogEx::DoDataExchange(pDX); 48 | } 49 | 50 | BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) 51 | END_MESSAGE_MAP() 52 | 53 | BOOL CAboutDlg::OnInitDialog() 54 | { 55 | CDialogEx::OnInitDialog(); 56 | 57 | // TODO: 在此添加额外的初始化 58 | CString version_info; 59 | GetDlgItemText(IDC_STATIC_VERSION, version_info); 60 | version_info.Replace(_T(""), VERSION); 61 | #ifdef _M_X64 62 | version_info += _T(" (x64)"); 63 | #endif 64 | 65 | #ifdef _DEBUG 66 | version_info += _T(" (Debug)"); 67 | #endif 68 | 69 | SetDlgItemText(IDC_STATIC_VERSION, version_info); 70 | 71 | //设置最后编译日期 72 | CString temp_str; 73 | GetDlgItemText(IDC_STATIC_COPYRIGHT, temp_str); 74 | temp_str.Replace(_T(""), COMPILE_DATE); 75 | CString year{ COMPILE_DATE }; 76 | year = year.Left(4); 77 | temp_str.Replace(_T(""), year); 78 | SetDlgItemText(IDC_STATIC_COPYRIGHT, temp_str); 79 | 80 | return TRUE; // return TRUE unless you set the focus to a control 81 | // 异常: OCX 属性页应返回 FALSE 82 | } 83 | 84 | 85 | // CWindowsThemeColorFixerDlg 对话框 86 | 87 | const UINT WM_TASKBARCREATED{ ::RegisterWindowMessage(_T("TaskbarCreated")) }; //注册任务栏建立的消息 88 | 89 | CWindowsThemeColorFixerDlg::CWindowsThemeColorFixerDlg(CWnd* pParent /*=nullptr*/) 90 | : CDialog(IDD_WINDOWSTHEMECOLORFIXER_DIALOG, pParent) 91 | { 92 | m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 93 | } 94 | 95 | void CWindowsThemeColorFixerDlg::DoDataExchange(CDataExchange* pDX) 96 | { 97 | CDialog::DoDataExchange(pDX); 98 | } 99 | 100 | BEGIN_MESSAGE_MAP(CWindowsThemeColorFixerDlg, CDialog) 101 | ON_WM_SYSCOMMAND() 102 | ON_WM_PAINT() 103 | ON_WM_QUERYDRAGICON() 104 | ON_BN_CLICKED(IDC_REDUCE_COLOR_CHECK, &CWindowsThemeColorFixerDlg::OnBnClickedReduceColorCheck) 105 | ON_WM_TIMER() 106 | ON_BN_CLICKED(IDC_BUTTON1, &CWindowsThemeColorFixerDlg::OnBnClickedButton1) 107 | //ON_BN_CLICKED(IDC_BUTTON2, &CWindowsThemeColorFixerDlg::OnBnClickedButton2) 108 | ON_BN_CLICKED(IDC_ADJUST_COLOR_BUTTON, &CWindowsThemeColorFixerDlg::OnBnClickedAdjustColorButton) 109 | ON_COMMAND(ID_SETTINGS, &CWindowsThemeColorFixerDlg::OnSettings) 110 | ON_MESSAGE(WM_NOTIFYICON, &CWindowsThemeColorFixerDlg::OnNotifyicon) 111 | ON_COMMAND(ID_APP_ABOUT, &CWindowsThemeColorFixerDlg::OnAppAbout) 112 | ON_WM_CLOSE() 113 | ON_COMMAND(ID_MENU_EXIT, &CWindowsThemeColorFixerDlg::OnMenuExit) 114 | ON_WM_DESTROY() 115 | ON_REGISTERED_MESSAGE(WM_TASKBARCREATED, &CWindowsThemeColorFixerDlg::OnTaskbarcreated) 116 | ON_WM_DWMCOLORIZATIONCOLORCHANGED() 117 | ON_BN_CLICKED(IDC_HIDE_MAIN_WINDOW_CHECK, &CWindowsThemeColorFixerDlg::OnBnClickedHideMainWindowCheck) 118 | ON_WM_QUERYENDSESSION() 119 | ON_BN_CLICKED(IDC_AUTO_RUN_CHECK, &CWindowsThemeColorFixerDlg::OnBnClickedAutoRunCheck) 120 | ON_BN_CLICKED(IDC_ADJUST_ONLY_LIGHT_MODE_CHECK, &CWindowsThemeColorFixerDlg::OnBnClickedAdjustOnlyLightModeCheck) 121 | ON_BN_CLICKED(IDC_ENHANCED_CHECK, &CWindowsThemeColorFixerDlg::OnBnClickedEnhancedCheck) 122 | END_MESSAGE_MAP() 123 | 124 | 125 | // CWindowsThemeColorFixerDlg 消息处理程序 126 | 127 | void CWindowsThemeColorFixerDlg::LoadConfig() 128 | { 129 | m_auto_adjust_color = (theApp.GetProfileInt(_T("config"), _T("auto_adjust_color"), 1) != 0); 130 | m_hide_main_window_when_start = (theApp.GetProfileInt(_T("config"), _T("hide_main_window_when_start"), 0) != 0); 131 | m_adjust_only_light_mode = (theApp.GetProfileInt(_T("config"), _T("adjust_only_light_mode"), 0) != 0); 132 | m_enhanced_mode = (theApp.GetProfileInt(_T("config"), _T("enhanced_mode"), 1) != 0); 133 | } 134 | 135 | void CWindowsThemeColorFixerDlg::SaveConfig() const 136 | { 137 | theApp.WriteProfileInt(L"config", L"auto_adjust_color", m_auto_adjust_color); 138 | theApp.WriteProfileInt(L"config", L"hide_main_window_when_start", m_hide_main_window_when_start); 139 | theApp.WriteProfileInt(L"config", L"adjust_only_light_mode", m_adjust_only_light_mode); 140 | theApp.WriteProfileInt(L"config", L"enhanced_mode", m_enhanced_mode); 141 | } 142 | 143 | void CWindowsThemeColorFixerDlg::SetOpaque(int opaque) 144 | { 145 | SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); 146 | SetLayeredWindowAttributes(0, opaque * 255 / 100, LWA_ALPHA); //透明度取值范围为0~255 147 | } 148 | 149 | COLORREF CWindowsThemeColorFixerDlg::GetThemeColor() 150 | { 151 | COLORREF color{}; 152 | if (m_enhanced_mode) 153 | color = WindowsThemeColorApi::GetAccentColor(); 154 | else 155 | color = m_dwm_lib.GetWindowsThemeColor(); 156 | return color; 157 | } 158 | 159 | void CWindowsThemeColorFixerDlg::SetThemeColor(COLORREF color) 160 | { 161 | if (m_enhanced_mode) 162 | { 163 | WindowsThemeColorApi::SetAccentColor(color); 164 | } 165 | else 166 | { 167 | m_dwm_lib.SetWindowsThemeColor(color); 168 | CCommon::SetWindowsThemeColor(color); 169 | } 170 | 171 | //显示设置主题颜色的次数 172 | m_color_adjust_count++; 173 | SetDlgItemText(IDC_COUNT_STATIC, std::to_wstring(m_color_adjust_count).c_str()); 174 | } 175 | 176 | void CWindowsThemeColorFixerDlg::DoAdjustThemeColor() 177 | { 178 | if (m_auto_adjust_color) 179 | { 180 | if (m_adjust_only_light_mode && !CCommon::IsAppLightTheme()) 181 | return; 182 | 183 | COLORREF color = GetThemeColor(); 184 | if (CColorConvert::IncreaseLuminance(color)) 185 | { 186 | static COLORREF last_adjust_color; 187 | if (!CCommon::IsColorSimilar(last_adjust_color, color)) 188 | SetThemeColor(color); 189 | last_adjust_color = color; 190 | } 191 | } 192 | } 193 | 194 | UINT CWindowsThemeColorFixerDlg::AdjustThemeColorThreadCallback(LPVOID dwUser) 195 | { 196 | CWindowsThemeColorFixerDlg* pThis = (CWindowsThemeColorFixerDlg*)dwUser; 197 | while (true) 198 | { 199 | if (pThis->m_adjust_color_required) 200 | { 201 | Sleep(5000); //先延迟一段时间 202 | pThis->DoAdjustThemeColor(); 203 | pThis->m_adjust_color_required = false; 204 | } 205 | else 206 | { 207 | Sleep(1000); 208 | } 209 | } 210 | return 0; 211 | } 212 | 213 | BOOL CWindowsThemeColorFixerDlg::OnInitDialog() 214 | { 215 | CDialog::OnInitDialog(); 216 | 217 | // 将“关于...”菜单项添加到系统菜单中。 218 | 219 | // IDM_ABOUTBOX 必须在系统命令范围内。 220 | ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 221 | ASSERT(IDM_ABOUTBOX < 0xF000); 222 | 223 | CMenu* pSysMenu = GetSystemMenu(FALSE); 224 | if (pSysMenu != nullptr) 225 | { 226 | BOOL bNameValid; 227 | CString strAboutMenu; 228 | bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); 229 | ASSERT(bNameValid); 230 | if (!strAboutMenu.IsEmpty()) 231 | { 232 | pSysMenu->AppendMenu(MF_SEPARATOR); 233 | pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 234 | } 235 | } 236 | 237 | // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动 238 | // 执行此操作 239 | SetIcon(m_hIcon, TRUE); // 设置大图标 240 | SetIcon(m_hIcon, FALSE); // 设置小图标 241 | 242 | // TODO: 在此添加额外的初始化代码 243 | 244 | LoadConfig(); 245 | 246 | //初始化控件 247 | ((CButton*)GetDlgItem(IDC_REDUCE_COLOR_CHECK))->SetCheck(m_auto_adjust_color); 248 | ((CButton*)GetDlgItem(IDC_HIDE_MAIN_WINDOW_CHECK))->SetCheck(m_hide_main_window_when_start); 249 | ((CButton*)GetDlgItem(IDC_AUTO_RUN_CHECK))->SetCheck(theApp.GetAutoRun()); 250 | CheckDlgButton(IDC_ADJUST_ONLY_LIGHT_MODE_CHECK, m_adjust_only_light_mode); 251 | CheckDlgButton(IDC_ENHANCED_CHECK, m_enhanced_mode); 252 | 253 | m_menu.LoadMenu(IDR_MENU1); 254 | 255 | SetTimer(TIMER_ID, 1000, NULL); 256 | 257 | m_ntIcon.cbSize = sizeof(NOTIFYICONDATA); //该结构体变量的大小 258 | m_ntIcon.hIcon = m_hIcon; 259 | m_ntIcon.hWnd = m_hWnd; //接收托盘图标通知消息的窗口句柄 260 | CString atip{ APP_NAME }; //鼠标指向图标时显示的提示 261 | #ifdef _DEBUG 262 | atip += _T(" (Debug)"); 263 | #endif 264 | StringCchCopy(m_ntIcon.szTip, 128, atip.GetString()); 265 | m_ntIcon.uCallbackMessage = WM_NOTIFYICON; //应用程序定义的消息ID号 266 | m_ntIcon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; //图标的属性:设置成员uCallbackMessage、hIcon、szTip有效 267 | ::Shell_NotifyIcon(NIM_ADD, &m_ntIcon); //在系统通知区域增加这个图标 268 | 269 | m_adjust_color_required = true; 270 | AfxBeginThread(AdjustThemeColorThreadCallback, (LPVOID)this); 271 | 272 | if (m_hide_main_window_when_start) 273 | SetOpaque(0); 274 | 275 | return TRUE; // 除非将焦点设置到控件,否则返回 TRUE 276 | } 277 | 278 | void CWindowsThemeColorFixerDlg::OnSysCommand(UINT nID, LPARAM lParam) 279 | { 280 | if ((nID & 0xFFF0) == IDM_ABOUTBOX) 281 | { 282 | CAboutDlg dlgAbout; 283 | dlgAbout.DoModal(); 284 | } 285 | else 286 | { 287 | CDialog::OnSysCommand(nID, lParam); 288 | } 289 | } 290 | 291 | // 如果向对话框添加最小化按钮,则需要下面的代码 292 | // 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序, 293 | // 这将由框架自动完成。 294 | 295 | void CWindowsThemeColorFixerDlg::OnPaint() 296 | { 297 | if (IsIconic()) 298 | { 299 | CPaintDC dc(this); // 用于绘制的设备上下文 300 | 301 | SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); 302 | 303 | // 使图标在工作区矩形中居中 304 | int cxIcon = GetSystemMetrics(SM_CXICON); 305 | int cyIcon = GetSystemMetrics(SM_CYICON); 306 | CRect rect; 307 | GetClientRect(&rect); 308 | int x = (rect.Width() - cxIcon + 1) / 2; 309 | int y = (rect.Height() - cyIcon + 1) / 2; 310 | 311 | // 绘制图标 312 | dc.DrawIcon(x, y, m_hIcon); 313 | } 314 | else 315 | { 316 | CDialog::OnPaint(); 317 | } 318 | } 319 | 320 | //当用户拖动最小化窗口时系统调用此函数取得光标 321 | //显示。 322 | HCURSOR CWindowsThemeColorFixerDlg::OnQueryDragIcon() 323 | { 324 | return static_cast(m_hIcon); 325 | } 326 | 327 | 328 | 329 | void CWindowsThemeColorFixerDlg::OnBnClickedReduceColorCheck() 330 | { 331 | // TODO: 在此添加控件通知处理程序代码 332 | m_auto_adjust_color = (((CButton*)GetDlgItem(IDC_REDUCE_COLOR_CHECK))->GetCheck() != 0); 333 | } 334 | 335 | 336 | void CWindowsThemeColorFixerDlg::OnTimer(UINT_PTR nIDEvent) 337 | { 338 | // TODO: 在此添加消息处理程序代码和/或调用默认值 339 | if (nIDEvent == TIMER_ID) 340 | { 341 | if (m_first_start) 342 | { 343 | m_first_start = false; 344 | if (m_hide_main_window_when_start) //设置隐藏主窗口 345 | ShowWindow(SW_HIDE); 346 | SetOpaque(100); //重新设置窗口不透明度 347 | } 348 | if (m_auto_adjust_color) 349 | { 350 | //AdjustWindowsThemeColor(); 351 | } 352 | } 353 | 354 | CDialog::OnTimer(nIDEvent); 355 | } 356 | 357 | 358 | void CWindowsThemeColorFixerDlg::OnBnClickedButton1() 359 | { 360 | // TODO: 在此添加控件通知处理程序代码 361 | //bool is_auto_color = CCommon::IsAutoColor(); 362 | 363 | //重置调整主题颜色次数 364 | m_color_adjust_count = 0; 365 | SetDlgItemText(IDC_COUNT_STATIC, std::to_wstring(m_color_adjust_count).c_str()); 366 | } 367 | 368 | 369 | //void CWindowsThemeColorFixerDlg::OnBnClickedButton2() 370 | //{ 371 | // // TODO: 在此添加控件通知处理程序代码 372 | // COLORREF color{ RGB(35, 172, 57) }; 373 | // m_themeColorLib.SetWindowsThemeColor(color); 374 | // //CCommon::SetAccentColor(color); 375 | //} 376 | 377 | 378 | void CWindowsThemeColorFixerDlg::OnBnClickedAdjustColorButton() 379 | { 380 | // TODO: 在此添加控件通知处理程序代码 381 | COLORREF color = GetThemeColor(); 382 | if (CColorConvert::IncreaseLuminance(color)) 383 | { 384 | SetThemeColor(color); 385 | } 386 | } 387 | 388 | 389 | void CWindowsThemeColorFixerDlg::OnSettings() 390 | { 391 | // TODO: 在此添加命令处理程序代码 392 | ShowWindow(SW_RESTORE); 393 | SetForegroundWindow(); 394 | } 395 | 396 | 397 | afx_msg LRESULT CWindowsThemeColorFixerDlg::OnNotifyicon(WPARAM wParam, LPARAM lParam) 398 | { 399 | if (lParam == WM_RBUTTONUP) 400 | { 401 | //在通知区点击右键弹出右键菜单 402 | SetForegroundWindow(); 403 | CPoint point1; //定义一个用于确定光标位置的位置 404 | GetCursorPos(&point1); //获取当前光标的位置,以便使得菜单可以跟随光标 405 | m_menu.GetSubMenu(0)->SetDefaultItem(ID_SETTINGS, FALSE); //设置默认菜单项 406 | m_menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point1.x, point1.y, this); //在指定位置显示弹出菜单 407 | } 408 | if (lParam == WM_LBUTTONDBLCLK) 409 | { 410 | ShowWindow(SW_RESTORE); 411 | SetForegroundWindow(); 412 | } 413 | return 0; 414 | } 415 | 416 | 417 | void CWindowsThemeColorFixerDlg::OnAppAbout() 418 | { 419 | // TODO: 在此添加命令处理程序代码 420 | CAboutDlg dlg; 421 | dlg.DoModal(); 422 | } 423 | 424 | 425 | void CWindowsThemeColorFixerDlg::OnClose() 426 | { 427 | // TODO: 在此添加消息处理程序代码和/或调用默认值 428 | 429 | ShowWindow(HIDE_WINDOW); 430 | //CDialog::OnClose(); 431 | } 432 | 433 | 434 | void CWindowsThemeColorFixerDlg::OnMenuExit() 435 | { 436 | // TODO: 在此添加命令处理程序代码 437 | OnCancel(); 438 | } 439 | 440 | 441 | void CWindowsThemeColorFixerDlg::OnDestroy() 442 | { 443 | CDialog::OnDestroy(); 444 | 445 | //程序退出时删除通知栏图标 446 | ::Shell_NotifyIcon(NIM_DELETE, &m_ntIcon); 447 | 448 | SaveConfig(); 449 | } 450 | 451 | 452 | afx_msg LRESULT CWindowsThemeColorFixerDlg::OnTaskbarcreated(WPARAM wParam, LPARAM lParam) 453 | { 454 | //重新添加通知栏图标 455 | ::Shell_NotifyIcon(NIM_ADD, &m_ntIcon); 456 | return 0; 457 | } 458 | 459 | 460 | void CWindowsThemeColorFixerDlg::OnColorizationColorChanged(DWORD dwColorizationColor, BOOL bOpacity) 461 | { 462 | // 此功能要求 Windows Vista 或更高版本。 463 | // _WIN32_WINNT 符号必须 >= 0x0600。 464 | // TODO: 在此添加消息处理程序代码和/或调用默认值 465 | static DWORD last_color{}; 466 | static DWORD last_last_color{}; 467 | if (!CCommon::IsColorSimilar(last_color, dwColorizationColor) && !CCommon::IsColorSimilar(last_last_color, dwColorizationColor)) 468 | { 469 | m_adjust_color_required = true; 470 | } 471 | last_last_color = last_color; 472 | last_color = dwColorizationColor; 473 | 474 | CDialog::OnColorizationColorChanged(dwColorizationColor, bOpacity); 475 | } 476 | 477 | 478 | void CWindowsThemeColorFixerDlg::OnBnClickedHideMainWindowCheck() 479 | { 480 | // TODO: 在此添加控件通知处理程序代码 481 | m_hide_main_window_when_start = (((CButton*)GetDlgItem(IDC_HIDE_MAIN_WINDOW_CHECK))->GetCheck() != 0); 482 | } 483 | 484 | 485 | BOOL CWindowsThemeColorFixerDlg::OnQueryEndSession() 486 | { 487 | if (!CDialog::OnQueryEndSession()) 488 | return FALSE; 489 | 490 | // TODO: 在此添加专用的查询结束会话代码 491 | SaveConfig(); 492 | 493 | return TRUE; 494 | } 495 | 496 | 497 | void CWindowsThemeColorFixerDlg::OnBnClickedAutoRunCheck() 498 | { 499 | // TODO: 在此添加控件通知处理程序代码 500 | bool auto_run = (((CButton*)GetDlgItem(IDC_AUTO_RUN_CHECK))->GetCheck() != 0); 501 | theApp.SetAutoRun(auto_run); 502 | } 503 | 504 | 505 | void CWindowsThemeColorFixerDlg::OnBnClickedAdjustOnlyLightModeCheck() 506 | { 507 | // TODO: 在此添加控件通知处理程序代码 508 | m_adjust_only_light_mode = (IsDlgButtonChecked(IDC_ADJUST_ONLY_LIGHT_MODE_CHECK) != 0); 509 | } 510 | 511 | 512 | void CWindowsThemeColorFixerDlg::OnBnClickedEnhancedCheck() 513 | { 514 | // TODO: 在此添加控件通知处理程序代码 515 | m_enhanced_mode = (IsDlgButtonChecked(IDC_ENHANCED_CHECK) != 0); 516 | } 517 | --------------------------------------------------------------------------------