using System.Runtime.InteropServices; using System.Windows.Forms; namespace B3ButcherWeightClient { public class WinApiSendMessage { //声明 API 函数 [DllImport("User32.dll", EntryPoint = "SendMessage")] public static extern int SendMessage( int hWnd, // handle to destination window int Msg, // message int wParam, // first message parameter int lParam // second message parameter ); [DllImport("User32.dll", EntryPoint = "FindWindow")] public static extern int FindWindow(string lpClassName, string lpWindowName); [DllImport("wininet.dll")] public extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); const int SND_ASYNC = 1; const int SND_FileNAME = 0X20000; [DllImport("winmm.dll", EntryPoint = "PlaySound")] private static extern int PlaySound(string lpxzName, int hModul, int dwFlags); public static int WinAPIPlaySound(string fileName) { int isOk = PlaySound(Application.StartupPath + fileName, 1, SND_FileNAME | SND_ASYNC); return isOk; } } }