1 2 // MusicPlayer2.h : PROJECT_NAME 应用程序的主头文件 3 // 4 5 #pragma once 6 7 #ifndef __AFXWIN_H__ 8 #error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件" 9 #endif 10 11 #include "resource.h" // 主符号 12 #include "CommonData.h" 13 #include "AcceleratorRes.h" 14 #include "LastFM.h" 15 #include "StrTable.h" 16 #include "MenuMgr.h" 17 #include "IconMgr.h" 18 #include "ChinesePingyinRes.h" 19 20 // CMusicPlayerApp: 21 // 有关此类的实现,请参阅 MusicPlayer2.cpp 22 // 23 24 class CMusicPlayerApp : public CWinApp 25 { 26 public: 27 CMusicPlayerApp(); 28 29 wstring m_module_dir; //当前程序exe文件所在目录 30 wstring m_appdata_dir; 31 wstring m_config_dir; 32 wstring m_local_dir; //当前目录(debug模式下为.\,release模式下为exe文件所在目录) 33 wstring m_playlist_dir; //播放列表目录 34 wstring m_config_path; //配置文件的路径 35 wstring m_song_data_path; //储存所有歌曲信息数据文件的路径 36 wstring m_recent_list_dat_path; // 存储 “最近播放列表”列表(std::list<ListItem>)的路径 37 // 以下三项不再使用,但路径留作旧版兼容,新程序不再创建这三个文件 38 wstring m_recent_path_dat_path; //"recent_path.dat"文件的路径 39 wstring m_recent_playlist_data_path; 40 wstring m_recent_medialib_playlist_path; 41 42 wstring m_desktop_path; //桌面的路径 43 wstring m_module_path_reg; //程序exe文件的路径 44 //wstring m_temp_path; //临时文件夹的路径 45 wstring m_lastfm_path; ///存储Last.fm数据的路径 46 wstring m_ui_data_path; //用户自定义界面数据的路径 47 48 vector<DeviceInfo> m_output_devices; //播放设备的信息 49 50 vector<CRect> m_screen_rects; // 屏幕的范围 51 52 LyricSettingData m_lyric_setting_data; //“选项设置”对话框中“歌词设置”中的数据 53 ApperanceSettingData m_app_setting_data; //“选项设置”对话框中“外观设置”中的数据 54 GeneralSettingData m_general_setting_data; //“选项设置”对话框中“常规设置”中的数据 55 PlaySettingData m_play_setting_data; //“选项设置”对话框中“播放设置”中的数据 56 NonCategorizedSettingData m_nc_setting_data; //未分类的设置数据 57 GlobalHotKeySettingData m_hot_key_setting_data; //“全局快捷键”设置 58 MediaLibSettingData m_media_lib_setting_data; //“媒体库”设置 59 CAcceleratorRes m_accelerator_res; 60 CChinesePingyinRes m_chinese_pingyin_res; 61 62 StrTable m_str_table; // 实际上负责language manger 63 // IconMgr比MenuMgr先构造,后析构,虽然懒加载下不是必须不过语义应当如此 64 IconMgr m_icon_mgr; // 负责图标句柄缓存与懒加载 65 MenuMgr m_menu_mgr; 66 67 UIData m_ui_data; 68 FontSet m_font_set; //字体资源 69 ImageSet m_image_set; //图片资源 70 71 int m_cmd{}; 72 73 int m_fps{}; 74 75 wstring m_window_title; // 窗口的标题 76 77 volatile bool m_lyric_download_dialog_exit{ true }; //用于指示歌词下载对话框已经退出 78 volatile bool m_batch_download_dialog_exit{ true }; //用于指示歌词批量下载对话框已经退出 79 volatile bool m_cover_download_dialog_exit{ true }; //用于指示歌词下载对话框已经退出 80 volatile bool m_format_convert_dialog_exit{ true }; //用于指示格式对话框已经退出 81 MediaUpdateThreadPara m_media_update_para; 82 83 bool m_module_dir_writable{ true }; //指示程序所在目录是否可写 84 85 void SaveSongData(); //将所有歌曲信息以序列化的方式保存到文件 86 87 void CheckUpdate(bool message); 88 void CheckUpdateInThread(bool message); //在后台线程中检查更新 89 90 void LoadGlobalConfig(); 91 void SaveGlobalConfig(); 92 void SaveConfig(); 93 void LoadConfig(); 94 95 96 void LoadImgResource(); 97 98 int DPI(int pixel); //将一个像素值进行DPI变换 99 int DPI(double pixel); 100 //进行DPI变换后四舍五入处理 101 //round:round为0.5时四舍五入,round为0.4时为五舍六入 102 int DPIRound(double pixel, double round = 0.5); //对结果进行四舍五入处理 103 void GetDPIFromWindow(CWnd* pWnd); 104 GetDPI()105 int GetDPI() const 106 { 107 return m_dpi; 108 } 109 110 //获取系统信息文本 111 wstring GetSystemInfoString(); 112 113 void SetAutoRun(bool auto_run); 114 bool GetAutoRun(); 115 116 117 void WriteLog(const wstring& log_str, int log_type = NonCategorizedSettingData::LT_ERROR); 118 119 //开启一个后台线程并更新媒体库 120 // force为true时强制重新获取媒体库文件夹下的所有歌曲元数据,false时获取修改时间改变的歌曲元数据 121 void StartUpdateMediaLib(bool force); IsMeidaLibUpdating()122 bool IsMeidaLibUpdating() const { return m_media_lib_updating; } IsCheckingForUpdate()123 bool IsCheckingForUpdate() const { return m_checking_update; } //是否正在检查更新 124 125 void AutoSelectNotifyIcon(); 126 HICON GetNotifyIncon(int index); 127 128 bool IsScintillaLoaded() const; 129 130 LastFM m_lastfm; 131 void LoadLastFMData(); 132 void SaveLastFMData(); 133 void UpdateLastFMNowPlaying(); 134 void UpdateLastFMFavourite(bool favourite); 135 void LastFMScrobble(); 136 137 //更新UI中的媒体库项目 138 void UpdateUiMeidaLibItems(); 139 140 private: 141 void LoadSongData(); 142 143 static LRESULT CALLBACK MultiMediaKeyHookProc(int nCode, WPARAM wParam, LPARAM lParam); 144 static UINT CheckUpdateThreadFunc(LPVOID lpParam); //启动时检查更新线程函数 145 static UINT UpdateLastFMNowPlayingFunProc(LPVOID lpParam); 146 static UINT UpdateLastFMFavouriteFunProc(LPVOID lpParam); 147 static UINT LastFMScrobbleFunProc(LPVOID lpParam); 148 149 private: 150 HHOOK m_multimedia_key_hook = NULL; 151 152 int m_dpi{}; 153 154 vector<wstring> m_def_lang_list; // 线程启动时的默认UI语言列表(仅用于GetSystemInfoString) 155 156 ULONG_PTR m_gdiplusToken{}; 157 bool m_media_lib_updating{ false }; 158 bool m_checking_update{ false }; //是否正在检查更新 159 160 HMODULE m_hScintillaModule{}; 161 162 CWinThread* m_media_lib_update_thread{}; 163 164 // 重写 165 public: 166 virtual BOOL InitInstance(); 167 168 // 实现 169 170 DECLARE_MESSAGE_MAP() 171 afx_msg void OnHelp(); 172 virtual int ExitInstance(); 173 afx_msg void OnHelpUpdateLog(); 174 afx_msg void OnHelpCustomUi(); 175 afx_msg void OnHelpFaq(); 176 }; 177 178 extern CMusicPlayerApp theApp; 179