diff --git a/minipath/language/common_res.h b/minipath/language/common_res.h index c202e71c0..b07ef2f41 100644 --- a/minipath/language/common_res.h +++ b/minipath/language/common_res.h @@ -207,7 +207,8 @@ #define IDS_ERR_INIOPEN 50018 #define IDS_ERR_INICREATE 50019 #define IDS_ERR_INIWRITE 50020 -#define IDS_ERR_LANG_NOT_AVAIL 50021 +#define IDS_WARN_PREF_LNG_NOT_AVAIL 50021 + #define SC_ALWAYSONTOP 60001 #define SC_ABOUT 60002 diff --git a/minipath/language/mp_en_us/strings_en_us.rc b/minipath/language/mp_en_us/strings_en_us.rc index 0108ec12d..6b0e52c2a 100644 Binary files a/minipath/language/mp_en_us/strings_en_us.rc and b/minipath/language/mp_en_us/strings_en_us.rc differ diff --git a/minipath/src/Dialogs.c b/minipath/src/Dialogs.c index be035ce3d..ad8d76d37 100644 --- a/minipath/src/Dialogs.c +++ b/minipath/src/Dialogs.c @@ -44,21 +44,20 @@ extern HWND hwndMain; extern LANGID g_iPrefLngLocID; -int ErrorMessage(int iLevel,UINT uIdMsg,...) +int ErrorMessage(int iLevel, UINT uIdMsg, ...) { - WCHAR szText [256*2]; - WCHAR szTitle[256*2]; - WCHAR *c; + WCHAR szText[256 * 2] = { L'\0' }; + WCHAR szTitle[256 * 2] = { L'\0' }; int iIcon; - HWND hwnd; if (!GetString(uIdMsg,szText,COUNTOF(szText))) return(0); - wvsprintf(szTitle,szText,(LPVOID)(&uIdMsg + 1)); + int t = wvsprintf(szTitle,szText,(LPVOID)((PUINT_PTR)&uIdMsg + 1)); + szTitle[t] = L'\0'; - c = StrChr(szTitle,L'\n'); + WCHAR* c = StrChr(szTitle,L'\n'); if (c) { lstrcpy(szText,(c + 1)); @@ -73,10 +72,9 @@ int ErrorMessage(int iLevel,UINT uIdMsg,...) iIcon = (iLevel > 1) ? MB_ICONEXCLAMATION : MB_ICONINFORMATION; HWND focus = GetFocus(); - hwnd = focus ? focus : hwndMain; - - return MessageBoxEx(hwnd,szText,szTitle,MB_SETFOREGROUND | iIcon, g_iPrefLngLocID); + HWND hwnd = focus ? focus : hwndMain; + return MessageBoxEx(hwnd, szText, szTitle, MB_SETFOREGROUND | iIcon, g_iPrefLngLocID); } diff --git a/minipath/src/Helpers.c b/minipath/src/Helpers.c index 1fcc09a8d..03e1ea7af 100644 --- a/minipath/src/Helpers.c +++ b/minipath/src/Helpers.c @@ -137,6 +137,44 @@ void EndWaitCursor() } +//============================================================================= +// +// GetLastErrorToMsgBox() +// +DWORD GetLastErrorToMsgBox(LPWSTR lpszFunction, DWORD dwErrID) +{ + // Retrieve the system error message for the last-error code + if (!dwErrID) { + dwErrID = GetLastError(); + } + + LPVOID lpMsgBuf; + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwErrID, + g_iPrefLngLocID, + (LPTSTR)&lpMsgBuf, + 0, NULL); + + // Display the error message and exit the process + + LPVOID lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, + (lstrlen((LPCWSTR)lpMsgBuf) + lstrlen((LPCWSTR)lpszFunction) + 80) * sizeof(WCHAR)); + + wsprintf((LPWSTR)lpDisplayBuf, L"Error: '%s' failed with error id %d:\n%s.\n", lpszFunction, dwErrID, (LPWSTR)lpMsgBuf); + + MessageBox(NULL, (LPCWSTR)lpDisplayBuf, L"Notepad3 - ERROR", MB_OK | MB_ICONEXCLAMATION); + + LocalFree(lpMsgBuf); + LocalFree(lpDisplayBuf); + + return dwErrID; +} + + //============================================================================= // // ExeNameFromWnd() diff --git a/minipath/src/Helpers.h b/minipath/src/Helpers.h index b181369a5..92b22832b 100644 --- a/minipath/src/Helpers.h +++ b/minipath/src/Helpers.h @@ -88,6 +88,8 @@ LRESULT SendWMSize(HWND); int FormatString(LPWSTR,int,UINT,...); +DWORD GetLastErrorToMsgBox(LPWSTR lpszFunction, DWORD dwErrID); + void PathRelativeToApp(LPWSTR,LPWSTR,int,BOOL,BOOL,BOOL); void PathAbsoluteFromApp(LPWSTR,LPWSTR,int,BOOL); diff --git a/minipath/src/minipath.c b/minipath/src/minipath.c index 932886664..9a075481f 100644 --- a/minipath/src/minipath.c +++ b/minipath/src/minipath.c @@ -233,7 +233,7 @@ static HMODULE __fastcall _LoadLanguageResources(LANGID const langID) lstrcpy(tchAvailLngs, g_tchAvailableLanguages); WCHAR tchUserLangMultiStrg[128] = { L'\0' }; if (!_LngStrToMultiLngStr(tchAvailLngs, tchUserLangMultiStrg, 512)) { - ErrorMessage(2, IDS_ERR_LANG_NOT_AVAIL, g_tchPrefLngLocName); + GetLastErrorToMsgBox(L"_LngStrToMultiLngStr()", ERROR_MUI_INVALID_LOCALE_NAME); return NULL; } @@ -241,7 +241,7 @@ static HMODULE __fastcall _LoadLanguageResources(LANGID const langID) DWORD langCount = 0; // using SetProcessPreferredUILanguages is recommended for new applications (esp. multi-threaded applications) if (!SetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, tchUserLangMultiStrg, &langCount) || (langCount == 0)) { - ErrorMessage(2, IDS_ERR_LANG_NOT_AVAIL, g_tchPrefLngLocName); + GetLastErrorToMsgBox(L"SetProcessPreferredUILanguages()", 0); return NULL; } SetThreadUILanguage(langID); @@ -349,6 +349,10 @@ int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int n hAcc = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_MAINWND)); + if (bPrefLngNotAvail) { + ErrorMessage(2, IDS_WARN_PREF_LNG_NOT_AVAIL, g_tchPrefLngLocName); + } + while (GetMessage(&msg,NULL,0,0)) { if (!TranslateAccelerator(hwnd,hAcc,&msg)) diff --git a/minipath/src/minipath.rc b/minipath/src/minipath.rc index f5e4d113a..aef60c878 100644 Binary files a/minipath/src/minipath.rc and b/minipath/src/minipath.rc differ diff --git a/src/Helpers.h b/src/Helpers.h index e62ea9d73..560cf141b 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -20,7 +20,7 @@ #define STRSAFE_NO_DEPRECATE // don't allow deprecated functions #include #include -#include +#include #include "typedefs.h" @@ -31,7 +31,7 @@ extern WCHAR g_wchIniFile[MAX_PATH]; // ============================================================================ -#define STRGFY(X) L##X +#define STRGFY(X) L##(X) #define MKWSTRG(strg) STRGFY(strg) #define UNUSED(expr) (void)(expr) diff --git a/src/Notepad3.c b/src/Notepad3.c index ecc85caa1..2db23d594 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -723,7 +723,7 @@ int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int n SetTimer(hwnd, IDT_TIMER_MRKALL, USER_TIMER_MINIMUM, (TIMERPROC)MQ_ExecuteNext); if (bPrefLngNotAvail) { - InfoBoxLng(MBWARN, L"MsgPrefLanguageNotAvailable", IDS_WARN_PREF_LNG_NOT_AVAIL); + InfoBoxLng(MBWARN, L"MsgPrefLanguageNotAvailable", IDS_WARN_PREF_LNG_NOT_AVAIL, g_tchPrefLngLocName); } MSG msg; @@ -7467,7 +7467,7 @@ static bool __fastcall _CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule) static bool __fastcall _CheckIniFileRedirect(LPWSTR lpszFile,LPCWSTR lpszModule) { WCHAR tch[MAX_PATH] = { L'\0' }; - if (GetPrivateProfileString(L"" APPNAME, L"" APPNAME ".ini",L"",tch,COUNTOF(tch),lpszFile)) { + if (GetPrivateProfileString( L"" APPNAME, L"" APPNAME ".ini", L"",tch,COUNTOF(tch),lpszFile)) { if (_CheckIniFile(tch,lpszModule)) { StringCchCopy(lpszFile,MAX_PATH,tch); return true; diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 675b7c83e..eebd836b8 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -285,7 +285,7 @@ END STRINGTABLE BEGIN - IDS_WARN_PREF_LNG_NOT_AVAIL "Sorry, your prefered language is not available." + IDS_WARN_PREF_LNG_NOT_AVAIL "Sorry, your prefered language (%s) is not available." IDS_STATUS_DOCLINE "%s%s / %s" IDS_STATUS_DOCCOLUMN "%s%s" IDS_STATUS_DOCCOLUMN2 "%s%s / %s"