diff --git a/DS4Windows/DS4Control/ScpDevice.cs b/DS4Windows/DS4Control/ScpDevice.cs index 267f10d..bc22c4b 100644 --- a/DS4Windows/DS4Control/ScpDevice.cs +++ b/DS4Windows/DS4Control/ScpDevice.cs @@ -181,6 +181,7 @@ namespace DS4Windows public const Int32 DEVICE_NOTIFY_SERVICE_HANDLE = 0x0001; public const Int32 DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = 0x0004; + public const Int32 WM_CREATE = 0x0001; public const Int32 WM_DEVICECHANGE = 0x0219; public const Int32 DIGCF_PRESENT = 0x0002; diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 086ef32..3f9f85e 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -1037,14 +1037,29 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question private int hotplugCounter = 0; private object hotplugCounterLock = new object(); private const int DBT_DEVNODES_CHANGED = 0x0007; + private const int DBT_DEVICEARRIVAL = 0x8000; + private const int DBT_DEVICEREMOVECOMPLETE = 0x8004; protected override void WndProc(ref Message m) { - if (m.Msg == ScpDevice.WM_DEVICECHANGE) + if (m.Msg == ScpDevice.WM_CREATE) + { + Guid hidGuid = new Guid(); + NativeMethods.HidD_GetHidGuid(ref hidGuid); + IntPtr outHandle = new IntPtr(); + bool result = ScpDevice.RegisterNotify(this.Handle, hidGuid, ref outHandle); + if (!result) + { + ScpForm_Closing(this, + new FormClosingEventArgs(CloseReason.ApplicationExitCall, false)); + } + } + else if (m.Msg == ScpDevice.WM_DEVICECHANGE) { if (runHotPlug) { Int32 Type = m.WParam.ToInt32(); - if (Type == DBT_DEVNODES_CHANGED) + if (Type == DBT_DEVICEARRIVAL || + Type == DBT_DEVICEREMOVECOMPLETE) { lock (hotplugCounterLock) {