コード例 #1
0
        /*
         * // Listen for the control's window creation and then hook into it.
         * private void OnHandleCreated(object sender, EventArgs e)
         * {
         *  try
         *  {
         *      // Window is now created, assign handle to NativeWindow.
         *      IntPtr handle = ((Control)sender).Handle;
         *      RegisterNotify(handle);
         *  }
         *  catch (API.APIException ex)
         *  {
         *      throw new USBException("Failed to register new window handle for device notification.", ex);
         *  }
         * }
         *
         * private void OnHandleDestroyed(object sender, EventArgs e)
         * {
         *  try
         *  {
         *      // Window was destroyed, release hook.
         *      StopNotify();
         *  }
         *  catch (API.APIException ex)
         *  {
         *      throw new USBException("Failed to unregister destroyed window handle for device notification.", ex);
         *  }
         * }
         *
         * private void RegisterNotify(IntPtr handle)
         * {
         *  AssignHandle(handle);
         *
         *  if (_notifyHandle != IntPtr.Zero)
         *  {
         *      API.DeviceManagement.StopDeviceDeviceNotifications(_notifyHandle);
         *      _notifyHandle = IntPtr.Zero;
         *  }
         *  API.DeviceManagement.RegisterForDeviceNotifications(handle, _guid, ref _notifyHandle);
         * }
         *
         * private void StopNotify()
         * {
         *  //ReleaseHandle();
         *  if (_notifyHandle != IntPtr.Zero)
         *  {
         *      API.DeviceManagement.StopDeviceDeviceNotifications(_notifyHandle);
         *      _notifyHandle = IntPtr.Zero;
         *  }
         * }
         *
         * protected override void WndProc(ref Message m)
         * {
         *  // Listen for operating system messages
         *
         *  switch (m.Msg)
         *  {
         *      case API.DeviceManagement.WM_DEVICECHANGE:
         *          _notifier.HandleDeviceChange(m);
         *          break;
         *      case WM_NCDESTROY:
         *          // Note: when a control is used, OnHandleDestroyed will be called and the
         *          // handle is already released from NativeWindow. In that case, this
         *          // WM_NCDESTROY message will not be caught here. This is no problem since
         *          // StopNotify is already called. Even if it does, calling it twice does not cause
         *          // problems.
         *          // When a window handle is used instead of a Control the OnHandle events will not
         *          // fire and this handler is necessary to release the handle and stop notifications
         *          // when the window is destroyed.
         *          StopNotify();
         *          break;
         *  }
         *  base.WndProc(ref m);
         * }
         */

        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            // Listen for operating system messages

            switch (msg)
            {
            case API.DeviceManagement.WM_DEVICECHANGE:
                return((IntPtr)_notifier.HandleDeviceChange(msg, wParam, lParam));
                //break;
            }
            return(IntPtr.Zero);
        }
コード例 #2
0
        protected override void WndProc(ref Message m)
        {
            // Listen for operating system messages

            switch (m.Msg)
            {
            case API.DeviceManagement.WM_DEVICECHANGE:
                _notifier.HandleDeviceChange(m);
                break;
            }
            base.WndProc(ref m);
        }
コード例 #3
0
        protected override void WndProc(ref Message m)
        {
            // Listen for operating system messages

            switch (m.Msg)
            {
            case API.DeviceManagement.WM_DEVICECHANGE:
                _notifier.HandleDeviceChange(m);
                break;

            case WM_NCDESTROY:
                // Note: when a control is used, OnHandleDestroyed will be called and the
                // handle is already released from NativeWindow. In that case, this
                // WM_NCDESTROY message will not be caught here. This is no problem since
                // StopNotify is already called. Even if it does, calling it twice does not cause
                // problems.
                // When a window handle is used instead of a Control the OnHandle events will not
                // fire and this handler is necessary to release the handle and stop notifications
                // when the window is destroyed.
                StopNotify();
                break;
            }
            base.WndProc(ref m);
        }