Skip to content

Commit

Permalink
添加IconMgr类重构HICON缓存 part05
Browse files Browse the repository at this point in the history
  • Loading branch information
lrisora committed Jun 20, 2024
1 parent ccb67e1 commit cf53bbc
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 43 deletions.
4 changes: 2 additions & 2 deletions MusicPlayer2/BaseDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void CBaseDialog::ReLoadLayoutResource()

void CBaseDialog::SetIcon(IconMgr::IconType type, BOOL bBigIcon)
{
if (bBigIcon)
CDialog::SetIcon(theApp.m_icon_mgr.GetHICON(type, IconMgr::IconStyle::IS_OutlinedDark, IconMgr::IconSize::IS_Default), TRUE);
if (bBigIcon) // 大图标需要DPI32才足够清晰?
CDialog::SetIcon(theApp.m_icon_mgr.GetHICON(type, IconMgr::IconStyle::IS_OutlinedDark, IconMgr::IconSize::IS_DPI_32), TRUE);
else
CDialog::SetIcon(theApp.m_icon_mgr.GetHICON(type, IconMgr::IconStyle::IS_OutlinedDark, IconMgr::IconSize::IS_DPI_16), FALSE);
}
Expand Down
3 changes: 2 additions & 1 deletion MusicPlayer2/CTabCtrlEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ void CTabCtrlEx::AdjustTabWindowSize()
//为每个标签添加图标
if (m_icon_list.empty())
return;
CSize icon_size = IconMgr::GetIconSize(IconMgr::IconSize::IS_DPI_16);
CImageList ImageList;
ImageList.Create(theApp.DPI(16), theApp.DPI(16), ILC_COLOR32 | ILC_MASK, 2, 2);
ImageList.Create(icon_size.cx, icon_size.cy, ILC_COLOR32 | ILC_MASK, 2, 2);
for (auto icon_type : m_icon_list)
{
HICON hIcon = theApp.m_icon_mgr.GetHICON(icon_type, IconMgr::IconStyle::IS_OutlinedDark, IconMgr::IconSize::IS_DPI_16);
Expand Down
5 changes: 0 additions & 5 deletions MusicPlayer2/DrawCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,6 @@ void CDrawCommon::ImageResize(const wstring& path_src, const wstring& path_dest,
ImageResize(imSrc, path_dest, size, type);
}

HICON CDrawCommon::LoadIconResource(UINT id, int width, int height)
{
return (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(id), IMAGE_ICON, width, height, 0);
}

HBITMAP CDrawCommon::CopyBitmap(HBITMAP hSourceHbitmap)
{
CDC sourceDC;
Expand Down
2 changes: 0 additions & 2 deletions MusicPlayer2/DrawCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ class CDrawCommon
static void ImageResize(const CImage& img_src, const wstring& path_dest, int size, ImageType type);
static void ImageResize(const wstring& path_src, const wstring& path_dest, int size, ImageType type);

static HICON LoadIconResource(UINT id, int width, int height);

//复制一个bitmap (http://wupei.j2megame.org/archives/86)
//(这两个函数未测试成功,复制的图片为全黑色,原因暂时未知,后面再调查)
static HBITMAP CopyBitmap(HBITMAP hSourceHbitmap);
Expand Down
17 changes: 6 additions & 11 deletions MusicPlayer2/FolderExploreDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ BOOL CFolderExploreDlg::OnInitDialog()
// TODO: 在此添加额外的初始化

//为树控件设置图标
CImageList image_list;
image_list.Create(theApp.DPI(16), theApp.DPI(16), ILC_COLOR32 | ILC_MASK, 2, 2);
image_list.Add(CDrawCommon::LoadIconResource(IDI_EXPLORE_FOLDER, theApp.DPI(16), theApp.DPI(16)));
m_folder_explore_tree.SetImageList(&image_list, TVSIL_NORMAL);
image_list.Detach();
CSize icon_size = IconMgr::GetIconSize(IconMgr::IconSize::IS_DPI_16);
CImageList ImageList;
ImageList.Create(icon_size.cx, icon_size.cy, ILC_COLOR32 | ILC_MASK, 2, 2);
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Folder, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_DPI_16));
m_folder_explore_tree.SetImageList(&ImageList, TVSIL_NORMAL);
ImageList.Detach();

//设置行高
m_folder_explore_tree.SetItemHeight(theApp.DPI(22));
Expand All @@ -246,12 +247,6 @@ BOOL CFolderExploreDlg::OnInitDialog()
//即只有当标签切换到“文件夹浏览”时才填充数据,以加载“媒体库”对话框的打开速度
//ShowFolderTree();

////
//CImageList image_list1;
//image_list1.Create(theApp.DPI(16), theApp.DPI(16), ILC_COLOR32 | ILC_MASK, 2, 2);
//image_list1.Add(theApp.LoadIcon(IDI_FILE_ICON));
//m_song_list_ctrl.SetImageList(&image_list1, LVSIL_SMALL);

//初始化右侧列表
m_song_list_ctrl.SetExtendedStyle(m_song_list_ctrl.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_LABELTIP);
//CRect rc_song_list;
Expand Down
2 changes: 1 addition & 1 deletion MusicPlayer2/IconMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CSize IconMgr::GetIconSize(IconSize size)
case IS_DPI_20: case IS_DPI_20_Full_Screen: width = theApp.DPI(20); break;
case IS_DPI_32: case IS_DPI_32_Full_Screen: width = theApp.DPI(32); break;
case IS_ORG_512: width = 512; break;
default: width = 0; break; // 系统默认图标大小 SM_CXICON * SM_CYICON, 此时返回0
default: width = theApp.DPI(16); break; // 系统默认小图标大小 SM_CXICON * SM_CYICON
}
if (size == IS_DPI_16_Full_Screen || size == IS_DPI_20_Full_Screen || size == IS_DPI_32_Full_Screen)
width = static_cast<int>(width * CONSTVAL::FULL_SCREEN_ZOOM_FACTOR);
Expand Down
3 changes: 1 addition & 2 deletions MusicPlayer2/IconMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ class IconMgr

enum IconSize
{
IS_Default, // SM_CXICON * SM_CYICON
IS_DPI_16,
IS_DPI_16, // SM_CXICON * SM_CYICON
IS_DPI_16_Full_Screen,
IS_DPI_20,
IS_DPI_20_Full_Screen,
Expand Down
27 changes: 13 additions & 14 deletions MusicPlayer2/LyricEditDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,23 @@ BOOL CLyricEditDlg::OnInitDialog()
return -1; // fail to create
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
int icon_size = theApp.DPI(20);
if (icon_size < 32)
icon_size = CCommon::IconSizeNormalize(icon_size);

CSize icon_size = IconMgr::GetIconSize(IconMgr::IconSize::IS_DPI_20);
CImageList ImageList;
ImageList.Create(icon_size, icon_size, ILC_COLOR32 | ILC_MASK, 2, 2);
ImageList.Create(icon_size.cx, icon_size.cy, ILC_COLOR32 | ILC_MASK, 2, 2);

//通过ImageList对象加载图标作为工具栏的图标
//添加图标
ImageList.Add(CDrawCommon::LoadIconResource(IDI_ADD_TAG, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_REPLACE_TAG, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_DELETE_TAG, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_SAVE, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_PLAY_PAUSE, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_REW, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_FF, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_LOCATE_D, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_FIND, icon_size, icon_size));
ImageList.Add(CDrawCommon::LoadIconResource(IDI_REPLACE, icon_size, icon_size));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Le_Tag_Insert, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Le_Tag_Replace, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Le_Tag_Delete, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Le_Save, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Play_Pause, IconMgr::IconStyle::IS_Filled, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Rewind, IconMgr::IconStyle::IS_Filled, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Fast_Forward, IconMgr::IconStyle::IS_Filled, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Locate, IconMgr::IconStyle::IS_OutlinedDark, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Le_Find, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_DPI_20));
ImageList.Add(theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Le_Replace, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_DPI_20));
m_wndToolBar.GetToolBarCtrl().SetImageList(&ImageList);
ImageList.Detach();
SetToolbarCmdEnable();
Expand Down
2 changes: 1 addition & 1 deletion MusicPlayer2/MusicPlayer2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void CMusicPlayerApp::LoadConfig()
m_hot_key_setting_data.global_multimedia_key_enable = ini.GetBool(L"hot_key", L"global_multimedia_key_enable", false);
}

void CMusicPlayerApp::LoadIconResource()
void CMusicPlayerApp::LoadImgResource()
{
//加载图片资源
m_image_set.default_cover_img = CCommon::GetPngImageResource(IDB_DEFAULT_ALBUM_COVER);
Expand Down
2 changes: 1 addition & 1 deletion MusicPlayer2/MusicPlayer2.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CMusicPlayerApp : public CWinApp
void LoadConfig();


void LoadIconResource();
void LoadImgResource();

int DPI(int pixel); //将一个像素值进行DPI变换
int DPI(double pixel);
Expand Down
6 changes: 3 additions & 3 deletions MusicPlayer2/MusicPlayerDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const UINT WM_TASKBARCREATED{ ::RegisterWindowMessage(_T("TaskbarCreated")) };
CMusicPlayerDlg::CMusicPlayerDlg(wstring cmdLine, CWnd* pParent /*=NULL*/)
: m_cmdLine{ cmdLine }, CMainDialogBase(IDD_MUSICPLAYER2_DIALOG, pParent)
{
m_hIcon = theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_App, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_Default);
m_hIcon = theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_App, IconMgr::IconStyle::IS_Color, IconMgr::IconSize::IS_DPI_32);
m_path_edit.SetTooltopText(theApp.m_str_table.LoadText(L"UI_TIP_BTN_RECENT_FOLDER_OR_PLAYLIST").c_str());

//初始化UI
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void CMusicPlayerDlg::UpdatePlayPauseButton()
if (theApp.IsTaskbarInteractionEnabled())
{
HICON hIcon_play = theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Play, IconMgr::IconStyle::IS_Filled, IconMgr::IconSize::IS_DPI_16);
HICON hIcon_pause = theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Play_Pause, IconMgr::IconStyle::IS_Filled, IconMgr::IconSize::IS_DPI_16);
HICON hIcon_pause = theApp.m_icon_mgr.GetHICON(IconMgr::IconType::IT_Pause, IconMgr::IconStyle::IS_Filled, IconMgr::IconSize::IS_DPI_16);
if (CPlayer::GetInstance().IsPlaying() && !CPlayer::GetInstance().IsError())
{
//更新任务栏缩略图上“播放/暂停”的图标
Expand Down Expand Up @@ -1993,7 +1993,7 @@ BOOL CMusicPlayerDlg::OnInitDialog()
CMainDialogBase::OnInitDialog();

// 载入图标资源
theApp.LoadIconResource();
theApp.LoadImgResource();
// 载入字体资源
theApp.m_font_set.Init(theApp.m_str_table.GetDefaultFontName().c_str());

Expand Down

0 comments on commit cf53bbc

Please sign in to comment.