📄 common.cs
字号:
using System;
using System.Runtime .InteropServices ;
namespace MyClock
{
/// <summary>
/// Common 的摘要说明。
/// </summary>
public class Common
{
public Common()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void DoorOpen()
{
mciSendString("set cdaudio door open","",0,0); //打开
}
public void DoorClose()
{
mciSendString("set cdaudio door closed","",0,0);//关闭
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}
[DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok );
[DllImport("advapi32.dll", SetLastError=true) ]
internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid );
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool ExitWindowsEx( int flg, int rea );
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;
public static void DoExitWin( int flg )
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
}
internal const int SND_SYNC = 0x0000 ; /* play synchronously (default) */
internal const int SND_ASYNC = 0x0001 ; /* play asynchronously */
internal const int SND_NODEFAULT = 0x0002 ; /* silence (!default) if sound not found */
internal const int SND_MEMORY = 0x0004 ;/* pszSound points to a memory file */
internal const int SND_LOOP = 0x0008 ; /* loop the sound until next sndPlaySound */
internal const int SND_NOSTOP = 0x0010 ; /* don't stop any currently playing sound */
internal const long SND_NOWAIT = 0x00002000L; /* don't wait if the driver is busy */
internal const long SND_ALIAS = 0x00010000L; /* name is a registry alias */
internal const long SND_ALIAS_ID = 0x00110000L ;/* alias is a predefined ID */
internal const long SND_FILENAME = 0x00020000L; /* name is file name */
internal const long SND_RESOURCE = 0x00040004L; /* name is resource name or atom */
[DllImport("winmm.dll")]
public static extern long PlaySound(String fileName,long a,long b);
[DllImport("winmm.dll")]
public static extern int mciSendString(string s1,string s2,int i1,int i2);
}
public class AnimateClass
{
public const Int32 AW_HOR_POSITIVE = 0x00000001;
public const Int32 AW_HOR_NEGATIVE = 0x00000002;
public const Int32 AW_VER_POSITIVE = 0x00000004;
public const Int32 AW_VER_NEGATIVE = 0x00000008;
public const Int32 AW_CENTER = 0x00000010;
public const Int32 AW_HIDE = 0x00010000;
public const Int32 AW_ACTIVATE = 0x00020000;
public const Int32 AW_SLIDE = 0x00040000;
public const Int32 AW_BLEND = 0x00080000;
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern bool AnimateWindow(
IntPtr hwnd, // handle to window
int dwTime, // duration of animation
int dwFlags // animation type
);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -