1- using Microsoft . Win32 ;
1+ using EyeGuard . BLL ;
2+ using Microsoft . Win32 ;
3+ using NAudio . CoreAudioApi ;
24using System ;
35using System . Collections . Generic ;
46using System . Diagnostics ;
57using System . Drawing ;
68using System . IO ;
9+ using System . Linq ;
10+ using System . Media ;
711using System . Runtime . InteropServices ;
812using System . Text ;
13+ using System . Threading ;
14+ using WpfScreenHelper ;
915
1016namespace EyeGuard
1117{
@@ -66,7 +72,7 @@ public static string GetFormattingTime(string value)
6672 int TotalSeconds = Convert . ToInt32 ( value ) ;
6773
6874 int branch = TotalSeconds / 60 ;
69- int second = TotalSeconds % 60 ;
75+ int second = TotalSeconds % 60 ;
7076 return GetFormattingTime ( branch ) + ":" + GetFormattingTime ( second ) ;
7177 }
7278
@@ -81,7 +87,7 @@ public static double ExecDateDiff(DateTime dateBegin, DateTime dateEnd)
8187 {
8288 TimeSpan ts1 = new TimeSpan ( dateBegin . Ticks ) ;
8389 TimeSpan ts2 = new TimeSpan ( dateEnd . Ticks ) ;
84- TimeSpan ts3 = ts2 - ts1 ;
90+ TimeSpan ts3 = ts2 - ts1 ;
8591 //得到相差的分钟数
8692 return ts3 . TotalMinutes ;
8793 }
@@ -159,7 +165,7 @@ public struct RECT
159165 //桌面窗口句柄
160166 private IntPtr desktopHandle ;
161167 //Shell窗口句柄
162- private IntPtr shellHandle ;
168+ private IntPtr shellHandle ;
163169 #endregion
164170
165171
@@ -233,12 +239,6 @@ public static void BootUp(bool Whether = true)
233239 }
234240 #endregion
235241
236- [ DllImport ( "PublicTools.dll" , EntryPoint = "_GetStateOfTheSound@0" ) ]
237- private static extern int GetStateOfTheSound ( ) ;
238-
239- //_GetInfoOnTheScreen@4
240- [ DllImport ( "PublicTools.dll" , EntryPoint = "GetInfoOnTheScreen" ) ]
241- private static extern IntPtr GetInfoOnTheScreen ( ) ;
242242
243243 /// <summary>
244244 /// 全部屏幕信息
@@ -251,22 +251,16 @@ public static void BootUp(bool Whether = true)
251251 /// </summary>
252252 public static void GetInfoOnTheScreens ( )
253253 {
254- string value = Marshal . PtrToStringAnsi ( GetInfoOnTheScreen ( ) ) ;
255- string [ ] Displays = value . Split ( ',' ) ;
256-
257- for ( int i = 0 ; i < Displays . Length ; i ++ )
254+ for ( int i = 0 ; i < Screen . AllScreens . Count ( ) ; i ++ )
258255 {
259- string [ ] _value = Displays [ i ] . Split ( "X" ) ;
260- if ( _value . Length == 2 )
261- {
262- InfoOnTheScreen infoOnThe = new InfoOnTheScreen ( ) ;
263- infoOnThe . Width = Convert . ToInt32 ( _value [ 0 ] ) ;
264- infoOnThe . Height = Convert . ToInt32 ( _value [ 1 ] ) ;
265- infoOnThe . Order = i ;
266- InfoOnTheScreens . Add ( infoOnThe ) ;
267- }
256+ var _value = Screen . AllScreens . ToList ( ) [ i ] ;
257+ InfoOnTheScreen infoOnThe = new InfoOnTheScreen ( ) ;
258+ infoOnThe . Width = Convert . ToInt32 ( _value . Bounds . Width ) ;
259+ infoOnThe . Height = Convert . ToInt32 ( _value . Bounds . Height ) ;
260+ infoOnThe . Order = i ;
261+ InfoOnTheScreens . Add ( infoOnThe ) ;
268262 }
269-
263+
270264 }
271265
272266 /// <summary>
@@ -275,11 +269,12 @@ public static void GetInfoOnTheScreens()
275269 /// <returns></returns>
276270 public static bool IsAudioPlaying ( )
277271 {
278- if ( GetStateOfTheSound ( ) == 1 )
272+ using ( var enumerator = new MMDeviceEnumerator ( ) )
279273 {
280- return true ;
274+ var defaultDevice = enumerator . GetDefaultAudioEndpoint ( DataFlow . Render , Role . Multimedia ) ;
275+ bool state = defaultDevice . AudioMeterInformation . MasterPeakValue > 0 ;
276+ return state ;
281277 }
282- return false ;
283278 }
284279 }
285280
0 commit comments