From c884f4c5155b8d6a37506506c861be2534edf18f Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Sun, 30 Aug 2020 12:28:46 +0200 Subject: [PATCH] + fix: enhanced internal icon/bitmap handling --- src/Dialogs.c | 15 +++++++-------- src/Notepad3.c | 11 ++++------- src/TypeDefs.h | 1 - 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/Dialogs.c b/src/Dialogs.c index 48d64840f..d0a96a2e8 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -4910,22 +4910,21 @@ static void _GetIconInfo(HICON hIcon, int* width, int* height, WORD* bitsPerPix) // ConvertIconToBitmap() // cx/cy = 0 => use resource width/height // -HBITMAP ConvertIconToBitmap(const HICON hIcon, const int cx, const int cy) +HBITMAP ConvertIconToBitmap(const HICON hIcon, int cx, int cy) { int wdc = cx; int hdc = cy; - if ((cx == 0) || (cy == 0)) { + if ((cx <= 0) || (cy <= 0)) { _GetIconInfo(hIcon, &wdc, &hdc, NULL); + cx = cy = 0; } - // increase & condense size - wdc <<= 4; hdc <<= 4; HDC const hScreenDC = GetDC(NULL); HBITMAP const hbmpTmp = CreateCompatibleBitmap(hScreenDC, wdc, hdc); HDC const hMemDC = CreateCompatibleDC(hScreenDC); - HBITMAP const hOldBmp = SelectObject(hMemDC, hbmpTmp); + HBITMAP const hOldBmp = SelectObject(hMemDC, hbmpTmp); // assign DrawIconEx(hMemDC, 0, 0, hIcon, wdc, hdc, 0, NULL, DI_NORMAL /*&~DI_DEFAULTSIZE*/); - SelectObject(hMemDC, hOldBmp); + SelectObject(hMemDC, hOldBmp); // restore UINT const copyFlags = LR_COPYDELETEORG | LR_COPYRETURNORG | LR_DEFAULTSIZE | LR_CREATEDIBSECTION; HBITMAP const hDibBmp = (HBITMAP)CopyImage((HANDLE)hbmpTmp, IMAGE_BITMAP, cx, cy, copyFlags); @@ -4960,12 +4959,12 @@ void SetUACIcon(HWND hwnd, const HMENU hMenu, const UINT nItem) int const cx = ScaleIntByDPI(GetSystemMetrics(SM_CXSMICON), dpi.x); int const cy = ScaleIntByDPI(GetSystemMetrics(SM_CYSMICON), dpi.y); - if (Globals.hIconMsgShieldSmall) + if (Globals.hIconMsgShield) { MENUITEMINFO mii = { 0 }; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_BITMAP; - mii.hbmpItem = ConvertIconToBitmap(Globals.hIconMsgShieldSmall, cx, cy); + mii.hbmpItem = ConvertIconToBitmap(Globals.hIconMsgShield, cx, cy); SetMenuItemInfo(hMenu, nItem, FALSE, &mii); } bInitialized = true; diff --git a/src/Notepad3.c b/src/Notepad3.c index 712399b96..beb2ef079 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -882,11 +882,11 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, // ---------------------------------------------------- // ICON_BIG - int const cxb = GetSystemMetrics(SM_CXICON); - int const cyb = GetSystemMetrics(SM_CYICON); + int const cxb = GetSystemMetrics(SM_CXICON) << 2; + int const cyb = GetSystemMetrics(SM_CYICON) << 2; // ICON_SMALL - int const cxs = GetSystemMetrics(SM_CXSMICON); - int const cys = GetSystemMetrics(SM_CYSMICON); + int const cxs = GetSystemMetrics(SM_CXSMICON) << 1; + int const cys = GetSystemMetrics(SM_CYSMICON) << 1; //UINT const fuLoad = LR_DEFAULTCOLOR | LR_SHARED; @@ -931,9 +931,6 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, if (!Globals.hIconMsgShield) { LoadIconWithScaleDown(NULL, IDI_SHIELD, cxb, cyb, &(Globals.hIconMsgShield)); } - if (!Globals.hIconMsgShieldSmall) { - LoadIconWithScaleDown(NULL, IDI_SHIELD, cxb, cyb, &(Globals.hIconMsgShieldSmall)); - } //if (!Globals.hIconMsgWinLogo) { // LoadIconWithScaleDown(NULL, IDI_WINLOGO, cxl, cyl, &(Globals.hIconMsgWinLogo)); //} diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 3add8a434..d99ec947a 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -356,7 +356,6 @@ typedef struct _globals_t HICON hIconMsgError; HICON hIconMsgQuest; HICON hIconMsgShield; - HICON hIconMsgShieldSmall; //HICON hIconMsgWinLogo; HWND hwndDlgFindReplace; HWND hwndDlgCustomizeSchemes;