@@ -166,6 +166,249 @@ const wchar_t* CommonDisplayItem::GetItemIniKeyName() const
166166 }
167167}
168168
169+ CString CommonDisplayItem::GetItemValueText (bool is_main_window) const
170+ {
171+ if (is_plugin)
172+ {
173+ return plugin_item->GetItemValueText ();
174+ }
175+ else
176+ {
177+ const PublicSettingData* cfg_data{};
178+ if (is_main_window)
179+ cfg_data = &theApp.m_main_wnd_data ;
180+ else
181+ cfg_data = &theApp.m_taskbar_data ;
182+ CString str_value;
183+ switch (item_type)
184+ {
185+ // 上传、下载、总网速
186+ case TDI_UP:
187+ case TDI_DOWN:
188+ case TDI_TOTAL_SPEED:
189+ {
190+ CString str_in_speed = CCommon::DataSizeToString (theApp.m_in_speed , *cfg_data);
191+ CString str_out_speed = CCommon::DataSizeToString (theApp.m_out_speed , *cfg_data);
192+ CString str_total_speed = CCommon::DataSizeToString (theApp.m_in_speed + theApp.m_out_speed , *cfg_data);
193+ if (!cfg_data->hide_unit || cfg_data->speed_unit == SpeedUnit::AUTO)
194+ {
195+ str_in_speed += _T (" /s" );
196+ str_out_speed += _T (" /s" );
197+ str_total_speed += _T (" /s" );
198+ }
199+ // 交换上传和下载位置
200+ if (is_main_window && theApp.m_main_wnd_data .swap_up_down )
201+ std::swap (str_in_speed, str_out_speed);
202+ if (item_type == TDI_UP)
203+ str_value = str_out_speed;
204+ else if (item_type == TDI_DOWN)
205+ str_value = str_in_speed;
206+ else
207+ str_value = str_total_speed;
208+ }
209+ break ;
210+ // CPU利用率
211+ case TDI_CPU:
212+ str_value = CCommon::UsageToString (theApp.m_cpu_usage , *cfg_data);
213+ break ;
214+ // 内存利用率
215+ case TDI_MEMORY:
216+ if (cfg_data->memory_display == MemoryDisplay::MEMORY_USED)
217+ str_value = CCommon::DataSizeToString (static_cast <unsigned long long >(theApp.m_used_memory ) * 1024 , cfg_data->separate_value_unit_with_space );
218+ else if (cfg_data->memory_display == MemoryDisplay::MEMORY_AVAILABLE)
219+ str_value = CCommon::DataSizeToString ((static_cast <unsigned long long >(theApp.m_total_memory ) - static_cast <unsigned long long >(theApp.m_used_memory )) * 1024 , cfg_data->separate_value_unit_with_space );
220+ else
221+ str_value = CCommon::UsageToString (theApp.m_memory_usage , *cfg_data);
222+ break ;
223+ // 显卡利用率
224+ case TDI_GPU_USAGE:
225+ str_value = CCommon::UsageToString (theApp.m_gpu_usage , *cfg_data);
226+ break ;
227+ // 硬盘利用率
228+ case TDI_HDD_USAGE:
229+ str_value = CCommon::UsageToString (theApp.m_hdd_usage , *cfg_data);
230+ break ;
231+ // CPU温度
232+ case TDI_CPU_TEMP:
233+ str_value = CCommon::TemperatureToString (theApp.m_cpu_temperature , *cfg_data);
234+ break ;
235+ // 显卡温度
236+ case TDI_GPU_TEMP:
237+ str_value = CCommon::TemperatureToString (theApp.m_gpu_temperature , *cfg_data);
238+ break ;
239+ // 硬盘温度
240+ case TDI_HDD_TEMP:
241+ str_value = CCommon::TemperatureToString (theApp.m_hdd_temperature , *cfg_data);
242+ break ;
243+ // 主板温度
244+ case TDI_MAIN_BOARD_TEMP:
245+ str_value = CCommon::TemperatureToString (theApp.m_main_board_temperature , *cfg_data);
246+ break ;
247+ // CPU频率
248+ case TDI_CPU_FREQ:
249+ str_value = CCommon::FreqToString (theApp.m_cpu_freq , *cfg_data);
250+ break ;
251+ // 总流量
252+ case TDI_TODAY_TRAFFIC:
253+ str_value = CCommon::KBytesToString ((theApp.m_today_up_traffic + theApp.m_today_down_traffic ) / 1024u );
254+ break ;
255+ default :
256+ break ;
257+ }
258+ return str_value;
259+ }
260+ }
261+
262+ CString CommonDisplayItem::GetItemValueSampleText (bool is_main_window) const
263+ {
264+ if (is_plugin)
265+ {
266+ return plugin_item->GetItemValueSampleText ();
267+ }
268+ // 主窗口(用于绘制预览图)
269+ else if (is_main_window)
270+ {
271+ CString sample_str;
272+ switch (item_type)
273+ {
274+ case TDI_UP:
275+ sample_str = _T (" 88.8 KB/s" );
276+ break ;
277+ case TDI_DOWN:
278+ sample_str = _T (" 88.9 KB/s" );
279+ break ;
280+ case TDI_TOTAL_SPEED:
281+ sample_str = _T (" 90 KB/s" );
282+ break ;
283+ case TDI_TODAY_TRAFFIC:
284+ sample_str = _T (" 100 MB" );
285+ break ;
286+ case TDI_CPU:
287+ sample_str = _T (" 50 %" );
288+ break ;
289+ case TDI_MEMORY:
290+ sample_str = _T (" 51 %" );
291+ break ;
292+ case TDI_CPU_TEMP: case TDI_GPU_TEMP: case TDI_HDD_TEMP: case TDI_MAIN_BOARD_TEMP:
293+ sample_str = _T (" 40 °C" );
294+ break ;
295+ case TDI_CPU_FREQ:
296+ sample_str = _T (" 1.0 GHz" );
297+ break ;
298+ default :
299+ sample_str = _T (" 99" );
300+ break ;
301+ }
302+ return sample_str;
303+ }
304+ // 任务栏窗口(用于计算任务栏窗口宽度)
305+ else
306+ {
307+ CString sample_str;
308+ switch (item_type)
309+ {
310+ // 网速
311+ case TDI_UP:
312+ case TDI_DOWN:
313+ case TDI_TOTAL_SPEED:
314+ {
315+ wstring digits (theApp.m_taskbar_data .digits_number , L' 8' ); // 根据数据位数生成指定个数的“8”
316+ bool hide_unit{ theApp.m_taskbar_data .hide_unit && theApp.m_taskbar_data .speed_unit != SpeedUnit::AUTO };
317+ if (theApp.m_taskbar_data .speed_short_mode )
318+ {
319+ if (hide_unit)
320+ sample_str.Format (_T (" %s." ), digits.c_str ());
321+ else
322+ sample_str.Format (_T (" %s.M/s" ), digits.c_str ());
323+ }
324+ else
325+ {
326+ if (hide_unit)
327+ sample_str.Format (_T (" %s.8" ), digits.c_str ());
328+ else
329+ sample_str.Format (_T (" %s.8MB/s" ), digits.c_str ());
330+ }
331+ if (!hide_unit && theApp.m_taskbar_data .separate_value_unit_with_space )
332+ sample_str += _T (' ' );
333+ if (theApp.m_taskbar_data .speed_short_mode && !theApp.m_taskbar_data .unit_byte && !theApp.m_taskbar_data .hide_unit )
334+ sample_str += _T (' b' );
335+ }
336+ break ;
337+ // 占用率百分比
338+ case TDI_CPU:
339+ case TDI_MEMORY:
340+ case TDI_GPU_USAGE:
341+ case TDI_HDD_USAGE:
342+ {
343+ // 获取当前数值
344+ int value = 0 ;
345+ if (item_type == TDI_CPU)
346+ value = theApp.m_cpu_usage ;
347+ else if (item_type == TDI_MEMORY)
348+ value = theApp.m_memory_usage ;
349+ else if (item_type == TDI_GPU_USAGE)
350+ value = theApp.m_gpu_usage ;
351+ else if (item_type == TDI_HDD_USAGE)
352+ value = theApp.m_hdd_usage ;
353+
354+ // 当数值达到100时,使用字符串“100”作为宽度,防止显示不全
355+ if (value >= 100 )
356+ sample_str = _T (" 100" );
357+ else
358+ sample_str = _T (" 99" );
359+ if (!theApp.m_taskbar_data .hide_percent )
360+ {
361+ if (theApp.m_taskbar_data .separate_value_unit_with_space )
362+ sample_str += _T (" %" );
363+ else
364+ sample_str += _T (" %" );
365+ }
366+ // 内存显示不为已使用百分比时
367+ if (item_type == TDI_MEMORY)
368+ {
369+ if (theApp.m_taskbar_data .memory_display == MemoryDisplay::MEMORY_USED || theApp.m_taskbar_data .memory_display == MemoryDisplay::MEMORY_AVAILABLE)
370+ {
371+ // 宽度为总内存的宽度
372+ sample_str = CCommon::DataSizeToString (static_cast <unsigned long long >(theApp.m_total_memory ) * 1024 , theApp.m_taskbar_data .separate_value_unit_with_space );
373+ }
374+ }
375+ }
376+ break ;
377+ // 温度
378+ case TDI_CPU_TEMP:
379+ case TDI_GPU_TEMP:
380+ case TDI_HDD_TEMP:
381+ case TDI_MAIN_BOARD_TEMP:
382+ {
383+ if (theApp.m_taskbar_data .separate_value_unit_with_space )
384+ sample_str = _T (" 99 °C" );
385+ else
386+ sample_str = _T (" 99°C" );
387+ }
388+ break ;
389+ // CPU频率
390+ case TDI_CPU_FREQ:
391+ {
392+ if (theApp.m_taskbar_data .separate_value_unit_with_space )
393+ sample_str = _T (" 1.00 GHz" );
394+ else
395+ sample_str = _T (" 1.00GHz" );
396+ }
397+ break ;
398+ // 流量
399+ case TDI_TODAY_TRAFFIC:
400+ {
401+ if (theApp.m_taskbar_data .separate_value_unit_with_space )
402+ sample_str = _T (" 999.99 MB" );
403+ else
404+ sample_str = _T (" 999.99MB" );
405+ }
406+ break ;
407+ }
408+ return sample_str;
409+ }
410+ }
411+
169412// /////////////////////////////////////////////////////////////////////////////////////////////
170413DisplayItemSet::DisplayItemSet (std::initializer_list<DisplayItem> items)
171414 : data(items)
0 commit comments