public MessageWindow(CS classStyle, WS style, WS_EX exStyle, Rect location, string name, WndProc callback) { Class6.yDnXvgqzyB5jw(); base(); this._wndProcCallback = callback; Guid guid = Guid.NewGuid(); this._className = string.Concat("MessageWindowClass+", guid.ToString()); WNDCLASSEX wNDCLASSEX = new WNDCLASSEX() { cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)), style = classStyle, lpfnWndProc = MessageWindow.s_WndProc, hInstance = Standard.NativeMethods.GetModuleHandle(null), hbrBackground = Standard.NativeMethods.GetStockObject(StockObject.NULL_BRUSH), lpszMenuName = "", lpszClassName = this._className }; WNDCLASSEX wNDCLASSEX1 = wNDCLASSEX; Standard.NativeMethods.RegisterClassEx(ref wNDCLASSEX1); GCHandle gCHandle = new GCHandle(); try { gCHandle = GCHandle.Alloc(this); IntPtr intPtr = (IntPtr)gCHandle; this.Handle = Standard.NativeMethods.CreateWindowEx(exStyle, this._className, name, style, (int)location.X, (int)location.Y, (int)location.Width, (int)location.Height, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, intPtr); } finally { gCHandle.Free(); } }
private void button54_Click(object sender, EventArgs e) { WndProc proc = MyWndProc; IntPtr result = Win32API.CallWindowProc(proc, this.Handle, WindowsMsg.WM_SIZE, (IntPtr)0, (IntPtr)0); Console.WriteLine(result); }
private static ushort CreateWindowClass(WndProc wndProc) { var menuName = RandomHelper.GetString(5, 10, true); var className = RandomHelper.GetString(5, 10, true); return(CreateWindowClass(wndProc, menuName, className)); }
public static void Run <T>(T applicationContext) where T : IApplicationContext, IFocusManager { if (AttachMouse) { _mouseIO = new MouseIO(); } System.Console.CursorVisible = false; WndProc.Init(); applicationContext.RenderComplete += (obj, e) => { if (AttachMouse) { WndProc.Attach(_mouseIO); } WndProc.Attach(applicationContext); }; Task.Run(async() => { try { await applicationContext.Run(); } catch (Exception ex) { throw; } }).GetAwaiter().GetResult(); }
public NotifyIcon() { _id = ++NextId; _callback = Callback; Loaded += (s, e) => { RegisterClass(); if (Visibility == Visibility.Visible) { OnIconChanged(); UpdateIcon(true); } _dispatcherTimerPos = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(200) }; _dispatcherTimerPos.Tick += DispatcherTimerPos_Tick; }; if (Application.Current != null) { Application.Current.Exit += (s, e) => Dispose(); } }
public Win32Window(WindowingService service, WndProc wndProc) : base(service) { var winClass = new WndClass { style = Constants.CS_OWNDC, lpfnWndProc = wndProc, hInstance = Native.GetModuleHandle(null), lpszClassName = $"OpenWindow_DUMMY[{Native.GetCurrentThreadId()}]({_windowId++})" }; _className = winClass.lpszClassName; if (Native.RegisterClass(ref winClass) == 0) { throw GetLastException("Registering window class failed."); } Hwnd = Native.CreateWindowEx( 0, winClass.lpszClassName, "OpenWindow dummy window", 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, winClass.hInstance, IntPtr.Zero); _windowData = new Win32WindowData(Hwnd); InitOpenGl(service.GlSettings); }
private static IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam) { IntPtr result = IntPtr.Zero; MessageWindow messageWindow = null; if (msg == WM.CREATE) { CREATESTRUCT createstruct = (CREATESTRUCT)Marshal.PtrToStructure(lParam, typeof(CREATESTRUCT)); messageWindow = (MessageWindow)GCHandle.FromIntPtr(createstruct.lpCreateParams).Target; MessageWindow.s_windowLookup.Add(hwnd, messageWindow); } else if (!MessageWindow.s_windowLookup.TryGetValue(hwnd, out messageWindow)) { return(NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam)); } WndProc wndProcCallback = messageWindow._wndProcCallback; if (wndProcCallback != null) { result = wndProcCallback(hwnd, msg, wParam, lParam); } else { result = NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam); } if (msg == WM.NCDESTROY) { messageWindow._Dispose(true, true); GC.SuppressFinalize(messageWindow); } return(result); }
public MessageWindow(CS classStyle, WS style, WS_EX exStyle, Rect location, string name, WndProc callback) { _wndProcCallback = callback; _className = "MessageWindowClass+" + Guid.NewGuid().ToString(); var wc = new WNDCLASSEX { cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)), style = classStyle, lpfnWndProc = s_WndProc, hInstance = NativeMethods.GetModuleHandle(null), hbrBackground = NativeMethods.GetStockObject(StockObject.NULL_BRUSH), lpszMenuName = "", lpszClassName = _className, }; NativeMethods.RegisterClassEx(ref wc); var gcHandle = default(GCHandle); try { gcHandle = GCHandle.Alloc(this); var pinnedThisPtr = (IntPtr)gcHandle; Handle = NativeMethods.CreateWindowEx(exStyle, _className, name, style, (int)location.X, (int)location.Y, (int)location.Width, (int)location.Height, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pinnedThisPtr); } finally { gcHandle.Free(); } }
public Msn(ISettings settings, ILogger logger) { _settings = settings; _logger = logger; var enabled = settings.Get <bool>(Enabled); _logger.Log($"MSN plugin is {(enabled ? "enabled" : "disabled")}", LogLevel.Information); if (!enabled || WndProcc != null) { return; } WndProcc = CustomWndProc; lpWndClass = new WNDCLASS { lpszClassName = lpClassName, lpfnWndProc = WndProcc }; ushort num = RegisterClassW(ref lpWndClass); int num2 = Marshal.GetLastWin32Error(); if ((num == 0) && (num2 != 0x582)) { throw new Exception("Could not register window class"); } this.m_hwnd = CreateWindowExW(0, lpClassName, string.Empty, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); }
public GlobalHotKey(int id, int virtualKey, int modifiers, Action callback) { Id = id; VirtualKey = virtualKey; Modifiers = modifiers; Callback = callback; _wndProcRegistration = WndProc.Listen(786, m => { // Filter out other hotkey events if (m.WParam.ToInt32() != Id) { return; } // Throttling lock (_lock) { if ((DateTimeOffset.Now - _lastTriggerTimestamp).Duration().TotalSeconds < 0.2) { return; } _lastTriggerTimestamp = DateTimeOffset.Now; } Callback(); }); }
public SystemEvent(int eventId, Action callback) { EventId = eventId; Callback = callback; _wndProcRegistration = WndProc.Listen(eventId, m => callback()); }
public WindowInBandWrapper(Window window) { _window = window; delegWndProc = myWndProc; _DPI = 1; _window.PreviewMouseUp += Window_PreviewMouseUp; _window.PreviewStylusUp += Window_PreviewStylusUp; _window.PreviewMouseDown += Window_PreviewMouseDown; _window.PreviewStylusDown += Window_PreviewStylusDown; _window.DpiChanged += _window_DpiChanged; if (_window.SizeToContent != SizeToContent.Manual) { (_window.Content as FrameworkElement).SizeChanged += _window_SizeChanged; } else { _window.SizeChanged += _window_SizeChanged; } SetupHideTimer(); }
public MessageWindow(CS classStyle, WS style, WS_EX exStyle, Rect location, string name, WndProc callback) { this._wndProcCallback = callback; this._className = "MessageWindowClass+" + Guid.NewGuid().ToString(); WNDCLASSEX wNDCLASSEX = new WNDCLASSEX { cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)), style = classStyle, lpfnWndProc = MessageWindow.s_WndProc, hInstance = NativeMethods.GetModuleHandle(null), hbrBackground = NativeMethods.GetStockObject(StockObject.NULL_BRUSH), lpszMenuName = "", lpszClassName = this._className }; NativeMethods.RegisterClassEx(ref wNDCLASSEX); GCHandle value = default(GCHandle); try { value = GCHandle.Alloc(this); IntPtr lpParam = (IntPtr)value; this.Handle = NativeMethods.CreateWindowEx(exStyle, this._className, name, style, (int)location.X, (int)location.Y, (int)location.Width, (int)location.Height, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, lpParam); } finally { value.Free(); } }
private static IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam) { IntPtr zero = IntPtr.Zero; MessageWindow target = null; if (msg == WM.CREATE) { CREATESTRUCT structure = (CREATESTRUCT)Marshal.PtrToStructure(lParam, typeof(CREATESTRUCT)); target = (MessageWindow)GCHandle.FromIntPtr(structure.lpCreateParams).Target; MessageWindow.s_windowLookup.Add(hwnd, target); } else if (!MessageWindow.s_windowLookup.TryGetValue(hwnd, out target)) { return(Standard.NativeMethods.DefWindowProcW(hwnd, msg, wParam, lParam)); } WndProc wndProc = target._wndProcCallback; zero = (wndProc == null ? Standard.NativeMethods.DefWindowProcW(hwnd, msg, wParam, lParam) : wndProc(hwnd, msg, wParam, lParam)); if (msg == WM.NCDESTROY) { target._Dispose(true, true); GC.SuppressFinalize(target); } return(zero); }
/// <summary> /// /// </summary> /// <param name="className"></param> /// <param name="callback"></param> public RegisterWindow(string className, Action <WindowMessage> callback) { if (className == null) { throw new Exception("className is null"); } if (className == string.Empty) { throw new Exception("className is empty"); } _customWndProc = callback; _wndProcDelegate = ProxyWndProc; WndClassStruct wndClass = new WndClassStruct { lpszClassName = className, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_wndProcDelegate) }; ushort classAtom = RegisterClassW(ref wndClass); int lastError = Marshal.GetLastWin32Error(); if (classAtom == 0 && lastError != ERROR_CLASS_ALREADY_EXISTS) { throw new Exception("Could not register window class"); } _hwnd = CreateWindowExW( 0, className, string.Empty, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero ); Logger.Info("Created window " + _hwnd); if (!ChangeWindowMessageFilterEx(_hwnd, WM_COPYDATA, ChangeWindowMessageFilterExAction.Allow, IntPtr.Zero)) { var isAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); Logger.Warn("Failed to remove UIPI filter restrictions."); if (isAdmin) { Logger.Fatal("Running as administrator, will not be able to communicate with GD due to UIPI filter."); } else { Logger.Info("Not running as administrator, UIPI filter not required."); } } }
private static ushort CreateWindowClass(WndProc wndProc, string menuName, string className) { var wnd = new WindowClassEx() { cbSize = WindowClassEx.GetSize(), style = 0, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(wndProc), cbClsExtra = 0, cbWndExtra = 0, hInstance = IntPtr.Zero, hIcon = IntPtr.Zero, hCursor = IntPtr.Zero, hbrBackground = IntPtr.Zero, lpszMenuName = menuName, lpszClassName = className, hIconSm = IntPtr.Zero }; var regResult = User32.RegisterClassEx(ref wnd); if (regResult == 0) { ExceptionHelper.ThrowLastWin32Exception(); } return(regResult); }
/// <summary> /// Function to hook the window procedure. /// </summary> /// <param name="windowHandle">Window handle to hook.</param> private void HookWindowProc(IntPtr windowHandle) { // Only need to hook the application window, but if that's not available for whatever reason // we can hook into the control being used to receive raw input events. At the very minimum we // need a window of some kind in order to process the WM_INPUT event. If one is not available, // then we must throw an exception. if (MessageFilter != null) { return; } if (windowHandle == IntPtr.Zero) { if (Gorgon.ApplicationForm == null) { throw new ArgumentException(Resources.GORINP_RAW_NO_WINDOW_TO_BIND, "windowHandle"); } windowHandle = Gorgon.ApplicationForm.Handle; } _hookedWindow = windowHandle; // Hook the window procedure. _oldWndProc = Win32API.GetWindowLong(new HandleRef(this, _hookedWindow), WindowLongType.WndProc); _wndProc = RawWndProc; _newWndProc = Marshal.GetFunctionPointerForDelegate(_wndProc); Win32API.SetWindowLong(new HandleRef(this, _hookedWindow), WindowLongType.WndProc, _newWndProc); MessageFilter = new MessageFilter(); }
public static void Initialize(GameWindow window) { if (initialized) { throw new InvalidOperationException("KeyboardInput.Initialize can only be called once!"); } hookProcDelegate = new WndProc(HookProc); //set Wnd long before Init IME SetWindowLong(window.Handle, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(hookProcDelegate)); ImmReleaseContext(window.Handle, (IntPtr)Traverse.Create(typeof(KeyboardInput)).Field("hIMC").GetValue()); api = new IMM(); api.Initialize(window.Handle); //Composition api.m_compositionHandler.eventComposition += IMEControl_CompositionEvent; api.m_compositionHandler.eventGetTextExt += IMEControl_GetCompExtEvent; prevWndProc = (IntPtr)Traverse.Create(typeof(KeyboardInput)).Field("prevWndProc").GetValue(); CharEntered += KeyboardInput__CharEntered; KeyDown += KeyboardInput__KeyDown; initialized = true; }
public CustomWindow() { Messages = new List <YourType>(); var className = "Prototype Messaging Class"; WndProc mWndProcDelegate = CustomWndProc; // Create WNDCLASS WNDCLASS windClass = new WNDCLASS { lpszClassName = className, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(mWndProcDelegate) }; UInt16 classAtom = Importer.RegisterClassW(ref windClass); int lastError = Marshal.GetLastWin32Error(); if (classAtom == 0 && lastError != ErrorClassAlreadyExists) { throw new Exception("Could not register window class"); } // Create window Handle = Importer.CreateWindowExW( 0, className, "Prototype Messaging Window", 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero ); }
public static bool Initialize(IntPtr handle) { if (_isInitialized) { //throw new InvalidOperationException("TextInput.Initialize can only be called once!"); return false; } hookProcDelegate = new WndProc(HookProc); prevWndProc = SetWindowLongPtr(new HandleRef(null, handle), GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(hookProcDelegate)); hIMC = ImmGetContext(handle); RawInputDevice[] rid = new RawInputDevice[1]; rid[0].UsagePage = HIDUsagePage.Generic; //0x01; rid[0].Usage = HIDUsage.Mouse; //0x02; rid[0].Flags = RawInputDeviceFlags.InputSink;// | RawInputDeviceFlags.CaptureMouse; rid[0].WindowHandle = handle; //rid[1].UsagePage = HIDUsagePage.Keyboard; //rid[1].Usage = HIDUsage.Keyboard; //rid[1].Flags = RawInputDeviceFlags.AppKeys; //rid[1].WindowHandle = handle; if (!RegisterRawInputDevices(rid, rid.Length, Marshal.SizeOf(rid[0]))) { //throw new ApplicationException("Failed to register raw input device(s)."); return false; } _isInitialized = true; return true; }
public WindowCreator(RawInputParser rawInputParser) { RawInputParser = rawInputParser; WndProcDelegate = WndProc; windowClassName += Guid.NewGuid().ToString(); }
/// <summary> /// 重新设置窗口的窗口过程,保证窗口过程是 <see cref="WndProc(IntPtr, uint, IntPtr, IntPtr)"/> /// </summary> /// <remarks> /// 该函数并非无意义,我们定义 <see cref="WndProc(IntPtr, uint, IntPtr, IntPtr)"/> 为窗口过程,子类通过重写该过程实现 /// 窗口消息的处理。但是,如果子类要自己定义窗口类,那么必然存在将窗口过程设置为其他的情况,为了保证正常,所有才会有这个方法; /// 另外,窗口过程是switch,如果switch的判断内容过多,会造成性能的下降,该方法也可以将创建将创建时的窗口过程和实际执行的窗口 /// 过程进行分离,从而实现减少实际窗口过程的switch判断的目的。 /// </remarks> private void SubclassWndProc() { _wndProc = new WndProc(WndProc); ApiUser32.SetWindowLong( _handle, GWLIndex.GWLP_WNDPROC, Marshal.GetFunctionPointerForDelegate(_wndProc)); }
/// <summary> /// Creates a hook for the WindowProc function. /// </summary> /// <param name="hWnd">Handle of the window to hook.</param> /// <param name="wndProcHandler">Handles the WndProc function.</param> public WndProcHook(IntPtr hWnd, WndProc wndProcHandler) { WindowHandle = hWnd; var windowProc = Native.GetWindowLong(hWnd, Native.GWL.GWL_WNDPROC); Misc.Debug.WriteLine($"WindowProc: {(long)windowProc:X}"); SetupHook(wndProcHandler, windowProc); }
public static IntPtr SetWindowLong(HandleRef hwnd, WindowLongType index, WndProc wndProc) { if (IntPtr.Size == 4) { return(SetWindowLong32(hwnd, index, wndProc)); } return(SetWindowLongPtr64(hwnd, index, wndProc)); }
public MessagePumpWindow(WndProc wndProc) { _wndProc = wndProc; lock (_syncRoot) { _thread = new Thread(MessagePump); RegisterWindowClass(); } }
void OnDisable() { SetWindowLongPtr(wndHandle, GWL_WNDPROC, (long)unityWndProc); wndHandle = IntPtr.Zero; unityWndProc = IntPtr.Zero; hook = null; }
public NativeWindow(string className, string caption, int width, int height) { ClassName = className; Handle = IntPtr.Zero; Instance = System.Diagnostics.Process.GetCurrentProcess ().Handle; WindowProcedureDelegate = WindowProcedure; RegisterClass (); CreateWindow (caption, width, height); }
public DragWindowHandler(IntPtr handle, IChromelyNativeHost nativeHost, FramelessOption framelessOption) { _handle = handle; _nativeHost = nativeHost; _framelessOption = framelessOption ?? new FramelessOption(); _originalWndProc = GetWindowLongPtr(_handle, (int)GWL.WNDPROC); _wndProc = WndProc; _wndProcPtr = Marshal.GetFunctionPointerForDelegate(_wndProc); SetWindowLongPtr(_handle, (int)GWL.WNDPROC, _wndProcPtr); }
public static void CreateWindow(int x, int y, int width, int height, WndProc wndProc, out IntPtr hWnd, out ushort regResult) { regResult = CreateWindowClass(wndProc); hWnd = CreateWindow(regResult, x, y, width, height, WindowStyle, WindowStyleEx); User32.SetLayeredWindowAttributes(hWnd, 0, 255, LayeredWindowAttributes.Alpha); User32.UpdateWindow(hWnd); ExtendFrameIntoClient(hWnd, x, y, width, height); }
public WndProcInputService(IntPtr handle) { _wndProc = new WndProc(handle); _wndProc.MouseWheel += AddEvent; _wndProc.MouseMove += OnMouseMove; _wndProc.MouseUp += OnMouseUp; _wndProc.MouseDown += OnMouseDown; _wndProc.KeyDown += OnKeyDown; _wndProc.KeyUp += OnKeyUp; _wndProc.KeyChar += OnKeyChar; }
public static void Initialize(GameWindow window) { if (initialized) { throw new InvalidOperationException("TextInput.Initialize can only be called once!"); } hookProcDelegate = HookProc; prevWndProc = (IntPtr)SetWindowLong(window.Handle, -4, (int)Marshal.GetFunctionPointerForDelegate((Delegate)hookProcDelegate)); hIMC = ImmGetContext(window.Handle); initialized = true; }
public InputManager(IntPtr handle) { m_WndProc = new WndProc(handle); m_WndProc.MouseWheel += onMouseWheel; m_WndProc.MouseMove += onMouseMove; m_WndProc.MouseUp += onMouseUp; m_WndProc.MouseDown += onMouseDown; m_WndProc.KeyDown += onKeyDown; m_WndProc.KeyUp += onKeyUp; m_WndProc.KeyChar += onKeyChar; }
public Window(int width, int height, string title) { isOpen = true; process = WindowProcess; processHandle = Process.GetCurrentProcess().Handle; windowClass = GetRegisteredWindowClass(); windowHandle = CreateWindow(width, height, title); deviceContext = Win.GetDC(windowHandle); CreateContext(); }
/// <summary> /// Initialize the TextInput with the given GameWindow. /// </summary> /// <param name="window">The XNA window to which text input should be linked.</param> public static void Initialize( GameWindow window ) { if( initialized ) throw new InvalidOperationException( "TextInput.Initialize can only be called once!" ); hookProcDelegate = new WndProc( HookProc ); prevWndProc = (IntPtr) SetWindowLong( window.Handle, GWL_WNDPROC, (int) Marshal.GetFunctionPointerForDelegate( hookProcDelegate ) ); hIMC = ImmGetContext( window.Handle ); initialized = true; }
public MessageWindow(CS classStyle, WS style, WS_EX exStyle, Rect location, string name, WndProc callback) { // A null callback means just use DefWindowProc. _wndProcCallback = callback; _className = "MessageWindowClass+" + Guid.NewGuid().ToString(); var wc = new WNDCLASSEX { cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)), style = classStyle, lpfnWndProc = s_WndProc, hInstance = NativeMethods.GetModuleHandle(null), hbrBackground = NativeMethods.GetStockObject(StockObject.NULL_BRUSH), lpszMenuName = "", lpszClassName = _className, }; NativeMethods.RegisterClassEx(ref wc); GCHandle gcHandle = default(GCHandle); try { gcHandle = GCHandle.Alloc(this); IntPtr pinnedThisPtr = (IntPtr)gcHandle; Handle = NativeMethods.CreateWindowEx( exStyle, _className, name, style, (int)location.X, (int)location.Y, (int)location.Width, (int)location.Height, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pinnedThisPtr); } finally { gcHandle.Free(); } _dispatcher = Dispatcher.CurrentDispatcher; }
public EVRPlayListener(MainForm parent) { m_parent = parent; m_KeepMe = new WndProc(CustomWndProc); IntPtr hInstance = Marshal.GetHINSTANCE(this.GetType().Module); WNDCLASSEX wndClassEx = new WNDCLASSEX(); wndClassEx.cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)); wndClassEx.style = ClassStyle.GLOBALCLASS; wndClassEx.cbClsExtra = 0; wndClassEx.cbWndExtra = 0; wndClassEx.hbrBackground = IntPtr.Zero; wndClassEx.hCursor = IntPtr.Zero; wndClassEx.hIcon = IntPtr.Zero; wndClassEx.hIconSm = IntPtr.Zero; wndClassEx.lpszClassName = EVR_CLASS; wndClassEx.lpszMenuName = null; wndClassEx.hInstance = hInstance; wndClassEx.lpfnWndProc = m_KeepMe; ushort atom = RegisterClassEx(ref wndClassEx); //WNDCLASSEX lpwcx; //bool isReg = GetClassInfoEx(hInstance, EVR_CLASS, out lpwcx); if (atom == 0) { int error = Marshal.GetLastWin32Error(); throw new Win32Exception(error); } // Create window //m_hwnd = CreateWindowEx( // WindowStyle.EX_NOACTIVATE, // atom, // EVR_WIN, // 0, // 0, // 0, // 0, // 0, // IntPtr.Zero, // IntPtr.Zero, // Marshal.GetHINSTANCE(parent.GetType().Module), // IntPtr.Zero //); m_hwnd = CreateWindowEx( WindowStyle.EX_NOACTIVATE, EVR_CLASS, EVR_WIN, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero ); if (m_hwnd == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); throw new Win32Exception(error); } }
internal GameWindow(int x, int y, int width, int height, string title, IntPtr icon, IntPtr smallIcon, Action onTimer) { this.onTimer = onTimer; wndProc = ProcessMessages; WNDCLASSEX wc = new WNDCLASSEX { cbSize = (uint)WNDCLASSEX.SizeInBytes, //style = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw, style = ClassStyles.OwnDC | ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw, hInstance = instance, lpfnWndProc = wndProc, lpszClassName = className, hIcon = icon, hIconSm = smallIcon, hCursor = Functions.LoadCursor(NULL, IDC.ARROW), hbrBackground = NULL, cbClsExtra = 0, cbWndExtra = 0, lpszMenuName = null }; short atom = Functions.RegisterClassEx(ref wc); if (atom == 0) throw new Exception(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error())); const WS style = //(WS)0x16cf0000; //WS.CAPTION | WS.VISIBLE | WS.CLIPSIBLINGS | WS.CLIPCHILDREN | //WS.SYSMENU | WS.SIZEFRAME | WS.OVERLAPPEDWINDOW | WS.MINIMIZEBOX | WS.MAXIMIZEBOX; (WS)114229248; const WS_EX exStyle = //(WS_EX)0x00040100; //WS_EX.LEFT | WS_EX.LTRREADING | WS_EX.RIGHTSCROLLBAR | //WS_EX.WINDOWEDGE | WS_EX.APPWINDOW; (WS_EX)262401 ^ WS_EX.DLGMODALFRAME; //IntPtr windowName = Marshal.StringToHGlobalAuto(title); // Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). RECT rect = new RECT { left = x, top = y, right = x + width, bottom = y + height }; Functions.AdjustWindowRectEx(ref rect, style, false, exStyle); hwnd = Functions.CreateWindowEx( exStyle, className, title, style, rect.left, rect.top, rect.Width, rect.Height, IntPtr.Zero, IntPtr.Zero, instance, IntPtr.Zero); if (hwnd == IntPtr.Zero) throw new Exception(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error())); Functions.GetClientRect(hwnd, out clientRectangle); input = new Input(GetClientRect); }
/// <summary> /// Initializes a new instance of the <see cref="RemovableDriveMonitor"/> class. /// Default Constructor /// </summary> public RemovableDriveMonitor() { var wc = new WNDCLASS(); // Preventing garbage collection of the delegate dontGCthis = new WndProc(this.Callback); wc.lpfnWndProc = dontGCthis; // Note that you need to ensure unique names // for each registered class. // For example, if you open the same plugin // in two different tabs of the browser, // you still should not end up with // two registered classes with identical names. wc.lpszClassName = "foobar" + (new Random()).Next(); RegisterClass(wc); var createResult = CreateWindowEx(0, wc.lpszClassName, "Window title", 0, 100, 100, 500, 500, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0); }
private static extern IntPtr SetWindowLongPtr64(HandleRef hwnd, WindowLongType index, WndProc wndProc);
/// <summary> /// Initialize the TextInput with the given GameWindow. /// </summary> /// <param name="handle">The XNA window to which text input should be linked.</param> public static void Initialize(IntPtr handle) { if (Initialized) throw new InvalidOperationException("TextInput.Initialize can only be called once!"); _hookProcDelegate = HookProc; _prevWndProc = (IntPtr)SetWindowLong(handle, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(_hookProcDelegate)); _hImc = ImmGetContext(handle); Initialized = true; }
public void CreateMainWindowNative(int width, int height) { const int CS_VREDRAW = 0x0001; const int CS_HREDRAW = 0x0002; // Register class _proc_native = InternalProcessNativeWindowMessage; WNDCLASSEX wcx = WNDCLASSEX.Build(); wcx.style = CS_VREDRAW | CS_HREDRAW; wcx.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_proc_native); wcx.hInstance = GetModuleHandle(null); wcx.lpszClassName = "OMG MEOW"; short a = RegisterClassExW(ref wcx); uint styleEx = 0; uint style = (uint) WindowStyles.WS_OVERLAPPEDWINDOW; _hwnd = CreateWindowExW(styleEx, "OMG MEOW", null, style, -1, 0, width, height, IntPtr.Zero, IntPtr.Zero, wcx.hInstance, IntPtr.Zero); Debug.Assert(_hwnd != IntPtr.Zero); }
// Using this seems to cause some problems. Something isnt disposed I think? public static void Reinitialize(IntPtr handle) { _hookProcDelegate = SystemInput.HookProc; _prevWndProc = (IntPtr)SystemInput.SetWindowLong(handle, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(_hookProcDelegate)); _hIMC = SystemInput.ImmGetContext(handle); }
static SystemInput() { if (FlaiGame.Current == null) { throw new InvalidOperationException("Instance of FlaiGame must be initialized before accessing SystemInput"); } _hookProcDelegate = SystemInput.HookProc; _prevWndProc = (IntPtr)SystemInput.SetWindowLong(FlaiGame.Current.Window.Handle, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(_hookProcDelegate)); _hIMC = SystemInput.ImmGetContext(FlaiGame.Current.Window.Handle); }
/// <summary> /// Creates a new instance of PageantWindow that acts as a server for /// Putty-type clients. /// </summary> /// <exception cref="PageantRunningException"> /// Thrown when another instance of Pageant is running. /// </exception> /// <remarks>This window is not meant to be used for UI.</remarks> public PageantAgent() { DoOSCheck(); if (CheckPageantRunning()) { throw new PageantRunningException(); } // create reference to delegate so that garbage collector does not eat it. customWndProc = new WndProc(CustomWndProc); // Create WNDCLASS WNDCLASS wind_class = new WNDCLASS(); wind_class.lpszClassName = className; wind_class.lpfnWndProc = customWndProc; UInt16 class_atom = RegisterClassW(ref wind_class); int last_error = Marshal.GetLastWin32Error(); if (class_atom == 0 && last_error != ERROR_CLASS_ALREADY_EXISTS) { throw new Exception("Could not register window class"); } Thread winThread = new Thread(RunWindowInNewAppcontext); winThread.SetApartmentState(ApartmentState.STA); winThread.Name = "PageantWindow"; lock (lockObject) { winThread.Start(); // wait for window to be created before continuing to prevent more than // one instance being run at a time. if (!Monitor.Wait(lockObject, 5000)) { if (winThread.ThreadState == System.Threading.ThreadState.Running) { throw new TimeoutException("PageantAgent start timed out."); } else { throw new Exception("PageantAgent failed to start."); } } } }
private XplatUIWin32() { // Handle singleton stuff first ref_count=0; mouse_state = MouseButtons.None; mouse_position = Point.Empty; grab_confined = false; grab_area = Rectangle.Empty; message_queue = new Queue(); themes_enabled = false; wnd_proc = new WndProc(InternalWndProc); FosterParent=Win32CreateWindow(WindowExStyles.WS_EX_TOOLWINDOW, "static", "Foster Parent Window", WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (FosterParent==IntPtr.Zero) { Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0); } scroll_height = Win32GetSystemMetrics(SystemMetrics.SM_CYHSCROLL); scroll_width = Win32GetSystemMetrics(SystemMetrics.SM_CXVSCROLL); timer_list = new Hashtable (); registered_classes = new Hashtable (); }
public static extern IntPtr SetWindowLong( IntPtr window, int index, WndProc value);
public static IntPtr SetWindowLong(HandleRef hwnd, WindowLongType index, WndProc wndProc) { if (IntPtr.Size == 4) { return SetWindowLong32(hwnd, index, wndProc); } return SetWindowLongPtr64(hwnd, index, wndProc); }
/// <summary> /// Creates window that would receive plug in/out device events /// </summary> /// <returns></returns> IntPtr CreateReceiverWnd() { IntPtr wndHnd = IntPtr.Zero; m_wnd_proc_delegate = CustomWndProc; // Create WNDCLASS Native.WNDCLASS wind_class = new Native.WNDCLASS(); wind_class.lpszClassName = NOTIFICATION_WND_CLS; wind_class.lpfnWndProc = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(m_wnd_proc_delegate); UInt16 class_atom = Native.RegisterClassW(ref wind_class); int last_error = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); if (class_atom == 0 && last_error != ERROR_CLASS_ALREADY_EXISTS) { Exception e = new System.Exception("Could not register window class"); UnityEngine.Debug.LogException(e); return IntPtr.Zero; } try { // Create window wndHnd = Native.CreateWindowExW( 0, wind_class.lpszClassName, String.Empty, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero ); } catch (Exception e) { UnityEngine.Debug.LogException(e); } return wndHnd; }
public Subclasser(IntPtr hWnd, WndProc proc) { Handle = hWnd; this.proc = proc; }
private XplatUIWin32() { // Handle singleton stuff first ref_count=0; mouse_state = MouseButtons.None; mouse_position = Point.Empty; grab_confined = false; grab_area = Rectangle.Empty; message_queue = new Queue(); themes_enabled = false; wnd_proc = new WndProc(InternalWndProc); FosterParentLast = IntPtr.Zero; scroll_height = Win32GetSystemMetrics(SystemMetrics.SM_CYHSCROLL); scroll_width = Win32GetSystemMetrics(SystemMetrics.SM_CXVSCROLL); timer_list = new Hashtable (); registered_classes = new Hashtable (); }
public static void Initialize(GameWindow window) { if(created) throw new InvalidOperationException("WinHook Can Only Initialize Once"); created = true; hookProcDelegate = HookProc; prevWndProc = (IntPtr)SetWindowLong(window.Handle, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(hookProcDelegate)); hIMC = ImmGetContext(window.Handle); MouseEventDispatcher.SetToHook(); }