C#监听WIndows消息

HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;//窗口过程
if (hwndSource != null)
{
hwndSource.AddHook(new HwndSourceHook(DeveiceChanged)); //挂钩
}

原文地址:https://www.cnblogs.com/LCLBook/p/12124199.html