Merge pull request #2737 from RaiKoHoff/Dev_NewFeatures

Enhanced internal icon/bitmap handling
This commit is contained in:
Rainer Kottenhoff 2020-08-30 12:45:27 +02:00 committed by GitHub
commit d8af8901e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 16 deletions

View File

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

View File

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

View File

@ -356,7 +356,6 @@ typedef struct _globals_t
HICON hIconMsgError;
HICON hIconMsgQuest;
HICON hIconMsgShield;
HICON hIconMsgShieldSmall;
//HICON hIconMsgWinLogo;
HWND hwndDlgFindReplace;
HWND hwndDlgCustomizeSchemes;