forked from notepad-plus-plus/nppShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadUILanguageChanger.cpp
45 lines (34 loc) · 1.45 KB
/
ThreadUILanguageChanger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "pch.h"
#include "ThreadUILanguageChanger.h"
#include "LoggingHelper.h"
using namespace NppShell::Helpers;
extern LoggingHelper g_loggingHelper;
ThreadUILanguageChanger::ThreadUILanguageChanger(const wstring& languageTag)
{
// Save the original thread UI language setting
m_originalLanguageTag = GetThreadLanguage();
// Set the new thread UI language setting
SetThreadLanguage(languageTag);
g_loggingHelper.LogMessage(L"ThreadUILanguageChanger::ctor", L"Original language: " + m_originalLanguageTag);
g_loggingHelper.LogMessage(L"ThreadUILanguageChanger::ctor", L"New language: " + languageTag);
}
ThreadUILanguageChanger::~ThreadUILanguageChanger()
{
// Restore the original thread UI language setting
SetThreadLanguage(m_originalLanguageTag);
g_loggingHelper.LogMessage(L"ThreadUILanguageChanger::~tor", L"Original language: " + m_originalLanguageTag);
}
wstring ThreadUILanguageChanger::GetThreadLanguage()
{
DWORD numLanguages = 0;
DWORD bufferSize = 0;
GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages, nullptr, &bufferSize);
wstring language(bufferSize, '\0');
GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages, language.data(), &bufferSize);
return language;
}
void ThreadUILanguageChanger::SetThreadLanguage(const wstring& languageTag)
{
// Set the new thread UI language setting
SetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, languageTag.c_str(), nullptr);
}