⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppclib.cs

📁 用C#实现的取得CellID和LAC的程序源代码!
💻 CS
字号:
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;

using NiceTracker.Config;

namespace NiceTracker.Libraries
{
	/// <summary>
	/// Summary description for PPCLib.
	/// </summary>
	public class PPCLib
	{
		[DllImport("coredll.dll")]
		private static extern bool SipShowIM(int dwFlag);
		[DllImport("coredll.dll")]
		private static extern int waveOutGetNumDevs();
		[DllImport("coredll.dll")]
		private static extern int waveOutSetVolume(IntPtr hWaveOut, int dwVolume);
		[DllImport("coredll.dll")]
		private static extern int waveOutGetVolume(IntPtr hWaveOut, out int dwVolume);
		[DllImport("coredll.dll")]
		private static extern bool PlaySound(StringBuilder filename, IntPtr hmod, int fdwSound );
		[DllImport("coredll.dll")]
		private static extern bool AudioUpdateFromRegistry( );		
		[DllImport("aygshell", EntryPoint="Vibrate")]
		private static extern int VibratePlay( int cvn, IntPtr rgvn, uint fRepeat, uint dwTimeout);		
		[DllImport("aygshell")]
		private static extern int VibrateStop();

		private static int SND_SYNC =           0x0000;  /* play synchronously (default) */
		private static int SND_ASYNC =          0x0001;  /* play asynchronously */
		private static int SND_NODEFAULT =      0x0002;  /* silence (!default) if sound not found */
		private static int SND_MEMORY =         0x0004;  /* pszSound points to a memory file */
		private static int SND_LOOP =           0x0008;  /* loop the sound until next sndPlaySound */
		private static int SND_NOSTOP =         0x0010;  /* don't stop any currently playing sound */
		private static int SND_NOWAIT =     0x00002000; /* don't wait if the driver is busy */
		private static int SND_ALIAS =      0x00010000; /* name is a registry alias */
		private static int SND_ALIAS_ID =   0x00110000; /* alias is a predefined ID */
		private static int SND_FILENAME =   0x00020000; /* name is file name */
		private static int SND_RESOURCE =   0x00040004; /* name is resource name or atom */
		private static int SND_PURGE =          0x0040;  /* purge non-static events for task */
		private static int SND_APPLICATION =    0x0080;  /* look for application specific association */		


		[StructLayout(LayoutKind.Sequential)]
		struct WAVEFORMATEX
		{
			public ushort    wFormatTag;
			public ushort    nChannels;
			public uint      nSamplesPerSec;
			public uint      nAvgBytesPerSec;
			public ushort    nBlockAlign;
			public ushort    wBitsPerSample;
			public ushort    cbSize;
		}

		public enum PowerState 
		{
			PwrDeviceUnspecified = -1,		
			FullOn = 0,		// Full on
			LowOn = 1,		// Low on
			Standby = 2,	// Standby
			Sleep = 3,		// Sleep
			Off = 4,		// Off
			PwrDeviceMaximum = 5 
		};

		[DllImport("coredll.dll")]
		private static extern int DevicePowerNotify( string device, PowerState deviceState, int deviceFlags );

		public PPCLib()
		{		
		}

		public static bool ShowSip
		{
			set
			{
				if ( ConfigManager.ExpandSip )
				{
					if ( value )
						SipShowIM( 1 );
					else
						SipShowIM( 0 );
				}
			}
		}

		public static void SetVibrate( int duration )
		{
			VibratePlay(0, IntPtr.Zero, 0xffffffff, 0xffffffff);

			Thread.Sleep( duration * 1000 );

			VibrateStop();
		}

		public static void SetBacklight( PowerState pwr )
		{
			DevicePowerNotify( "BKL1:", pwr, 1 );
		}

		public static int WaveOutGetNumDevices()
		{
			return waveOutGetNumDevs();
		}

		public static void SetVolume( int vol )
		{
			int newVol = vol * 51;
			int newVolLR = newVol + ( newVol * 256 );

			waveOutSetVolume( IntPtr.Zero, newVolLR );
		}

		public static void SetProfile( int profile )
		{
			Registry.RootKey hklm=Registry.RootNameToValue("HKEY_CURRENT_USER"); 
			int appKey=Registry.OpenKey(hklm,"\\ControlPanel\\Notifications\\ShellOverrides"); 
			bool ret=Registry.SetValue(appKey,"Mode",profile); 
			bool success=Registry.CloseKey(ref appKey); 

			AudioUpdateFromRegistry();
		}

		public static void SetRingVolume( int vol )
		{
			Registry.RootKey hklm=Registry.RootNameToValue("HKEY_CURRENT_USER"); 
			int appKey=Registry.OpenKey(hklm,"\\ControlPanel\\SoundCategories\\Ring"); 
			bool ret=Registry.SetValue(appKey,"InitVol",vol); 
			bool success=Registry.CloseKey(ref appKey); 

			AudioUpdateFromRegistry();
		}

		public static bool PlaySound( string filename )
		{
			bool returnValue = false;

			StringBuilder sb = new StringBuilder( filename );			

			if ( File.Exists( sb.ToString() ) )
			{
				returnValue = PlaySound(  sb, IntPtr.Zero, (int)( SND_SYNC | SND_FILENAME ) );					
			}

			return returnValue;
		}

		public static bool InternetConnected()
		{
			bool ret = false;
			try
			{
				// Returns the Device Name
				string hostName = Dns.GetHostName();
				IPHostEntry thisHost = Dns.GetHostByName(hostName);
				string thisIpAddr = thisHost.AddressList[0].ToString();
				ret = thisIpAddr != System.Net.IPAddress.Parse("127.0.0.1").ToString();
			}
			catch ( Exception )
			{
				ret = false;
			}

			return ret;

		}																																   
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -