示例#1
0
        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);
            }
        }
        public static HRESULT ChangeWindowMessageFilterEx(IntPtr hwnd, WM message, MSGFLT action, out MSGFLTINFO filterInfo)
        {
            filterInfo = MSGFLTINFO.NONE;

            bool ret;

            // This origins of this API were added for Vista.  The Ex version was added for Windows 7.
            // If we're not on either, then this message filter isolation doesn't exist.
            if (!Utility.IsOSVistaOrNewer)
            {
                return HRESULT.S_FALSE;
            }

            // If we're on Vista rather than Win7 then we can't use the Ex version of this function.
            // The Ex version is preferred if possible because this results in process-wide modifications of the filter
            // and is deprecated as of Win7.
            if (!Utility.IsOSWindows7OrNewer)
            {
                // Note that the Win7 MSGFLT_ALLOW/DISALLOW enum values map to the Vista MSGFLT_ADD/REMOVE
                ret = _ChangeWindowMessageFilter(message, action);
                if (!ret)
                {
                    return (HRESULT)Win32Error.GetLastError();
                }
                return HRESULT.S_OK;
            }

            var filterstruct = new CHANGEFILTERSTRUCT { cbSize = (uint)Marshal.SizeOf(typeof(CHANGEFILTERSTRUCT)) };
            ret = _ChangeWindowMessageFilterEx(hwnd, message, action, ref filterstruct);
            if (!ret)
            {
                return (HRESULT)Win32Error.GetLastError();
            }

            filterInfo = filterstruct.ExtStatus;
            return HRESULT.S_OK;
        }
示例#3
0
        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 (Standard.NativeMethods.ChangeWindowMessageFilter(message, action))
                {
                    return(HRESULT.S_OK);
                }
                return((HRESULT)Win32Error.GetLastError());
            }
            CHANGEFILTERSTRUCT cHANGEFILTERSTRUCT = new CHANGEFILTERSTRUCT()
            {
                cbSize = (uint)Marshal.SizeOf(typeof(CHANGEFILTERSTRUCT))
            };
            CHANGEFILTERSTRUCT cHANGEFILTERSTRUCT1 = cHANGEFILTERSTRUCT;

            if (!Standard.NativeMethods.ChangeWindowMessageFilterEx_1(hwnd, message, action, ref cHANGEFILTERSTRUCT1))
            {
                return((HRESULT)Win32Error.GetLastError());
            }
            filterInfo = cHANGEFILTERSTRUCT1.ExtStatus;
            return(HRESULT.S_OK);
        }