Jump to content

Recommended Posts

  • Active+ Member

The window title bar switches to dark when Windows is set to dark mode, and updates live when the setting is changed while the client is running.

 

Only one file to edit: EterLib/MSWindow.cpp

1. Search for:
 

CMSWindow::TWindowClassSet CMSWindow::ms_stWCSet;
HINSTANCE CMSWindow::ms_hInstance = NULL;

Add below:
 

// Windows apps-theme setting; missing value (Wine, pre-1809) means light.
static bool IsSystemDarkMode()
{
	DWORD value = 1;
	DWORD size = sizeof(value);
	if (::RegGetValueW(HKEY_CURRENT_USER,
			L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
			L"AppsUseLightTheme", RRF_RT_REG_DWORD, nullptr, &value, &size) != ERROR_SUCCESS)
		return false;

	return value == 0;
}

// dwmapi is loaded dynamically: under Wine the call just fails and the
// Linux window manager keeps drawing the frame in the desktop theme.
static void ApplySystemTitleBarTheme(HWND hWnd)
{
	using DwmSetWindowAttributeFn = HRESULT(WINAPI*)(HWND, DWORD, LPCVOID, DWORD);
	constexpr DWORD UseImmersiveDarkMode = 20;
	constexpr DWORD UseImmersiveDarkModeBefore20H1 = 19;

	static HMODULE s_dwm = ::LoadLibraryA("dwmapi.dll");
	if (!s_dwm)
		return;

	static auto s_setAttr =
		reinterpret_cast<DwmSetWindowAttributeFn>(
			::GetProcAddress(s_dwm, "DwmSetWindowAttribute"));

	if (!s_setAttr)
		return;

	BOOL dark = IsSystemDarkMode() ? TRUE : FALSE;
	if (FAILED(s_setAttr(hWnd, UseImmersiveDarkMode, &dark, sizeof(dark))))
		s_setAttr(hWnd, UseImmersiveDarkModeBefore20H1, &dark, sizeof(dark));
}

2. Search for:
 

		case WM_ACTIVATEAPP:
			m_isActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
			break;

Add below:
 

		// Sent when the user toggles light/dark mode while the client runs.
		case WM_SETTINGCHANGE:
			if (lParam && ::lstrcmpiW((LPCWSTR)lParam, L"ImmersiveColorSet") == 0)
			{
				ApplySystemTitleBarTheme(hWnd);
				::SetWindowPos(hWnd, nullptr, 0, 0, 0, 0,
					SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
			}
			break;

3. Search for (inside CMSWindow::Create):
 

	SetWindowLongPtrW(m_hWnd, GWLP_USERDATA, (LONG_PTR)this);

Add below:
 

	ApplySystemTitleBarTheme(m_hWnd);

 

  • Metin2 Dev 1
  • Good 1
  • Love 2
Link to comment
https://metin2.dev/topic/34720-client-dark-mode/
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.