Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need a window, there's no way around that. Here's a sample implementation. Implement an event handler for the DeviceChangeNotifier.DeviceNotify event to get notifications. Call the DeviceChangeNotifier.Start() method at the start of your program. Call DeviceChangeNotifier.Stop() at the end of your program. Beware that the DeviceNotify event is raised on a background thread, be sure to lock as needed to keep your code thread-safe.</p> <pre><code>using System; using System.Windows.Forms; using System.Threading; class DeviceChangeNotifier : Form { public delegate void DeviceNotifyDelegate(Message msg); public static event DeviceNotifyDelegate DeviceNotify; private static DeviceChangeNotifier mInstance; public static void Start() { Thread t = new Thread(runForm); t.SetApartmentState(ApartmentState.STA); t.IsBackground = true; t.Start(); } public static void Stop() { if (mInstance == null) throw new InvalidOperationException("Notifier not started"); DeviceNotify = null; mInstance.Invoke(new MethodInvoker(mInstance.endForm)); } private static void runForm() { Application.Run(new DeviceChangeNotifier()); } private void endForm() { this.Close(); } protected override void SetVisibleCore(bool value) { // Prevent window getting visible if (mInstance == null) CreateHandle(); mInstance = this; value = false; base.SetVisibleCore(value); } protected override void WndProc(ref Message m) { // Trap WM_DEVICECHANGE if (m.Msg == 0x219) { DeviceNotifyDelegate handler = DeviceNotify; if (handler != null) handler(m); } base.WndProc(ref m); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload