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 Form1() { InitializeComponent(); CHANGEFILTERSTRUCT filterStatus = new CHANGEFILTERSTRUCT(); filterStatus.size = (uint)Marshal.SizeOf(filterStatus); filterStatus.info = 0; ChangeWindowMessageFilterEx(Handle, 0x4A, ChangeWindowMessageFilterExAction.Allow, ref filterStatus); }
private void RunWindowInNewAppcontext(bool AllowAccessFromNonElevatedProcess) { IntPtr hwnd; lock (lockObject) { // Create window hwnd = CreateWindowExW( 0, // dwExStyle className, // lpClassName className, // lpWindowName 0, // dwStyle 0, // x 0, // y 0, // nWidth 0, // nHeight IntPtr.Zero, // hWndParent IntPtr.Zero, // hMenu IntPtr.Zero, // hInstance IntPtr.Zero // lpParam ); if (AllowAccessFromNonElevatedProcess) { CHANGEFILTERSTRUCT filterStatus = new CHANGEFILTERSTRUCT(); filterStatus.size = (uint)Marshal.SizeOf(filterStatus); bool b = ChangeWindowMessageFilterEx(hwnd, WM_COPYDATA, ChangeWindowMessageFilterExAction.Allow, ref filterStatus); } appContext = new ApplicationContext(); Monitor.Pulse(lockObject); } // Pageant window is run in its own application context so that it does // not block the UI thread of applications that use it. Application.Run(appContext); // make sure socket files are cleaned up when we stop. StopCygwinSocket(); StopMsysSocket(); StopWindowsOpenSshPipe(); if (hwnd != IntPtr.Zero) { if (DestroyWindow(hwnd)) { hwnd = IntPtr.Zero; disposed = true; } } }
public Form1() { InitializeComponent(); try { CHANGEFILTERSTRUCT filterStatus = new CHANGEFILTERSTRUCT(); filterStatus.size = (uint)Marshal.SizeOf(filterStatus); filterStatus.info = 0; ChangeWindowMessageFilterEx(Handle, 0x4A, ChangeWindowMessageFilterExAction.Allow, ref filterStatus); } catch (Exception) { Close(); } }
public static Win32ErrorCode EnableWM_CopyData(IntPtr windowHandle) { CHANGEFILTERSTRUCT changeFilter = new CHANGEFILTERSTRUCT(); changeFilter.size = (uint)Marshal.SizeOf(changeFilter); changeFilter.info = 0; if (!MyUser32.ChangeWindowMessageFilterEx(windowHandle, User32.WindowMessage.WM_COPYDATA, ChangeWindowMessageFilterExAction.Allow, ref changeFilter)) { return(Kernel32.GetLastError()); } else { return(Win32ErrorCode.ERROR_SUCCESS); } }
RegisteredWindowInfo CreateWindowRegister(HookType type, String messageName) { RegisteredWindowInfo winRegTemp = new RegisteredWindowInfo(); CHANGEFILTERSTRUCT filterStatus = new CHANGEFILTERSTRUCT(); filterStatus.size = (uint)Marshal.SizeOf(filterStatus); filterStatus.info = 0; //Register the window with api call winRegTemp.windowRegisterID = RegisterWindowMessage(messageName); //Allow messages to be received form lower privileged processes ChangeWindowMessageFilterEx(hWnd, winRegTemp.windowRegisterID, ChangeWindowMessageFilterExAction.Allow, ref filterStatus); winRegTemp.type = type; return(winRegTemp); }
public void EnableDragDrop(IntPtr hWnd) { if (Is7OrHigher) { CHANGEFILTERSTRUCT changeStruct = new CHANGEFILTERSTRUCT(); changeStruct.cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(CHANGEFILTERSTRUCT))); ChangeWindowMessageFilterEx(hWnd, WM_DROPFILES, ChangeWindowMessageFilterExAction.Allow, ref changeStruct); ChangeWindowMessageFilterEx(hWnd, WM_COPYDATA, ChangeWindowMessageFilterExAction.Allow, ref changeStruct); ChangeWindowMessageFilterEx(hWnd, WM_COPYGLOBALDATA, ChangeWindowMessageFilterExAction.Allow, ref changeStruct); } else if (IsVistaOrHigher) { ChangeWindowMessageFilter(WM_DROPFILES, ChangeWindowMessageFilterFlags.Add); ChangeWindowMessageFilter(WM_COPYDATA, ChangeWindowMessageFilterFlags.Add); ChangeWindowMessageFilter(WM_COPYGLOBALDATA, ChangeWindowMessageFilterFlags.Add); } DragAcceptFiles(hWnd, true); }
private void Window_Loaded(object sender, RoutedEventArgs e) { var handle = new WindowInteropHelper(GetWindow(this)).Handle; var eh = new CHANGEFILTERSTRUCT(); eh.size = (uint)Marshal.SizeOf(eh); for (uint i = 1; i <= WM_DROPFILES; i++) { ChangeWindowMessageFilterEx(handle, i, ChangeWindowMessageFilterExAction.Allow, ref eh); } var b1 = ChangeWindowMessageFilterEx(handle, 0x0049, ChangeWindowMessageFilterExAction.Allow, ref eh); var b2 = ChangeWindowMessageFilterEx(handle, WM_DROPFILES, ChangeWindowMessageFilterExAction.Allow, ref eh); var b3 = ChangeWindowMessageFilterEx(handle, WM_COPYDATA, ChangeWindowMessageFilterExAction.Allow, ref eh); //ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); //ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD); //ChangeWindowMessageFilter(0x0049, MSGFLT_ADD); }
public static extern bool ChangeWindowMessageFilterEx(IntPtr hWnd, uint msg, ChangeWindowMessageFilterExAction action, ref CHANGEFILTERSTRUCT changeInfo);
private static extern bool _ChangeWindowMessageFilterEx(IntPtr hwnd, WM message, MSGFLT action, [In][Out] ref CHANGEFILTERSTRUCT pChangeFilterStruct);
private static extern bool ChangeWindowMessageFilterEx(IntPtr hWnd, uint message, ChangeWindowMessageFilterExAction action, [In, Out, Optional] ref CHANGEFILTERSTRUCT changeInfo);