mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2025-01-11 15:59:08 +01:00
Register for more specific device change events
This should make the WndProc method execution leaner
This commit is contained in:
parent
722bdf9670
commit
2029cc5531
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user