Skip to content

Commit bd59cca

Browse files
authored
Merge bd07bfa into 4ebeadd
2 parents 4ebeadd + bd07bfa commit bd59cca

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Src/Lib/ResourceHelper.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,14 @@ HICON CreateDisabledIcon( HICON hIcon, int iconSize )
384384
}
385385

386386
// Loads an image file into a bitmap and optionally resizes it
387-
HBITMAP LoadImageFile( const wchar_t *path, const SIZE *pSize, bool bUseAlpha, bool bPremultiply, std::vector<unsigned int> *pButtonAnim )
387+
HBITMAP LoadImageFile( const wchar_t *path, const SIZE *pSize, bool bUseAlpha, bool bPremultiply, std::vector<unsigned int> *pButtonAnim, UINT dpi )
388388
{
389389
HBITMAP srcBmp=NULL;
390390
if (_wcsicmp(PathFindExtension(path),L".bmp")==0)
391391
{
392392
srcBmp=(HBITMAP)LoadImage(NULL,path,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
393393
}
394-
if (srcBmp && !pSize)
394+
if (srcBmp && !pSize && !dpi)
395395
return srcBmp;
396396
CComPtr<IWICImagingFactory> pFactory;
397397
if (FAILED(pFactory.CoCreateInstance(CLSID_WICImagingFactory)))
@@ -482,6 +482,12 @@ HBITMAP LoadImageFile( const wchar_t *path, const SIZE *pSize, bool bUseAlpha, b
482482
else
483483
frameHeightD=frameWidthD*frameHeightS/frameWidthS;
484484
}
485+
486+
if (dpi)
487+
{
488+
frameWidthD=ScaleForDpi(dpi,frameWidthD);
489+
frameHeightD=ScaleForDpi(dpi,frameHeightD);
490+
}
485491
}
486492

487493
BITMAPINFO bi={0};
@@ -946,7 +952,12 @@ UINT GetDpi(HWND hwnd)
946952
return dpi;
947953
}
948954

955+
int ScaleForDpi(UINT dpi, int value)
956+
{
957+
return MulDiv(value, dpi, USER_DEFAULT_SCREEN_DPI);
958+
}
959+
949960
int ScaleForDpi(HWND hwnd, int value)
950961
{
951-
return MulDiv(value, GetDpi(hwnd), USER_DEFAULT_SCREEN_DPI);
962+
return ScaleForDpi(GetDpi(hwnd), value);
952963
}

Src/Lib/ResourceHelper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ HICON ShExtractIcon( const char *path, int index, int iconSize );
3535
HBITMAP BitmapFromIcon( HICON hIcon, int iconSize, unsigned int **pBits, bool bDestroyIcon );
3636

3737
// Loads an image file into a bitmap and optionally resizes it
38-
HBITMAP LoadImageFile( const wchar_t *path, const SIZE *pSize, bool bUseAlpha, bool bPremultiply, std::vector<unsigned int> *pButtonAnim );
38+
HBITMAP LoadImageFile( const wchar_t *path, const SIZE *pSize, bool bUseAlpha, bool bPremultiply, std::vector<unsigned int> *pButtonAnim, UINT dpi=0 );
3939

4040
// Loads a bitmap from a IMAGE resource
4141
HBITMAP LoadImageResource( HMODULE hModule, const wchar_t *name, bool bTopDown, bool bPremultiply );
@@ -88,6 +88,8 @@ HFONT CreateFontSetting( const wchar_t *fontStr, int dpi );
8888
// Return DPI of given window (or system DPI on older systems)
8989
UINT GetDpi(HWND hwnd = nullptr);
9090

91+
// Scale given value according to given DPI
92+
int ScaleForDpi(UINT dpi, int value);
9193
// Scale given value according to DPI of window
9294
int ScaleForDpi(HWND hwnd, int value);
9395

Src/StartMenu/StartMenuDLL/StartButton.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,16 @@ void CStartButton::LoadBitmap( void )
526526
}
527527
else
528528
{
529+
int dpi=GetDpi(GetParent());
529530
bool bResource=false;
530531
std::vector<unsigned int> buttonAnim;
531532
if (*path)
532533
{
533-
m_Bitmap=LoadImageFile(path,&size,true,true,&buttonAnim);
534+
m_Bitmap=LoadImageFile(path,&size,true,true,&buttonAnim,dpi);
534535
}
535536
if (!m_Bitmap)
536537
{
537538
int id;
538-
int dpi=GetDpi(GetParent());
539539
if (dpi<120)
540540
id=IDB_BUTTON96;
541541
else if (dpi<144)

0 commit comments

Comments
 (0)