Fix exception/crash on Windows Server Core 2022 (Datacenter)
The exception/crash occurs due to the unsupported icon format in Windows Server Core 2022 (due to the lack of a graphical library). The commit tries to make loading icons fail-safe, and it represents a balance between the functionality of loading icons and the minimal graphic support required for Notepad++: In the event of loading problems in a typical Windows version with complete graphical library support (which is unlikely but possible), users will receive alerts, and the ICO ID in question will be displayed in the caption. However, under Windows Server Core 2022, multiple alert message boxes may appear during Notepad++ launch, but they can be stopped after the first one, allowing the user to use Notepad++ normally. 3 choices on the alert message: "Yes" for ignoring error(s) and launch Notepad++, "No" for stop lauching Notepad++ and quit it. "Cancel" for displaying all message error with the loading failure of ICO ID in caption, and launch Notepad++. Fix #15313, close #15315
This commit is contained in:
parent
965e24859f
commit
46c5a0c226
|
@ -43,16 +43,47 @@ void IconList::create(int iconSize, HINSTANCE hInst, int* iconIDArray, int iconI
|
|||
addIcon(iconIDArray[i], iconSize, iconSize);
|
||||
}
|
||||
|
||||
void IconList::addIcon(int iconID, int cx, int cy) const
|
||||
void IconList::addIcon(int iconID, int cx, int cy, int failIconID) const
|
||||
{
|
||||
HICON hIcon = nullptr;
|
||||
DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(iconID), cx, cy, &hIcon, LR_DEFAULTSIZE);
|
||||
|
||||
if (!hIcon)
|
||||
throw std::runtime_error("IconList::addIcon : LoadIcon() function return null");
|
||||
{
|
||||
static bool ignoreWarning = false;
|
||||
int userAnswer = 0;
|
||||
if (!ignoreWarning)
|
||||
{
|
||||
userAnswer = ::MessageBoxA(NULL, "IconList::addIcon : LoadIcon() function return null.\nIgnore warning?", std::to_string(iconID).c_str(), MB_YESNOCANCEL | MB_ICONWARNING);
|
||||
ignoreWarning = userAnswer == IDYES;
|
||||
}
|
||||
|
||||
ImageList_AddIcon(_hImglst, hIcon);
|
||||
::DestroyIcon(hIcon);
|
||||
if (userAnswer == IDNO)
|
||||
{
|
||||
throw std::runtime_error("IconList::addIcon : LoadIcon() function returns null");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (failIconID != -1)
|
||||
{
|
||||
HBITMAP hBmp = static_cast<HBITMAP>(::LoadImage(_hInst, MAKEINTRESOURCE(failIconID), IMAGE_BITMAP, cx, cy, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT));
|
||||
if (hBmp != nullptr)
|
||||
{
|
||||
::ImageList_AddMasked(_hImglst, hBmp, ::GetSysColor(COLOR_3DFACE));
|
||||
::DeleteObject(hBmp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
constexpr int IDI_ICONABSENT = 104; // check resource.h for correct id
|
||||
DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(IDI_ICONABSENT), cx, cy, &hIcon);
|
||||
}
|
||||
}
|
||||
|
||||
if (hIcon != nullptr)
|
||||
{
|
||||
::ImageList_AddIcon(_hImglst, hIcon);
|
||||
::DestroyIcon(hIcon);
|
||||
}
|
||||
}
|
||||
|
||||
void IconList::addIcon(HICON hIcon) const
|
||||
|
@ -103,20 +134,20 @@ void ToolBarIcons::reInit(int size)
|
|||
{
|
||||
if (_tbiis[i]._defaultIcon != -1)
|
||||
{
|
||||
_iconListVector[HLIST_DEFAULT].addIcon(_tbiis[i]._defaultIcon, size, size);
|
||||
_iconListVector[HLIST_DISABLE].addIcon(_tbiis[i]._grayIcon, size, size);
|
||||
_iconListVector[HLIST_DEFAULT2].addIcon(_tbiis[i]._defaultIcon2, size, size);
|
||||
_iconListVector[HLIST_DISABLE2].addIcon(_tbiis[i]._grayIcon2, size, size);
|
||||
_iconListVector[HLIST_DEFAULT].addIcon(_tbiis[i]._defaultIcon, size, size, _tbiis[i]._stdIcon);
|
||||
_iconListVector[HLIST_DISABLE].addIcon(_tbiis[i]._grayIcon, size, size, _tbiis[i]._stdIcon);
|
||||
_iconListVector[HLIST_DEFAULT2].addIcon(_tbiis[i]._defaultIcon2, size, size, _tbiis[i]._stdIcon);
|
||||
_iconListVector[HLIST_DISABLE2].addIcon(_tbiis[i]._grayIcon2, size, size, _tbiis[i]._stdIcon);
|
||||
|
||||
_iconListVector[HLIST_DEFAULT_DM].addIcon(_tbiis[i]._defaultDarkModeIcon, size, size);
|
||||
_iconListVector[HLIST_DISABLE_DM].addIcon(_tbiis[i]._grayDarkModeIcon, size, size);
|
||||
_iconListVector[HLIST_DEFAULT_DM2].addIcon(_tbiis[i]._defaultDarkModeIcon2, size, size);
|
||||
_iconListVector[HLIST_DISABLE_DM2].addIcon(_tbiis[i]._grayDarkModeIcon2, size, size);
|
||||
_iconListVector[HLIST_DEFAULT_DM].addIcon(_tbiis[i]._defaultDarkModeIcon, size, size, _tbiis[i]._stdIcon);
|
||||
_iconListVector[HLIST_DISABLE_DM].addIcon(_tbiis[i]._grayDarkModeIcon, size, size, _tbiis[i]._stdIcon);
|
||||
_iconListVector[HLIST_DEFAULT_DM2].addIcon(_tbiis[i]._defaultDarkModeIcon2, size, size, _tbiis[i]._stdIcon);
|
||||
_iconListVector[HLIST_DISABLE_DM2].addIcon(_tbiis[i]._grayDarkModeIcon2, size, size, _tbiis[i]._stdIcon);
|
||||
}
|
||||
}
|
||||
|
||||
// Add dynamic icons (from plugins)
|
||||
for (auto i : _moreCmds)
|
||||
for (const auto& i : _moreCmds)
|
||||
{
|
||||
_iconListVector[HLIST_DEFAULT].addIcon(i._hIcon);
|
||||
_iconListVector[HLIST_DISABLE].addIcon(i._hIcon);
|
||||
|
|
|
@ -39,7 +39,7 @@ public :
|
|||
};
|
||||
|
||||
HIMAGELIST getHandle() const {return _hImglst;};
|
||||
void addIcon(int iconID, int cx = 32, int cy = 32) const;
|
||||
void addIcon(int iconID, int cx = 16, int cy = 16, int failIconID = -1) const;
|
||||
void addIcon(HICON hIcon) const;
|
||||
|
||||
bool changeIcon(size_t index, const TCHAR *iconLocation) const;
|
||||
|
|
Loading…
Reference in New Issue