Skip to content

Commit

Permalink
新增使用桌面背景作为背景的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Oct 20, 2020
1 parent 623d0f7 commit dbafb08
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 6 deletions.
13 changes: 13 additions & 0 deletions MusicPlayer2/AppearanceSettingDlg.cpp
Expand Up @@ -99,6 +99,9 @@ void CAppearanceSettingDlg::SetControlEnable()
m_back_transparency_slid.EnableWindow(m_data.enable_background);
m_background_gauss_blur_chk.EnableWindow(m_data.enable_background && m_data.album_cover_as_background);
m_gauss_blur_radius_sld.EnableWindow(m_data.enable_background && m_data.album_cover_as_background && m_data.background_gauss_blur);

m_default_background_edit.EnableWindow(m_data.enable_background && !m_data.use_desktop_background);
EnableDlgCtrl(IDC_USE_DESKTOP_BACKGROUND_CHECK, m_data.enable_background);
}

void CAppearanceSettingDlg::CalculateNotifyIconPreviewRect()
Expand Down Expand Up @@ -166,6 +169,7 @@ BEGIN_MESSAGE_MAP(CAppearanceSettingDlg, CTabDlg)
ON_BN_CLICKED(IDC_NOTIFY_ICON_AUTO_ADAPT_CHECK, &CAppearanceSettingDlg::OnBnClickedNotifyIconAutoAdaptCheck)
ON_BN_CLICKED(IDC_BTN_ROUND_CORNERS_CHECK, &CAppearanceSettingDlg::OnBnClickedBtnRoundCornersCheck)
ON_MESSAGE(WM_EDIT_BROWSE_CHANGED, &CAppearanceSettingDlg::OnEditBrowseChanged)
ON_BN_CLICKED(IDC_USE_DESKTOP_BACKGROUND_CHECK, &CAppearanceSettingDlg::OnBnClickedUseDesktopBackgroundCheck)
END_MESSAGE_MAP()


Expand Down Expand Up @@ -267,6 +271,7 @@ BOOL CAppearanceSettingDlg::OnInitDialog()
m_default_background_edit.SetWindowText(m_data.default_background.c_str());
CString szFilter = CCommon::LoadText(IDS_IMAGE_FILE_FILTER);
m_default_background_edit.EnableFileBrowseButton(NULL, szFilter);
CheckDlgButton(IDC_USE_DESKTOP_BACKGROUND_CHECK, m_data.use_desktop_background);

m_alignment_combo.AddString(CCommon::LoadText(IDS_ALIGN_LEFT));
m_alignment_combo.AddString(CCommon::LoadText(IDS_ALIGN_RIGHT));
Expand Down Expand Up @@ -738,3 +743,11 @@ afx_msg LRESULT CAppearanceSettingDlg::OnEditBrowseChanged(WPARAM wParam, LPARAM
}
return 0;
}


void CAppearanceSettingDlg::OnBnClickedUseDesktopBackgroundCheck()
{
// TODO: 在此添加控件通知处理程序代码
m_data.use_desktop_background = (IsDlgButtonChecked(IDC_USE_DESKTOP_BACKGROUND_CHECK) != 0);
SetControlEnable();
}
2 changes: 2 additions & 0 deletions MusicPlayer2/AppearanceSettingDlg.h
Expand Up @@ -140,4 +140,6 @@ class CAppearanceSettingDlg : public CTabDlg
afx_msg void OnBnClickedBtnRoundCornersCheck();
protected:
afx_msg LRESULT OnEditBrowseChanged(WPARAM wParam, LPARAM lParam);
public:
afx_msg void OnBnClickedUseDesktopBackgroundCheck();
};
1 change: 1 addition & 0 deletions MusicPlayer2/CPlayerUIBase.cpp
Expand Up @@ -476,6 +476,7 @@ void CPlayerUIBase::DrawBackground()
}
else
{
CSingleLock sync(&m_ui_data.default_background_sync, TRUE);
//MemDC.FillSolidRect(0, 0, m_draw_rect.Width(), m_draw_rect.Height(), GetSysColor(COLOR_BTNFACE)); //给缓冲DC的绘图区域填充对话框的背景颜色
m_draw.DrawBitmap(m_ui_data.default_background, CPoint(0, 0), m_draw_rect.Size(), CDrawCommon::StretchMode::FILL);
}
Expand Down
14 changes: 14 additions & 0 deletions MusicPlayer2/Common.cpp
Expand Up @@ -1605,3 +1605,17 @@ int CCommon::Random(int min, int max)
return _rand;
}

CString CCommon::GetDesktopBackgroundPath()
{
CString path;
CRegKey key;
if (key.Open(HKEY_CURRENT_USER, _T("Control Panel\\Desktop\\")) == ERROR_SUCCESS)
{
TCHAR buff[MAX_PATH]{};
ULONG size{ MAX_PATH };
key.QueryStringValue(_T("WallPaper"), buff, &size);
path = buff;
}
return path;
}

2 changes: 2 additions & 0 deletions MusicPlayer2/Common.h
Expand Up @@ -379,6 +379,8 @@ class CCommon

static int Random(int min, int max); //生成一个随机数,范围是大于或等于min,小于max

static CString GetDesktopBackgroundPath(); //获取桌面壁纸的路径

};

template<class T>
Expand Down
4 changes: 4 additions & 0 deletions MusicPlayer2/CommonData.h
Expand Up @@ -252,6 +252,8 @@ struct ApperanceSettingData
wstring default_background; //默认的背景图片

int playlist_width_percent{ 50 }; //主界面播放列表宽度的百分比

bool use_desktop_background{ false }; //使用桌面壁纸作为背景
};

struct GeneralSettingData
Expand Down Expand Up @@ -502,8 +504,10 @@ struct UIData
int draw_area_width; //绘图区的宽度
int draw_area_height; //绘图区的高度
CImage default_background; //默认的背景
CCriticalSection default_background_sync;
};


struct MenuSet
{
CMenu m_main_menu; //菜单栏上的菜单
Expand Down
Binary file modified MusicPlayer2/MusicPlayer2.rc
Binary file not shown.
35 changes: 31 additions & 4 deletions MusicPlayer2/MusicPlayerDlg.cpp
Expand Up @@ -363,6 +363,7 @@ void CMusicPlayerDlg::SaveConfig()
ini.WriteBool(L"config", L"button_round_corners", theApp.m_app_setting_data.button_round_corners);
ini.WriteInt(L"config", L"playlist_width_percent", theApp.m_app_setting_data.playlist_width_percent);
ini.WriteString(L"config", L"default_background", theApp.m_app_setting_data.default_background);
ini.WriteBool(L"config", L"use_desktop_background", theApp.m_app_setting_data.use_desktop_background);

ini.WriteInt(L"config", L"volum_step", theApp.m_nc_setting_data.volum_step);
ini.WriteInt(L"config", L"mouse_volum_step", theApp.m_nc_setting_data.mouse_volum_step);
Expand Down Expand Up @@ -511,6 +512,7 @@ void CMusicPlayerDlg::LoadConfig()
theApp.m_app_setting_data.button_round_corners = ini.GetBool(L"config", L"button_round_corners", false);
theApp.m_app_setting_data.playlist_width_percent = ini.GetInt(L"config", L"playlist_width_percent", 50);
theApp.m_app_setting_data.default_background = ini.GetString(L"config", L"default_background", DEFAULT_BACKGROUND_NAME);
theApp.m_app_setting_data.use_desktop_background = ini.GetBool(L"config", L"use_desktop_background", false);

theApp.m_nc_setting_data.volum_step = ini.GetInt(L"config", L"volum_step", 3);
theApp.m_nc_setting_data.mouse_volum_step = ini.GetInt(L"config", L"mouse_volum_step", 2);
Expand Down Expand Up @@ -1001,7 +1003,8 @@ void CMusicPlayerDlg::ApplySettings(const COptionsDlg& optionDlg)
//bool timer_interval_changed{ theApp.m_app_setting_data.ui_refresh_interval != optionDlg.m_tab2_dlg.m_data.ui_refresh_interval };
bool notify_icon_changed{ theApp.m_app_setting_data.notify_icon_selected != optionDlg.m_tab2_dlg.m_data.notify_icon_selected };
bool media_lib_display_item_changed{ theApp.m_media_lib_setting_data.display_item != optionDlg.m_media_lib_dlg.m_data.display_item };
bool default_background_changed{ theApp.m_app_setting_data.default_background != optionDlg.m_tab2_dlg.m_data.default_background };
bool default_background_changed{ theApp.m_app_setting_data.default_background != optionDlg.m_tab2_dlg.m_data.default_background
|| theApp.m_app_setting_data.use_desktop_background != optionDlg.m_tab2_dlg.m_data.use_desktop_background };
bool search_box_background_transparent_changed{ theApp.m_lyric_setting_data.cortana_transparent_color != optionDlg.m_tab1_dlg.m_data.cortana_transparent_color };

theApp.m_lyric_setting_data = optionDlg.m_tab1_dlg.m_data;
Expand Down Expand Up @@ -1576,8 +1579,14 @@ void CMusicPlayerDlg::UpdateABRepeatToolTip()

void CMusicPlayerDlg::LoadDefaultBackground()
{
CSingleLock sync(&theApp.m_ui_data.default_background_sync, TRUE);
theApp.m_ui_data.default_background.Destroy();
theApp.m_ui_data.default_background.Load(theApp.m_app_setting_data.default_background.c_str());
CString background_img;
if (theApp.m_app_setting_data.use_desktop_background)
background_img = CCommon::GetDesktopBackgroundPath();
else
background_img = theApp.m_app_setting_data.default_background.c_str();
theApp.m_ui_data.default_background.Load(background_img);
if (theApp.m_ui_data.default_background.IsNull())
theApp.m_ui_data.default_background.Load((theApp.m_local_dir + DEFAULT_BACKGROUND_NAME).c_str());
if (theApp.m_ui_data.default_background.IsNull())
Expand Down Expand Up @@ -2121,6 +2130,12 @@ void CMusicPlayerDlg::OnTimer(UINT_PTR nIDEvent)
m_no_lbtnup = false;
}

else if (nIDEvent == INGORE_COLOR_CHANGE_TIMER_ID)
{
KillTimer(INGORE_COLOR_CHANGE_TIMER_ID);
m_ignore_color_change = false;
}

CMainDialogBase::OnTimer(nIDEvent);
}

Expand Down Expand Up @@ -3964,8 +3979,20 @@ void CMusicPlayerDlg::OnColorizationColorChanged(DWORD dwColorizationColor, BOOL
// _WIN32_WINNT 符号必须 >= 0x0600。
// TODO: 在此添加消息处理程序代码和/或调用默认值

//响应主题颜色改变消息
ThemeColorChanged();
if (!m_ignore_color_change)
{
//响应主题颜色改变消息
ThemeColorChanged();

//如果设置了使用桌面背景为背景,则重新载入背景图片
if (theApp.m_app_setting_data.use_desktop_background)
LoadDefaultBackground();

//响应此消息后设置定时器,两秒内不再响应此消息
m_ignore_color_change = true;
SetTimer(INGORE_COLOR_CHANGE_TIMER_ID, 2000, NULL);
}


CMainDialogBase::OnColorizationColorChanged(dwColorizationColor, bOpacity);
}
Expand Down
3 changes: 2 additions & 1 deletion MusicPlayer2/MusicPlayerDlg.h
Expand Up @@ -154,7 +154,8 @@ class CMusicPlayerDlg : public CMainDialogBase
CPlayerToolBar m_playlist_toolbar;

bool m_no_lbtnup{ false }; //当它为true时,不响应WM_LBUTTONUP消息
enum { DELAY_TIMER_ID = 1200 };
bool m_ignore_color_change{ false }; //当它为true时,不响应颜色变化,防止短时间内重复收到主题颜色变化的消息
enum { DELAY_TIMER_ID = 1200, INGORE_COLOR_CHANGE_TIMER_ID = 1201 };

private:
void SaveConfig(); //保存设置到ini文件
Expand Down
3 changes: 2 additions & 1 deletion MusicPlayer2/resource.h
Expand Up @@ -1001,6 +1001,7 @@
#define IDC_FILE_TYPE_CHECK 1180
#define IDC_DEFAULT_BACKGROUND_PATH_EDIT 1182
#define IDC_INSERT_RADIO 1183
#define IDC_USE_DESKTOP_BACKGROUND_CHECK 1184
#define ID_32771 32771
#define ID_32772 32772
#define ID_OPEN 32773
Expand Down Expand Up @@ -1412,7 +1413,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 505
#define _APS_NEXT_COMMAND_VALUE 33219
#define _APS_NEXT_CONTROL_VALUE 1184
#define _APS_NEXT_CONTROL_VALUE 1185
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

0 comments on commit dbafb08

Please sign in to comment.