OnSourceInitialized

Topics: Bootstrappers & IoC, Feature Requests, Framework Services
May 26, 2011 at 6:53 AM
Edited May 26, 2011 at 6:54 AM

Is it possible to override this method? Usually this comes from Window class ?

How would I go about capturing window messages ? EG:

namespace WpfApplication1
{
   
public partial class Window1 : Window
   
{
       
public Window1()
       
{
           
InitializeComponent();
       
}

       
protected override void OnSourceInitialized(EventArgs e)
       
{
           
base.OnSourceInitialized(e);
           
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
            source
.AddHook(WndProc);
       
}

       
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
       
{
           
// Handle messages...

           
return IntPtr.Zero;
       
}
   
}
}

 

I need to detect a usb event..

 

thanks

Chris