+ chg: MUI aware MiniPath (2nd part)

This commit is contained in:
Rainer Kottenhoff 2018-06-26 00:59:17 +02:00
parent 988802a806
commit 095fb84199
10 changed files with 61 additions and 18 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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()

View File

@ -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);

View File

@ -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))

Binary file not shown.

View File

@ -20,7 +20,7 @@
#define STRSAFE_NO_DEPRECATE // don't allow deprecated functions
#include <strsafe.h>
#include <shlwapi.h>
#include <VersionHelpers.h>
#include <versionhelpers.h>
#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)

View File

@ -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;

View File

@ -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"