using System.Drawing;\r
using System.IO;\r
using System.Linq;\r
+using System.Runtime.InteropServices;\r
+using System.Text;\r
using System.Windows.Forms;\r
using Codeplex.Data;\r
using Fiddler;\r
public partial class MainForm : Form\r
{\r
private readonly Sniffer _sniffer = new Sniffer();\r
- private readonly dynamic _wmp = Activator.CreateInstance(Type.GetTypeFromProgID("WMPlayer.OCX.7"));\r
private readonly Config _config = new Config();\r
private readonly ConfigDialog _configDialog;\r
private int _currentFleet;\r
InitializeComponent();\r
FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest;\r
FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;\r
- _wmp.PlayStateChange += new EventHandler(_wmp_PlayStateChange);\r
_configDialog = new ConfigDialog(_config, this);\r
_labelCheckFleets = new[] {labelCheckFleet1, labelCheckFleet2, labelCheckFleet3, labelCheckFleet4};\r
\r
{\r
_logServer = new LogServer(_config.Log.Listen);\r
_logServer.Start();\r
-\r
}\r
if (_logServer != null)\r
_logServer.OutputDir = _config.Log.OutputDir;\r
PlaySound(soundFile, _config.SoundVolume);\r
}\r
\r
+ [DllImport("winmm.dll")]\r
+ private static extern int mciSendString(String command,\r
+ StringBuilder buffer, int bufferSize, IntPtr hwndCallback);\r
+\r
+// ReSharper disable InconsistentNaming\r
+ private const int MM_MCINOTIFY = 0x3B9;\r
+ private const int MCI_NOTIFY_SUCCESSFUL = 1;\r
+// ReSharper restore InconsistentNaming\r
+\r
public void PlaySound(string file, int volume)\r
{\r
if (!File.Exists(file))\r
return;\r
- _wmp.settings.volume = volume + 1;\r
- _wmp.settings.volume = volume - 1;\r
- _wmp.settings.volume = volume;\r
- _wmp.URL = file;\r
- _wmp.controls.play();\r
+ if (mciSendString("open \"" + file + "\" type mpegvideo alias sound", null, 0, IntPtr.Zero) != 0)\r
+ return;\r
+ mciSendString("setaudio sound volume to " + volume * 10, null, 0, IntPtr.Zero);\r
+ mciSendString("play sound from 0 notify", null, 0, Handle);\r
}\r
\r
- private void _wmp_PlayStateChange(object sender, EventArgs e)\r
+ protected override void WndProc(ref Message m)\r
{\r
- if (_wmp.playState == 8) // MediaEnded\r
- _wmp.URL = ""; // 再生したファイルが差し替えできなくなるのを防ぐ。\r
+ if (m.Msg == MM_MCINOTIFY && (int)m.WParam == MCI_NOTIFY_SUCCESSFUL)\r
+ mciSendString("close sound", null, 0, IntPtr.Zero);\r
+ base.WndProc(ref m);\r
}\r
\r
private void SetupFleetClick()\r