diff --git a/Versions/build.txt b/Versions/build.txt
index 26144aa17..73795f7e7 100644
--- a/Versions/build.txt
+++ b/Versions/build.txt
@@ -1 +1 @@
-2665
+2666
diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf
index 68af0aec3..5a34668f3 100644
--- a/res/Notepad3.exe.manifest.conf
+++ b/res/Notepad3.exe.manifest.conf
@@ -3,7 +3,7 @@
Notepad3 BETA
diff --git a/src/Encoding.c b/src/Encoding.c
index 08dae3da3..98ba849c8 100644
--- a/src/Encoding.c
+++ b/src/Encoding.c
@@ -113,10 +113,10 @@ void Encoding_InitDefaults()
65001 // (UTF-8)
};
- UINT const ansiInputCP = GetACP();
- ChangeEncodingCodePage(CPI_ANSI_DEFAULT, ansiInputCP); // set ANSI system CP ()
- assert(g_Encodings[CPI_ANSI_DEFAULT].uCodePage == ansiInputCP);
- StringCchPrintf(wchANSI, COUNTOF(wchANSI), L" (CP-%u)", ansiInputCP);
+ UINT const ansiCP = CodePageFromCharSet(ANSI_CHARSET);
+ ChangeEncodingCodePage(CPI_ANSI_DEFAULT, ansiCP); // set ANSI system CP ()
+ assert(g_Encodings[CPI_ANSI_DEFAULT].uCodePage == ansiCP);
+ StringCchPrintf(wchANSI, COUNTOF(wchANSI), L" (CP-%u)", ansiCP);
Globals.bIsCJKInputCodePage = IsDBCSCodePage(Scintilla_InputCodePage());
diff --git a/src/Helpers.c b/src/Helpers.c
index 9a6dcbe28..a9f1a1e0b 100644
--- a/src/Helpers.c
+++ b/src/Helpers.c
@@ -1430,13 +1430,24 @@ LRESULT ComboBox_AddStringMB2W(HWND hwnd, LPCSTR lpString)
//
// CodePageFromCharSet()
//
-UINT CodePageFromCharSet(UINT uCharSet)
+UINT CodePageFromCharSet(const UINT uCharSet)
{
- CHARSETINFO ci;
- if (TranslateCharsetInfo((DWORD*)(UINT_PTR)uCharSet, &ci, TCI_SRCCHARSET)) {
- return(ci.ciACP);
+ if (ANSI_CHARSET == uCharSet) {
+ if (Globals.uConsoleCodePage != 0) {
+ return Globals.uConsoleCodePage;
+ }
+ CPINFOEX cpinfo; ZeroMemory(&cpinfo, sizeof(CPINFOEX));
+ if (GetCPInfoEx(CP_THREAD_ACP, 0, &cpinfo)) {
+ return cpinfo.CodePage;
+ }
}
- return(GetACP());
+ else {
+ CHARSETINFO ci; ZeroMemory(&ci, sizeof(CHARSETINFO));
+ if (TranslateCharsetInfo((DWORD*)(UINT_PTR)uCharSet, &ci, TCI_SRCCHARSET)) {
+ return(ci.ciACP);
+ }
+ }
+ return GetACP(); // fallback: systems locale ANSI CP
}
@@ -1444,7 +1455,7 @@ UINT CodePageFromCharSet(UINT uCharSet)
//
// CharSetFromCodePage()
//
-UINT CharSetFromCodePage(UINT uCodePage) {
+UINT CharSetFromCodePage(const UINT uCodePage) {
CHARSETINFO ci;
if (TranslateCharsetInfo((DWORD*)(UINT_PTR)uCodePage, &ci, TCI_SRCCODEPAGE)) {
return(ci.ciCharset); // corresponds to SCI: SC_CHARSET_XXX
diff --git a/src/Helpers.h b/src/Helpers.h
index 17f96fc4b..f870f98b5 100644
--- a/src/Helpers.h
+++ b/src/Helpers.h
@@ -331,8 +331,8 @@ UINT SetDlgItemTextMB2W(HWND hDlg,int nIDDlgItem,LPSTR lpString);
LRESULT ComboBox_AddStringMB2W(HWND hwnd,LPCSTR lpString);
-UINT CodePageFromCharSet(UINT uCharSet);
-UINT CharSetFromCodePage(UINT uCodePage);
+UINT CodePageFromCharSet(const UINT uCharSet);
+UINT CharSetFromCodePage(const UINT uCodePage);
//==== UnSlash Functions ======================================================
diff --git a/src/Notepad3.c b/src/Notepad3.c
index cf4fca2ba..5a1409782 100644
--- a/src/Notepad3.c
+++ b/src/Notepad3.c
@@ -1,4 +1,4 @@
-/******************************************************************************
+/******************************************************************************
* *
* *
* Notepad3 *
@@ -96,7 +96,6 @@ int s_flagShellUseSystemMRU = 0;
int s_flagPrintFileAndLeave = 0;
bool s_flagDoRelaunchElevated = false;
-
// ------------------------------------
static WCHAR s_wchWndClass[16] = _W(SAPPNAME);
@@ -629,6 +628,7 @@ static void _InitGlobals()
Globals.pMRUfind = NULL;
Globals.pMRUreplace = NULL;
Globals.CallTipType = CT_NONE;
+ Globals.uConsoleCodePage = 0;
Globals.iAvailLngCount = 1;
Globals.iWrapCol = 0;
Globals.bForceReLoadAsUTF8 = false;
@@ -781,6 +781,11 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
{
_InitGlobals();
+ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
+ Globals.uConsoleCodePage = GetConsoleCP();
+ FreeConsole();
+ }
+
// Set global variable Globals.hInstance
Globals.hInstance = hInstance;
Globals.hPrevInst = hPrevInstance;
diff --git a/src/TypeDefs.h b/src/TypeDefs.h
index f25a37f5a..bb71b2cea 100644
--- a/src/TypeDefs.h
+++ b/src/TypeDefs.h
@@ -294,6 +294,7 @@ typedef struct _globals_t
bool bPrefLngNotAvail;
HWND hwndMain;
HANDLE hndlProcessHeap;
+ UINT uConsoleCodePage;
HWND hwndEdit;
HANDLE hndlScintilla;
HANDLE hwndToolbar;
diff --git a/src/VersionEx.h b/src/VersionEx.h
index 09b01e5c8..d1778d7f3 100644
--- a/src/VersionEx.h
+++ b/src/VersionEx.h
@@ -8,8 +8,8 @@
#define SAPPNAME "Notepad3"
#define VERSION_MAJOR 5
#define VERSION_MINOR 19
-#define VERSION_REV 1102
-#define VERSION_BUILD 2665
+#define VERSION_REV 1104
+#define VERSION_BUILD 2666
#define SCINTILLA_VER 420
#define ONIGURUMA_REGEX_VER 6.9.4
#define UCHARDET_VER 2018.09.27