public static HRESULT ChangeWindowMessageFilterEx(IntPtr hwnd, WM message, MSGFLT action, out MSGFLTINFO filterInfo) { filterInfo = MSGFLTINFO.NONE; if (!Utility.IsOSVistaOrNewer) { return(HRESULT.S_FALSE); } if (!Utility.IsOSWindows7OrNewer) { if (!NativeMethods._ChangeWindowMessageFilter(message, action)) { return((HRESULT)Win32Error.GetLastError()); } return(HRESULT.S_OK); } else { CHANGEFILTERSTRUCT changefilterstruct = new CHANGEFILTERSTRUCT { cbSize = (uint)Marshal.SizeOf(typeof(CHANGEFILTERSTRUCT)) }; if (!NativeMethods._ChangeWindowMessageFilterEx(hwnd, message, action, ref changefilterstruct)) { return((HRESULT)Win32Error.GetLastError()); } filterInfo = changefilterstruct.ExtStatus; return(HRESULT.S_OK); } }