From 20b011529b5afa56bb61ba12fccc71522ccafd4e Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 6 Mar 2026 20:28:32 +0100 Subject: [PATCH] fix: enhance InfoBoxLng() to replace non dark-mode aware MessageBoxEx(). InfoBoxLng is dynamicall adapted in height depending on text length. --- src/Config/Config.cpp | 16 +-- src/Dialogs.c | 310 ++++++++++++++++-------------------------- src/Dialogs.h | 6 +- src/Edit.c | 6 +- src/Helpers.c | 4 +- src/MuiLanguage.c | 10 +- src/Notepad3.c | 69 +++------- src/PathLib.c | 4 +- src/Styles.c | 2 +- src/TypeDefs.h | 1 - 10 files changed, 164 insertions(+), 264 deletions(-) diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 0ff58e7ee..feaab88e6 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -193,13 +193,13 @@ HANDLE AcquireWriteFileLock(LPCWSTR lpIniFilePath, OVERLAPPED& rOvrLpd) if (!bLocked) { HSTRINGW msg = StrgCreate(NULL); StrgFormat(msg, L"AcquireWriteFileLock(%s): NO EXCLUSIVE LOCK ACQUIRED!", lpIniFilePath); - MsgBoxLastError(StrgGet(msg), 0); + InfoBoxLastError(StrgGet(msg), 0); StrgDestroy(msg); } } else { HSTRINGW msg = StrgCreate(NULL); StrgFormat(msg, L"AcquireWriteFileLock(%s): INVALID FILE HANDLE!", lpIniFilePath); - MsgBoxLastError(StrgGet(msg), 0); + InfoBoxLastError(StrgGet(msg), 0); StrgDestroy(msg); } return (bLocked ? hFile : INVALID_HANDLE_VALUE); @@ -226,13 +226,13 @@ HANDLE AcquireReadFileLock(LPCWSTR lpIniFilePath, OVERLAPPED& rOvrLpd) if (!bLocked) { HSTRINGW msg = StrgCreate(NULL); StrgFormat(msg, L"AcquireReadFileLock(%s): NO READER LOCK ACQUIRED!", lpIniFilePath); - MsgBoxLastError(StrgGet(msg), 0); + InfoBoxLastError(StrgGet(msg), 0); StrgDestroy(msg); } } else { HSTRINGW msg = StrgCreate(NULL); StrgFormat(msg, L"AcquireReadFileLock(%s): INVALID FILE HANDLE!", lpIniFilePath); - MsgBoxLastError(StrgGet(msg), 0); + InfoBoxLastError(StrgGet(msg), 0); StrgDestroy(msg); } return (bLocked ? hFile : INVALID_HANDLE_VALUE); @@ -1138,11 +1138,11 @@ extern "C" bool CreateIniFile(const HPATHL hini_pth, DWORD* pdwFileSize_out) if (IS_VALID_HANDLE(hFile)) { CloseHandle(hFile); // done } else { - WCHAR fileName[MAX_PATH_EXPLICIT>>1] = { L'\0' }; + WCHAR fileName[MAX_PATH_EXPLICIT] = { L'\0' }; Path_GetDisplayName(fileName, COUNTOF(fileName), hini_pth, NULL, true); HSTRINGW msg = StrgCreate(NULL); StrgFormat(msg, L"CreateIniFile(%s): FAILED TO CREATE INITIAL INI FILE!", fileName); - MsgBoxLastError(StrgGet(msg), 0); + InfoBoxLastError(StrgGet(msg), 0); StrgDestroy(msg); if (pdwFileSize_out) { *pdwFileSize_out = 0UL; } return false; @@ -1157,11 +1157,11 @@ extern "C" bool CreateIniFile(const HPATHL hini_pth, DWORD* pdwFileSize_out) dwFileSize = GetFileSize(hFile, &dwFSHigh); CloseHandle(hFile); } else { - WCHAR fileName[MAX_PATH_EXPLICIT>>1] = { L'\0' }; + WCHAR fileName[MAX_PATH_EXPLICIT] = { L'\0' }; Path_GetDisplayName(fileName, COUNTOF(fileName), hini_pth, NULL, true); HSTRINGW msg = StrgCreate(NULL); StrgFormat(msg, L"CreateIniFile(%s): FAILED TO READ FILESIZE!", fileName); - MsgBoxLastError(StrgGet(msg), 0); + InfoBoxLastError(StrgGet(msg), 0); StrgDestroy(msg); dwFileSize = INVALID_FILE_SIZE; } diff --git a/src/Dialogs.c b/src/Dialogs.c index 3de3b3c31..cf729af04 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -87,144 +87,6 @@ HWND GetParentOrDesktop(HWND hDlg) } -//============================================================================= -// -// MessageBoxLng() -// -static HHOOK s_hCBThook = NULL; - -static LRESULT CALLBACK SetPosRelatedToParent_Hook(INT nCode, WPARAM wParam, LPARAM lParam) -{ - // notification that a window is about to be activated - if (nCode == HCBT_CREATEWND) { - HWND const hThisWnd = (HWND)wParam; - if (hThisWnd) { - - SetDialogIconNP3(hThisWnd); - InitWindowCommon(hThisWnd, true); - - // get window handles - LPCREATESTRUCT const pCreateStruct = ((LPCBT_CREATEWND)lParam)->lpcs; - - HWND const hParentWnd = pCreateStruct->hwndParent ? pCreateStruct->hwndParent : GetParentOrDesktop(hThisWnd); - - if (hParentWnd) { - - // set new coordinates - RECT rcDlg = { 0, 0, 0, 0 }; - rcDlg.left = pCreateStruct->x; - rcDlg.top = pCreateStruct->y; - rcDlg.right = pCreateStruct->x + pCreateStruct->cx; - rcDlg.bottom = pCreateStruct->y + pCreateStruct->cy; - - POINT const ptTopLeft = GetCenterOfDlgInParent(&rcDlg, hParentWnd); - - pCreateStruct->x = ptTopLeft.x; - pCreateStruct->y = ptTopLeft.y; - } - - // we are done - if (s_hCBThook) { - UnhookWindowsHookEx(s_hCBThook); - s_hCBThook = NULL; - } - } else if (s_hCBThook) { - // continue with any possible chained hooks - return CallNextHookEx(s_hCBThook, nCode, wParam, lParam); - } - } - return (LRESULT)0; -} -// ----------------------------------------------------------------------------- - - -int MessageBoxLng(UINT uType, UINT uidMsg, ...) -{ - HSTRINGW hfmt_str = StrgCreate(NULL); - LPWSTR const fmt_buf = StrgWriteAccessBuf(hfmt_str, XXXL_BUFFER); - if (!GetLngString(uidMsg, fmt_buf, (int)StrgGetAllocLength(hfmt_str))) { - StrgDestroy(hfmt_str); - return -1; - } - StrgSanitize(hfmt_str); - - HSTRINGW htxt_str = StrgCreate(NULL); - const PUINT_PTR argp = (PUINT_PTR)&uidMsg + 1; - bool const bHasArgs = (argp && *argp); - if (bHasArgs) { - LPWSTR const txt_buf = StrgWriteAccessBuf(htxt_str, XXXL_BUFFER); - StringCchVPrintfW(txt_buf, StrgGetAllocLength(htxt_str), StrgGet(hfmt_str), (LPVOID)argp); - StrgSanitize(htxt_str); - } - - uType |= MB_SETFOREGROUND; //~ MB_TOPMOST - if (Settings.DialogsLayoutRTL) { - uType |= MB_RTLREADING; - } - - // center message box to focus or main - HWND const focus = GetFocus(); - HWND const hwnd = focus ? focus : Globals.hwndMain; - s_hCBThook = SetWindowsHookEx(WH_CBT, &SetPosRelatedToParent_Hook, 0, GetCurrentThreadId()); - - int const res = MessageBoxEx(hwnd, bHasArgs ? StrgGet(htxt_str) : StrgGet(hfmt_str), - _W(SAPPNAME), uType, GetLangIdByLocaleName(Globals.CurrentLngLocaleName)); - - StrgDestroy(htxt_str); - StrgDestroy(hfmt_str); - - return res; -} - - -//============================================================================= -// -// MsgBoxLastError() -// -DWORD MsgBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID) -{ - // Retrieve the system error message for the last-error code - if (!dwErrID) { - dwErrID = GetLastError(); - } - - LPVOID lpMsgBuf = NULL; - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dwErrID, - GetLangIdByLocaleName(Globals.CurrentLngLocaleName), - (LPWSTR)&lpMsgBuf, - 0, NULL); - - if (lpMsgBuf) { - // Display the error message and exit the process - size_t const len = StringCchLen((LPCWSTR)lpMsgBuf, 0) + StringCchLen(lpszMessage, 0) + 160; - LPWSTR const lpDisplayBuf = (LPWSTR)AllocMem(len * sizeof(WCHAR), HEAP_ZERO_MEMORY); - - if (lpDisplayBuf) { - - WCHAR msgFormat[128] = { L'\0' }; - GetLngString(IDS_MUI_ERR_DLG_FORMAT, msgFormat, COUNTOF(msgFormat)); - StringCchPrintf(lpDisplayBuf, len, msgFormat, lpszMessage, (LPCWSTR)lpMsgBuf, dwErrID); - // center message box to main - HWND const focus = GetFocus(); - HWND const hwnd = focus ? focus : Globals.hwndMain; - s_hCBThook = SetWindowsHookEx(WH_CBT, &SetPosRelatedToParent_Hook, 0, GetCurrentThreadId()); - - UINT uType = MB_ICONERROR | MB_TOPMOST | (Settings.DialogsLayoutRTL ? MB_RTLREADING : 0); - MessageBoxEx(hwnd, lpDisplayBuf, _W(SAPPNAME) L" - ERROR", uType, GetLangIdByLocaleName(Globals.CurrentLngLocaleName)); - - FreeMem(lpDisplayBuf); - } - LocalFree(lpMsgBuf); // LocalAlloc() - lpMsgBuf = NULL; - } - return dwErrID; -} - //============================================================================= // // _InfoBoxLngDlgProc() @@ -298,30 +160,77 @@ static INT_PTR CALLBACK _InfoBoxLngDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, //UINT const tabStopDist[3] = { 4, 4, 8 }; //SendMessage(GetDlgItem(hwnd, IDC_INFOBOXTEXT), EM_SETTABSTOPS, 3, (LPARAM)tabStopDist); -#if 0 - // Resize dialog to fit text - TODO: move buttons dynamically too - HWND const hWndText = GetDlgItem(hwnd, IDC_INFOBOXTEXT); - RECT rectText = { 0 }; - GetWindowRectEx(hWndText, &rectText); - - RECT rectNew = { 0 }; - rectNew.left = 0; - rectNew.top = 0; - rectNew.right = rectText.right - rectText.left; // max as specified - rectNew.bottom = rectNew.right; // max quadratic size - - HDC hdc = GetDC(hWndText); - DrawText(hdc, lpMsgBox->lpstrMessage, -1, &rectNew, DT_CALCRECT | DT_WORDBREAK); // calc size - ReleaseDC(hWndText, hdc); - - // Change size of text field - SetWindowPos(hWndText, NULL, 0, 0, rectNew.right - rectNew.left, rectNew.bottom - rectNew.top, SWP_NOMOVE | SWP_NOZORDER); - //GetWindowRect(hWndText, &rectText); - - int const width = (rectNew.right - rectNew.left) + 100; - int const height = (rectNew.bottom - rectNew.top) + 200; - SetWindowPos(hwnd, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER); -#endif + // --- Dynamic text sizing: grow dialog vertically to fit message --- + { + HWND const hWndText = GetDlgItem(hwnd, IDC_INFOBOXTEXT); + + // 1. Get current text control rect in parent client coords + RECT rcText; + GetWindowRect(hWndText, &rcText); + MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&rcText, 2); + int const origTextHeight = rcText.bottom - rcText.top; + int const textWidth = rcText.right - rcText.left; + + // 2. Measure required text height with correct font + HDC hdc = GetDC(hWndText); + HFONT hFont = (HFONT)SendMessage(hWndText, WM_GETFONT, 0, 0); + HFONT hOldFont = (HFONT)SelectObject(hdc, hFont); + + RECT rcCalc = { 0, 0, textWidth, 0 }; + DrawText(hdc, lpMsgBox->lpstrMessage, -1, &rcCalc, + DT_CALCRECT | DT_WORDBREAK | DT_EXPANDTABS | DT_NOPREFIX | DT_EDITCONTROL); + + SelectObject(hdc, hOldFont); + ReleaseDC(hWndText, hdc); + + int const measuredHeight = rcCalc.bottom; + + // 3. Calculate delta (only grow, never shrink below template size) + int deltaY = measuredHeight - origTextHeight; + if (deltaY < 0) { + deltaY = 0; + } + + // 4. Clamp: don't let dialog exceed ~70% of work area + if (deltaY > 0) { + RECT rcWorkArea; + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0); + RECT rcDialog; + GetWindowRect(hwnd, &rcDialog); + int const curDlgHeight = rcDialog.bottom - rcDialog.top; + int const maxDlgHeight = MulDiv(rcWorkArea.bottom - rcWorkArea.top, 70, 100); + if (curDlgHeight + deltaY > maxDlgHeight) { + deltaY = max(0, maxDlgHeight - curDlgHeight); + } + } + + // 5. Apply resize: grow text control, shift buttons/checkbox down, grow dialog + if (deltaY > 0) { + SetWindowPos(hWndText, NULL, 0, 0, textWidth, origTextHeight + deltaY, + SWP_NOMOVE | SWP_NOZORDER); + + int const ctlIDs[] = { IDOK, IDYES, IDNO, IDCANCEL, IDABORT, IDRETRY, + IDIGNORE, IDTRYAGAIN, IDCONTINUE, IDCLOSE, + IDC_INFOBOXCHECK }; + for (int i = 0; i < COUNTOF(ctlIDs); ++i) { + HWND hCtl = GetDlgItem(hwnd, ctlIDs[i]); + if (hCtl) { + RECT rc; + GetWindowRect(hCtl, &rc); + MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&rc, 2); + SetWindowPos(hCtl, NULL, rc.left, rc.top + deltaY, 0, 0, + SWP_NOSIZE | SWP_NOZORDER); + } + } + + RECT rcDlg; + GetWindowRect(hwnd, &rcDlg); + SetWindowPos(hwnd, NULL, 0, 0, + rcDlg.right - rcDlg.left, + (rcDlg.bottom - rcDlg.top) + deltaY, + SWP_NOMOVE | SWP_NOZORDER); + } + } SetDlgItemText(hwnd, IDC_INFOBOXTEXT, lpMsgBox->lpstrMessage); @@ -582,6 +491,54 @@ LONG InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...) return MAKELONG(answer, iMode); } + +//============================================================================= +// +// InfoBoxLastError() +// +DWORD InfoBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID) +{ + if (!dwErrID) { + dwErrID = GetLastError(); + } + + LPVOID lpMsgBuf = NULL; + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwErrID, + GetLangIdByLocaleName(Globals.CurrentLngLocaleName), + (LPWSTR)&lpMsgBuf, + 0, NULL); + + if (lpMsgBuf) { + size_t const len = StringCchLen((LPCWSTR)lpMsgBuf, 0) + StringCchLen(lpszMessage, 0) + 160; + LPWSTR const lpDisplayBuf = (LPWSTR)AllocMem(len * sizeof(WCHAR), HEAP_ZERO_MEMORY); + + if (lpDisplayBuf) { + WCHAR msgFormat[128] = { L'\0' }; + GetLngString(IDS_MUI_ERR_DLG_FORMAT, msgFormat, COUNTOF(msgFormat)); + StringCchPrintf(lpDisplayBuf, len, msgFormat, lpszMessage, (LPCWSTR)lpMsgBuf, dwErrID); + + INFOBOXLNG msgBox = { 0 }; + msgBox.uType = MB_OK | MB_ICONERROR | (Settings.DialogsLayoutRTL ? MB_RTLREADING : 0); + msgBox.lpstrMessage = lpDisplayBuf; // ownership transfers to _InfoBoxLngDlgProc + msgBox.lpstrSetting = NULL; + msgBox.bDisableCheckBox = true; + + HWND const focus = GetFocus(); + HWND const hwnd = focus ? focus : Globals.hwndMain; + ThemedDialogBoxParam(Globals.hLngResContainer, MAKEINTRESOURCE(IDD_MUI_INFOBOX), + hwnd, _InfoBoxLngDlgProc, (LPARAM)&msgBox); + } + LocalFree(lpMsgBuf); + } + return dwErrID; +} + + /* MinimizeToTray - Copyright 2000 Matthew Ellis @@ -793,31 +750,6 @@ void RestoreWndFromTray(HWND hWnd) // // DisplayCmdLineHelp() // -#if 0 -void DisplayCmdLineHelp(HWND hwnd) -{ - WCHAR szText[2048] = { L'\0' }; - GetLngString(IDS_MUI_CMDLINEHELP,szText,COUNTOF(szText)); - - MSGBOXPARAMS mbp = { 0 }; - mbp.cbSize = sizeof(MSGBOXPARAMS); - mbp.hwndOwner = hwnd; - mbp.hInstance = Globals.hInstance; - mbp.lpszText = szText; - mbp.lpszCaption = _W(SAPPNAME); - mbp.dwStyle = MB_OK | MB_USERICON | MB_SETFOREGROUND; - mbp.lpszIcon = MAKEINTRESOURCE(IDR_MAINWND); - mbp.dwContextHelpId = 0; - mbp.lpfnMsgBoxCallback = NULL; - mbp.dwLanguageId = GetLangIdByLocaleName(Globals.CurrentLngLocaleName); - - hhkMsgBox = SetWindowsHookEx(WH_CBT, &_MsgBoxProc, 0, GetCurrentThreadId()); - - MessageBoxIndirect(&mbp); - //MsgBoxLng(MBINFO, IDS_MUI_CMDLINEHELP); -} -#else - static INT_PTR CALLBACK CmdLineHelpProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); @@ -899,8 +831,6 @@ INT_PTR DisplayCmdLineHelp(HWND hwnd) return ThemedDialogBoxParam(Globals.hLngResContainer, MAKEINTRESOURCE(IDD_MUI_CMDLINEHELP), hwnd, CmdLineHelpProc, (LPARAM)L""); } -#endif - /* //============================================================================= @@ -1810,7 +1740,7 @@ bool OpenWithDlg(HWND hwnd, LPCWSTR lpstrFile) HPATHL hpthFileName = Path_Allocate(lpstrFile); dliOpenWith.pthFileName = Path_WriteAccessBuf(hpthFileName, PATHLONG_MAX_CCH); - WCHAR chDispayName[MAX_PATH_EXPLICIT>>1] = { L'\0' }; + WCHAR chDispayName[MAX_PATH_EXPLICIT] = { L'\0' }; Path_GetDisplayName(chDispayName, COUNTOF(chDispayName), hpthFileName, NULL, true); dliOpenWith.strDisplayName = chDispayName; diff --git a/src/Dialogs.h b/src/Dialogs.h index 94883afab..c9eb7c1a9 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -82,10 +82,8 @@ void DialogFileBrowse(HWND hwnd); void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern); void DialogAdminExe(HWND hwnd,bool); -int MessageBoxLng(UINT uType, UINT uidMsg, ...); -DWORD MsgBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID); - -LONG InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...); +LONG InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...); +DWORD InfoBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID); #define INFOBOX_ANSW(_R_) LOWORD(_R_) #define INFOBOX_MODE(_R_) HIWORD(_R_) diff --git a/src/Edit.c b/src/Edit.c index eba52fd8e..58eb6d76f 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -7354,13 +7354,13 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar break; case IDC_BACKSLASHHELP: // Display help messages in the find/replace windows - MessageBoxLng(MB_ICONINFORMATION, IDS_MUI_BACKSLASHHELP); + InfoBoxLng(MB_ICONINFORMATION, NULL, IDS_MUI_BACKSLASHHELP); break; case IDC_REGEXPHELP: - MessageBoxLng(MB_ICONINFORMATION, IDS_MUI_REGEXPHELP); + InfoBoxLng(MB_ICONINFORMATION, NULL, IDS_MUI_REGEXPHELP); break; case IDC_WILDCARDHELP: - MessageBoxLng(MB_ICONINFORMATION, IDS_MUI_WILDCARDHELP); + InfoBoxLng(MB_ICONINFORMATION, NULL, IDS_MUI_WILDCARDHELP); break; default: break; diff --git a/src/Helpers.c b/src/Helpers.c index 82496437e..364e38f1e 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -328,7 +328,7 @@ bool IsProcessElevated() } if (Globals.dwLastError != ERROR_SUCCESS) { - MsgBoxLastError(pLastErrMsg, Globals.dwLastError); + InfoBoxLastError(pLastErrMsg, Globals.dwLastError); } return bIsElevated; @@ -457,7 +457,7 @@ bool IsUserInAdminGroup() } if (Globals.dwLastError != ERROR_SUCCESS) { - MsgBoxLastError(pLastErrMsg, Globals.dwLastError); + InfoBoxLastError(pLastErrMsg, Globals.dwLastError); } return fInAdminGroup; diff --git a/src/MuiLanguage.c b/src/MuiLanguage.c index 53552f2f4..f8a78a7e0 100644 --- a/src/MuiLanguage.c +++ b/src/MuiLanguage.c @@ -144,7 +144,7 @@ static void SetMuiLocaleAll(LPCWSTR pszLocaleStr) { WCHAR msg[128]; StringCchPrintf(msg, COUNTOF(msg), L"Can't set desired locale '%s', using '%s' instead!", pszLocaleStr, pszLocaleCur ? pszLocaleCur : L""); - MsgBoxLastError(msg, ERROR_MUI_INVALID_LOCALE_NAME); + InfoBoxLastError(msg, ERROR_MUI_INVALID_LOCALE_NAME); #endif } } @@ -385,14 +385,14 @@ unsigned LoadLanguageResources(LPCWSTR pLocaleName) { WCHAR tchUserLangMultiStrg[LARGE_BUFFER] = { L'\0' }; if (!_LngStrToMultiLngStr(tchAvailLngs, tchUserLangMultiStrg, COUNTOF(tchUserLangMultiStrg))) { - MsgBoxLastError(L"Trying to load available Language resources!", ERROR_MUI_INVALID_LOCALE_NAME); + InfoBoxLastError(L"Trying to load available Language resources!", ERROR_MUI_INVALID_LOCALE_NAME); } ULONG langCount = 0; // using SetProcessPreferredUILanguages is recommended for new applications (esp. multi-threaded applications) SetProcessPreferredUILanguages(0, L"\0\0", &langCount); // clear if (!SetProcessPreferredUILanguages(MUI_LANGUAGE_NAME, tchUserLangMultiStrg, &langCount) || (langCount == 0)) { #if (defined(_DEBUG) || defined(DEBUG)) && !defined(NDEBUG) - MsgBoxLastError(L"Trying to set preferred Language!", ERROR_RESOURCE_LANG_NOT_FOUND); + InfoBoxLastError(L"Trying to set preferred Language!", ERROR_RESOURCE_LANG_NOT_FOUND); #endif } @@ -413,7 +413,7 @@ unsigned LoadLanguageResources(LPCWSTR pLocaleName) { MUI_LanguageDLLs[iLngIndex].bIsActive = true; MUI_LanguageDLLs[iInternalLngIndex].bIsActive = false; } else { - //MsgBoxLastError(L"LoadMUILibrary", 0); + //InfoBoxLastError(L"LoadMUILibrary", 0); iLngIndex = MuiLanguages_CountOf(); // not found } } @@ -548,7 +548,7 @@ void DynamicLanguageMenuCmd(int cmd) { Globals.hMainMenu = LoadMenu(Globals.hLngResContainer, MAKEINTRESOURCE(IDR_MUI_MAINMENU)); if (!Globals.hMainMenu) { - MsgBoxLastError(L"LoadMenu()", 0); + InfoBoxLastError(L"LoadMenu()", 0); CloseApplication(); return; } diff --git a/src/Notepad3.c b/src/Notepad3.c index 3572013d7..ed25496b6 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -993,7 +993,7 @@ void InvalidParameterHandler(const wchar_t* expression, StringCchPrintf(msg, COUNTOF(msg), L"Invalid Parameter in function '%s()' - File:'%s' Line:%i !", function, file, line); - MsgBoxLastError(msg, ERROR_INVALID_PARAMETER); + InfoBoxLastError(msg, ERROR_INVALID_PARAMETER); #endif } @@ -1041,7 +1041,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, // check if running at least on Windows 10 if (!IsWindows10OrGreater()) { - MsgBoxLastError(L"Application Initialization", ERROR_OLD_WIN_VERSION); + InfoBoxLastError(L"Application Initialization", ERROR_OLD_WIN_VERSION); return 1; // exit } @@ -1244,7 +1244,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, Globals.hMainMenu = LoadMenu(Globals.hLngResContainer, MAKEINTRESOURCE(IDR_MUI_MAINMENU)); if (!Globals.hMainMenu) { - MsgBoxLastError(L"LoadMenu()", 0); + InfoBoxLastError(L"LoadMenu()", 0); _CleanUpResources(NULL, false); return 1; } @@ -1778,7 +1778,7 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow) // manual (not automatic) reset & initial state: not signaled (TRUE, FALSE) s_hEventAppIsClosing = CreateEvent(NULL, TRUE, FALSE, NULL); if (!IS_VALID_HANDLE(s_hEventAppIsClosing)) { - MsgBoxLastError(L"CreateEvent(s_hEventAppIsClosing)", GetLastError()); + InfoBoxLastError(L"CreateEvent(s_hEventAppIsClosing)", GetLastError()); return NULL; } @@ -1830,13 +1830,13 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow) // manual (not automatic) reset & initial state: not signaled (TRUE, FALSE) s_FileChgObsvrData.hEventFileChanged = CreateEvent(NULL, TRUE, FALSE, NULL); if (!IS_VALID_HANDLE(s_FileChgObsvrData.hEventFileChanged)) { - MsgBoxLastError(L"CreateEvent(hEventFileChanged)", GetLastError()); + InfoBoxLastError(L"CreateEvent(hEventFileChanged)", GetLastError()); return NULL; } s_FileChgObsvrData.hEventFileDeleted = CreateEvent(NULL, TRUE, FALSE, NULL); if (!IS_VALID_HANDLE(s_FileChgObsvrData.hEventFileDeleted)) { CloseHandle(s_FileChgObsvrData.hEventFileChanged); - MsgBoxLastError(L"CreateEvent(hEventFileDeleted)", GetLastError()); + InfoBoxLastError(L"CreateEvent(hEventFileDeleted)", GetLastError()); return NULL; } @@ -2111,7 +2111,7 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow) // print file immediately and quit if (Globals.CmdLnFlag_PrintFileAndLeave) { WCHAR tchPageFmt[32] = { L'\0' }; - WCHAR szDisplayName[MAX_PATH_EXPLICIT>>1]; + WCHAR szDisplayName[MAX_PATH_EXPLICIT]; GetLngString(IDS_MUI_UNTITLED, szDisplayName, COUNTOF(szDisplayName)); Path_GetDisplayName(szDisplayName, COUNTOF(szDisplayName), Paths.CurrentFile, NULL, true); @@ -4869,7 +4869,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) } else { dwFileAttributes |= FILE_ATTRIBUTE_READONLY; } - WCHAR szDisplayName[MAX_PATH_EXPLICIT>>1] = { L'\0' }; + WCHAR szDisplayName[MAX_PATH_EXPLICIT] = { L'\0' }; if (!Path_SetFileAttributes(Paths.CurrentFile, dwFileAttributes)) { Path_GetDisplayName(szDisplayName, COUNTOF(szDisplayName), Paths.CurrentFile, NULL, false); InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_READONLY_MODIFY, szDisplayName); @@ -4997,7 +4997,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_FILE_PRINT: { WCHAR tchPageFmt[32] = { L'\0' }; - WCHAR szDisplayName[MAX_PATH_EXPLICIT>>1]; + WCHAR szDisplayName[MAX_PATH_EXPLICIT]; GetLngString(IDS_MUI_UNTITLED, szDisplayName, COUNTOF(szDisplayName)); Path_GetDisplayName(szDisplayName, COUNTOF(szDisplayName), Paths.CurrentFile, NULL, false); @@ -11173,7 +11173,7 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags, const DocP bool bCreateFile = s_flagQuietCreate; if (!bCreateFile) { - WCHAR szDisplayName[MAX_PATH_EXPLICIT >> 1] = { L'\0' }; + WCHAR szDisplayName[MAX_PATH_EXPLICIT] = { L'\0' }; GetLngString(IDS_MUI_UNTITLED, szDisplayName, COUNTOF(szDisplayName)); Path_GetDisplayName(szDisplayName, COUNTOF(szDisplayName), hopen_file, NULL, false); //~Path_FindFileName(hopen_file) @@ -11622,15 +11622,13 @@ bool FileSave(FileSaveFlags fSaveFlags) if (fSaveFlags & FSF_Ask) { // File or "Untitled" ... - WCHAR wchFileName[MAX_PATH_EXPLICIT>>1] = { L'\0' }; + WCHAR wchFileName[MAX_PATH_EXPLICIT] = { L'\0' }; GetLngString(IDS_MUI_UNTITLED, wchFileName, COUNTOF(wchFileName)); Path_GetDisplayName(wchFileName, COUNTOF(wchFileName), Paths.CurrentFile, NULL, false); - INT_PTR const answer = (Settings.MuteMessageBeep) ? - InfoBoxLng(MB_YESNOCANCEL | MB_ICONWARNING, NULL, IDS_MUI_ASK_SAVE, wchFileName) : - MessageBoxLng(MB_YESNOCANCEL | MB_ICONWARNING, IDS_MUI_ASK_SAVE, wchFileName); + INT_PTR const answer = InfoBoxLng(MB_YESNOCANCEL | MB_ICONWARNING, NULL, IDS_MUI_ASK_SAVE, wchFileName); switch (answer) { case IDCANCEL: @@ -11649,9 +11647,7 @@ bool FileSave(FileSaveFlags fSaveFlags) if (!(fSaveFlags & FSF_SaveAs) && !(fSaveFlags & FSF_SaveCopy) && Path_IsNotEmpty(Paths.CurrentFile)) { if (IsFileReadOnly()) { UpdateToolbar(); - INT_PTR const answer = (Settings.MuteMessageBeep) ? - InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_READONLY_SAVE, Path_FindFileName(Paths.CurrentFile)) : - MessageBoxLng(MB_YESNO | MB_ICONWARNING, IDS_MUI_READONLY_SAVE, Path_Get(Paths.CurrentFile)); + INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_READONLY_SAVE, Path_Get(Paths.CurrentFile)); if (IsYesOkay(answer)) { fSaveFlags |= FSF_SaveAs; } else { @@ -11747,28 +11743,18 @@ bool FileSave(FileSaveFlags fSaveFlags) } else if (!fioStatus.bCancelDataLoss) { - LPCWSTR const currentFileName = Path_FindFileName(Paths.CurrentFile); - if (!s_bIsProcessElevated && (Globals.dwLastError == ERROR_ACCESS_DENIED)) { - INT_PTR const answer = (Settings.MuteMessageBeep) ? - InfoBoxLng(MB_YESNO | MB_ICONSHIELD, NULL, IDS_MUI_ERR_ACCESSDENIED, currentFileName, _W(SAPPNAME)) : - MessageBoxLng(MB_YESNO | MB_ICONSHIELD, IDS_MUI_ERR_ACCESSDENIED, Path_Get(Paths.CurrentFile), _W(SAPPNAME)); + INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONSHIELD, NULL, IDS_MUI_ERR_ACCESSDENIED, Path_Get(Paths.CurrentFile), _W(SAPPNAME)); if (IsYesOkay(answer)) { if (DoElevatedRelaunch(&fioStatus, true)) { CloseApplication(); } else { ResetEvent(s_hEventAppIsClosing); - if (Settings.MuteMessageBeep) { - InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_SAVEFILE, currentFileName); - } else { - MessageBoxLng(MB_ICONWARNING, IDS_MUI_ERR_SAVEFILE, Path_Get(Paths.CurrentFile)); - } + InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_SAVEFILE, Path_Get(Paths.CurrentFile)); } } } else if (Globals.dwLastError == ERROR_PATH_NOT_FOUND) { - INT_PTR const answer = (Settings.MuteMessageBeep) ? - InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PATHNOTFOUND, currentFileName) : - MessageBoxLng(MB_YESNO | MB_ICONWARNING, IDS_MUI_ERR_PATHNOTFOUND, Path_Get(Paths.CurrentFile)); + INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PATHNOTFOUND, Path_Get(Paths.CurrentFile)); if (IsYesOkay(answer)) { // Recreate the directory tree (pattern from Config.cpp CreateIniFile) HPATHL hdir_path = Path_Copy(Paths.CurrentFile); @@ -11792,29 +11778,17 @@ bool FileSave(FileSaveFlags fSaveFlags) _MRU_UpdateSession(); } } else { - if (Settings.MuteMessageBeep) { - InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_ERR_SAVEFILE, currentFileName); - } else { - MessageBoxLng(MB_ICONERROR, IDS_MUI_ERR_SAVEFILE, Path_Get(Paths.CurrentFile)); - } + InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_ERR_SAVEFILE, Path_Get(Paths.CurrentFile)); } } else { - if (Settings.MuteMessageBeep) { - InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_ERR_SAVEFILE, currentFileName); - } else { - MessageBoxLng(MB_ICONERROR, IDS_MUI_ERR_SAVEFILE, Path_Get(Paths.CurrentFile)); - } + InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_ERR_SAVEFILE, Path_Get(Paths.CurrentFile)); } } else { // User declined — offer Save As - FileSave(FSF_SaveAs); + fSuccess = FileSave(FSF_SaveAs); } } else { - if (Settings.MuteMessageBeep) { - InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_ERR_SAVEFILE, currentFileName); - } else { - MessageBoxLng(MB_ICONERROR, IDS_MUI_ERR_SAVEFILE, Path_Get(Paths.CurrentFile)); - } + InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_ERR_SAVEFILE, Path_Get(Paths.CurrentFile)); } } @@ -12492,7 +12466,6 @@ LRESULT MsgFileChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) break; case FWM_MSGBOX: { - /// LONG const answer = MessageBoxExW(Globals.hwndMain, L"File change, Cancel, Retry, Continue", L"NP3", MB_ABORTRETRYIGNORE, GetLangIdByLocaleName(Globals.CurrentLngLocaleName)); LONG const answer = InfoBoxLng(MB_FILECHANGEDNOTIFY | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY); switch (LOWORD(answer)) { case IDCANCEL: @@ -12822,7 +12795,7 @@ void InstallFileWatching(const bool bInstall) { if (!IS_VALID_HANDLE(_hCurrFileHandle)) { - WCHAR wchDisplayName[MAX_PATH_EXPLICIT>>1]; + WCHAR wchDisplayName[MAX_PATH_EXPLICIT]; GetLngString(IDS_MUI_UNTITLED, wchDisplayName, COUNTOF(wchDisplayName)); Path_GetDisplayName(wchDisplayName, COUNTOF(wchDisplayName), Paths.CurrentFile, NULL, false); diff --git a/src/PathLib.c b/src/PathLib.c index 8cf8ee115..8b3f1f4d2 100644 --- a/src/PathLib.c +++ b/src/PathLib.c @@ -1471,7 +1471,7 @@ size_t PTHAPI Path_ToShortPathName(HPATHL hpth_in_out) DWORD const _len = GetShortPathNameW(StrgGet(hstr_io), NULL, 0); if (!_len) { #if (defined(_DEBUG) || defined(DEBUG)) && !defined(NDEBUG) - MsgBoxLastError(L"Path_ToShortPathName()", 0); + InfoBoxLastError(L"Path_ToShortPathName()", 0); #endif // DEBUG return 0; } @@ -1495,7 +1495,7 @@ size_t PTHAPI Path_GetLongPathNameEx(HPATHL hpth_in_out) DWORD const _len = GetLongPathNameW(StrgGet(hstr_io), NULL, 0); if (!_len) { - //MsgBoxLastError(L"Path_GetLongPathNameEx()", 0); + //InfoBoxLastError(L"Path_GetLongPathNameEx()", 0); return 0; } LPWSTR const buf = StrgWriteAccessBuf(hstr_io, _len); diff --git a/src/Styles.c b/src/Styles.c index 96f064c5e..b88eb2c7e 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -1280,7 +1280,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) if ((pLexNew->lexerID > SCLEX_NULL) && (iNewLexer != pLexNew->lexerID)) { WCHAR msg[256] = { L'\0' }; StringCchPrintf(msg, COUNTOF(msg), L"Failed to set desired Lexer (#%i), got Lexer #%i!", pLexNew->lexerID, iNewLexer); - MsgBoxLastError(msg, ERROR_DLL_INIT_FAILED); + InfoBoxLastError(msg, ERROR_DLL_INIT_FAILED); } #endif diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 362b9137d..06bd8351b 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -203,7 +203,6 @@ typedef enum BUFFER_SIZES { LARGE_BUFFER = 512, HUGE_BUFFER = 1024, XHUGE_BUFFER = 2048, - XXXL_BUFFER = 4096, EDGELINE_NUM_LIMIT = 256, ANSI_CHAR_BUFFER = 258,