Posts Tagged wpf

Using a custom WndProc in WPF apps

A current project at work needs to be able to respond to USB ‘thumb’ drives being inserted and removed. In Windows, such notifications are handled by processing the WM_DEVICECHANGE message. Using Windows Forms this is reasonably straightforward: the Form class has a protected WndProc method that can be overridden, like so:

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_DEVICECHANGE)
    {
        // Handle WM_DEVICECHANGE...
    }

    base.WndProc(ref m);
}

Unfortunately the same technique cannot be used in WPF applications. The spiritual equivalent of the Form class in WPF is Window, which has no WndProc method to override. So what to do?

Read the rest of this entry »

,

No Comments