public WindowClass(string registeredClassName) { _windowProcedure = WindowProcedure; _className = registeredClassName; _menuName = string.Empty; ModuleInstance = ModuleInstance.Null; }
/// <summary> /// Wrapper to SetWindowLong for changing the window procedure. Returns the old /// window procedure handle- use CallWindowProcedure to call the old method. /// </summary> public static IntPtr SetWindowProcedure(WindowHandle window, WindowProcedure newCallback) { // It is possible that the returned window procedure will not be a direct handle. return(SetWindowLong(window, WindowLong.WindowProcedure, Marshal.GetFunctionPointerForDelegate(newCallback))); }
const long ExtendedBit = 1 << 24; // Used to distinguish left and right control, alt and enter keys. public WinWindow(int x, int y, int width, int height, string title, DisplayDevice device) { WindowProcedureDelegate = WindowProcedure; UngroupFromTaskbar(); WinHandle = CreateWindow(x, y, width, height, title, device); Exists = true; }
public WinGLNative(int x, int y, int width, int height, string title, DisplayDevice device) { WindowProcedureDelegate = WindowProcedure; UngroupFromTaskbar(); window = new WinWindowInfo(CreateWindow(x, y, width, height, title, device)); exists = true; }
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) { // This is the main window procedure callback. We need the callback in order to create the window, so // don't move it below the CreateWindow calls. WindowProcedureDelegate = WindowProcedure; //// This timer callback is called periodically when the window enters a sizing / moving modal loop. //ModalLoopCallback = delegate(IntPtr handle, WindowMessage msg, UIntPtr eventId, int time) //{ // // Todo: find a way to notify the frontend that it should process queued up UpdateFrame/RenderFrame events. // if (Move != null) // Move(this, EventArgs.Empty); //}; // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be // bound to the top-level window, but rather to a child window docked in the parent. window = new WinWindowInfo( CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), null); child_window = new WinWindowInfo( CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window); exists = true; keyboard.Description = "Standard Windows keyboard"; keyboard.NumberOfFunctionKeys = 12; keyboard.NumberOfKeys = 101; keyboard.NumberOfLeds = 3; mouse.Description = "Standard Windows mouse"; mouse.NumberOfButtons = 3; mouse.NumberOfWheels = 1; keyboards.Add(keyboard); mice.Add(mouse); }
public WinInputBase() { this.WndProc = new WindowProcedure(this.WindowProcedure); this.InputThread = new Thread(new ThreadStart(this.ProcessEvents)); this.InputThread.IsBackground = true; this.InputThread.Start(); this.InputReady.WaitOne(); }
private void ChangeShockWaveWindowProcedure(IntPtr theHandle) { if (theHandle != IntPtr.Zero) { HookedWindowHandle = theHandle; newWindowProcedure = new WindowProcedure(newWindowProc); oldWindowProcedure = SetWindowLong(HookedWindowHandle, GWL_WNDPROC, newWindowProcedure); } }
public WinInputBase() { WndProc = WindowProcedure; InputThread = new Thread(ProcessEvents); InputThread.IsBackground = true; InputThread.Start(); InputReady.WaitOne(); }
public WinInputBase() { WndProc = WndProcHandler; Parent = new WinWindowInfo(NativeWindow.OsuWindowHandle, null); CreateDrivers(); // Subclass the window to retrieve the events we are interested in. OldWndProc = Functions.SetWindowLong(Parent.Handle, WndProc); Debug.Print("Input window attached to {0}", Parent); }
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) { WindowProcedureDelegate = WindowProcedure; // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be // bound to the top-level window, but rather to a child window docked in the parent. window = new WinWindowInfo( CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), null); child_window = new WinWindowInfo( CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window); exists = true; }
public void WindowCallback_Subclass() { int value = 42; WindowClass myClass = new WindowClass { ClassName = "WindowCallback_Subclass", WindowProcedure = (window, message, wParam, lParam) => { return(value); } }; Atom atom = WindowMethods.RegisterClass(ref myClass); atom.IsValid.Should().BeTrue(); try { WindowHandle window = WindowMethods.CreateWindow(atom, null, WindowStyles.Minimize | WindowStyles.Diabled); window.IsValid.Should().BeTrue(); try { WindowMethods.SendMessage(window, WindowMessage.Activate, 0, 0).Should().Be((LRESULT)42); IntPtr previous = IntPtr.Zero; WindowProcedure subClass = (w, m, wParam, lParam) => { return(WindowMethods.CallWindowProcedure(previous, w, m, wParam, lParam)); }; value = 1999; previous = WindowMethods.SetWindowProcedure(window, subClass); WindowMethods.SendMessage(window, WindowMessage.Activate, 0, 0).Should().Be((LRESULT)1999); GC.KeepAlive(subClass); } finally { WindowMethods.DestroyWindow(window); } } finally { WindowMethods.UnregisterClass(atom, null); } }
public void WindowCallback_Subclass() { int value = 42; WindowClassInfo myClass = new WindowClassInfo { ClassName = "WindowCallback_Subclass", WindowProcedure = (window, message, wParam, lParam) => { return(value); } }; Atom atom = Windows.RegisterClass(ref myClass); atom.IsValid.Should().BeTrue(); try { WindowHandle window = Windows.CreateWindow(atom, style: WindowStyles.Minimize | WindowStyles.Diabled); window.IsInvalid.Should().BeFalse(); try { Windows.SendMessage(window, MessageType.Activate, 0, 0).Should().Be((LResult)42); WNDPROC previous = default; WindowProcedure subClass = (w, m, wParam, lParam) => { return(Windows.CallWindowProcedure(previous, w, m, wParam, lParam)); }; value = 1999; previous = Windows.SetWindowProcedure(window, subClass); Windows.SendMessage(window, MessageType.Activate, 0, 0).Should().Be((LResult)1999); GC.KeepAlive(subClass); } finally { Windows.DestroyWindow(window); } } finally { Windows.UnregisterClass(atom, null); } }
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) { lock (WinGLNative.SyncRoot) { this.WindowProcedureDelegate = new WindowProcedure(this.WindowProcedure); this.window = new WinWindowInfo(this.CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), (WinWindowInfo)null); this.child_window = new WinWindowInfo(this.CreateWindow(0, 0, this.ClientSize.Width, this.ClientSize.Height, title, options, device, this.window.WindowHandle), this.window); this.exists = true; this.keyboard.Description = "Standard Windows keyboard"; this.keyboard.NumberOfFunctionKeys = 12; this.keyboard.NumberOfKeys = 101; this.keyboard.NumberOfLeds = 3; this.mouse.Description = "Standard Windows mouse"; this.mouse.NumberOfButtons = 3; this.mouse.NumberOfWheels = 1; this.keyboards.Add(this.keyboard); this.mice.Add(this.mouse); } }
private NativeClass() { this.LoadIcon(); this.windowProcedure = new WindowProcedure(this.Callback); var windowProcedurePtr = Marshal.GetFunctionPointerForDelegate(this.windowProcedure); ClassInfoEx windowClass = new ClassInfoEx( ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw, windowProcedurePtr, IntPtr.Zero, icon != null ? icon.Handle : NativeMethods.LoadIcon(IntPtr.Zero, new IntPtr(32512)), NativeMethods.LoadCursor(IntPtr.Zero, new IntPtr(32512)), IntPtr.Zero, null, typeof(NativeClass).FullName, IntPtr.Zero); ushort atom = NativeMethods.RegisterClassEx(ref windowClass); this.atom = new IntPtr(atom); }
public unsafe WindowClass( string className = default, ModuleInstance moduleInstance = default, ClassStyle classStyle = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw, BrushHandle backgroundBrush = default, IconHandle icon = default, IconHandle smallIcon = default, CursorHandle cursor = default, string menuName = null, int menuId = 0, int classExtraBytes = 0, int windowExtraBytes = 0) { // Handle default values className = className ?? Guid.NewGuid().ToString(); if (backgroundBrush == default) { backgroundBrush = SystemColor.Window; } else if (backgroundBrush == BrushHandle.NoBrush) { backgroundBrush = default; } if (icon == default) { icon = IconId.Application; } else if (icon == IconHandle.NoIcon) { icon = default; } if (cursor == default) { cursor = CursorId.Arrow; } else if (cursor == CursorHandle.NoCursor) { cursor = default; } // Unfortunately GetHINSTANCE isn't part of .NET Standard if (moduleInstance == default) { var method = typeof(Marshal).GetMethod("GetHINSTANCE"); Module module = Assembly.GetCallingAssembly().Modules.First(); moduleInstance = (IntPtr)method.Invoke(null, new object[] { module }); } if (menuId != 0 && menuName != null) { throw new ArgumentException("Can only set menu name or ID."); } _windowProcedure = WindowProcedure; ModuleInstance = moduleInstance; _className = className; _menuName = menuName ?? string.Empty; _wndClass = new WNDCLASSEX { cbSize = (uint)sizeof(WNDCLASSEX), style = classStyle, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_windowProcedure), cbClassExtra = classExtraBytes, cbWndExtra = windowExtraBytes, hInstance = (IntPtr)moduleInstance, hIcon = icon, hCursor = cursor, hbrBackground = backgroundBrush, hIconSm = smallIcon, lpszMenuName = (char *)menuId }; }
protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam) { switch (message) { case MessageType.Create: // Create the white-rectangle window against which the // scroll bars will be positioned. The child window ID is 9. hwndRect = Windows.CreateWindow( className: "static", style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.WhiteRectangle, parentWindow: window, menuHandle: (MenuHandle)9, instance: ModuleInstance); for (int i = 0; i < 3; i++) { // The three scroll bars have IDs 0, 1, and 2, with // scroll bar ranges from 0 through 255. hwndScroll[i] = Windows.CreateWindow( className: "scrollbar", style: WindowStyles.Child | WindowStyles.Visible | WindowStyles.TabStop | (WindowStyles)ScrollBarStyles.Veritcal, parentWindow: window, menuHandle: (MenuHandle)i, instance: ModuleInstance); hwndScroll[i].SetScrollRange(ScrollBar.Control, 0, 255, false); hwndScroll[i].SetScrollPosition(ScrollBar.Control, 0, false); // The three color-name labels have IDs 3, 4, and 5, // and text strings “Red”, “Green”, and “Blue”. hwndLabel[i] = Windows.CreateWindow( className: "static", windowName: szColorLabel[i], style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Center, parentWindow: window, menuHandle: (MenuHandle)(i + 3), instance: ModuleInstance); // The three color-value text fields have IDs 6, 7, // and 8, and initial text strings of “0”. hwndValue[i] = Windows.CreateWindow( className: "static", windowName: "0", style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Center, parentWindow: window, menuHandle: (MenuHandle)(i + 6), instance: ModuleInstance); OldScroll[i] = hwndScroll[i].SetWindowProcedure(_scrollProcedure = ScrollProcedure); hBrush[i] = Gdi.CreateSolidBrush(crPrim[i]); } hBrushStatic = Gdi.GetSystemColorBrush(SystemColor.ButtonHighlight); cyChar = Windows.GetDialogBaseUnits().Height; return(0); case MessageType.Size: int cxClient = lParam.LowWord; int cyClient = lParam.HighWord; rcColor = Rectangle.FromLTRB(cxClient / 2, 0, cxClient, cyClient); hwndRect.MoveWindow(new Rectangle(0, 0, cxClient / 2, cyClient), repaint: true); for (int i = 0; i < 3; i++) { hwndScroll[i].MoveWindow( new Rectangle((2 * i + 1) * cxClient / 14, 2 * cyChar, cxClient / 14, cyClient - 4 * cyChar), repaint: true); hwndLabel[i].MoveWindow( new Rectangle((4 * i + 1) * cxClient / 28, cyChar / 2, cxClient / 7, cyChar), repaint: true); hwndValue[i].MoveWindow( new Rectangle((4 * i + 1) * cxClient / 28, cyClient - 3 * cyChar / 2, cxClient / 7, cyChar), repaint: true); } window.SetFocus(); return(0); case MessageType.SetFocus: hwndScroll[idFocus].SetFocus(); return(0); case MessageType.VerticalScroll: int id = (int)((WindowHandle)lParam).GetWindowLong(WindowLong.Id); switch ((ScrollCommand)wParam.LowWord) { case ScrollCommand.PageDown: color[id] += 15; goto case ScrollCommand.LineDown; case ScrollCommand.LineDown: color[id] = Math.Min(255, color[id] + 1); break; case ScrollCommand.PageUp: color[id] -= 15; goto case ScrollCommand.LineUp; case ScrollCommand.LineUp: color[id] = Math.Max(0, color[id] - 1); break; case ScrollCommand.Top: color[id] = 0; break; case ScrollCommand.Bottom: color[id] = 255; break; case ScrollCommand.ThumbPosition: case ScrollCommand.ThumbTrack: color[id] = wParam.HighWord; break; default: return(0); } hwndScroll[id].SetScrollPosition(ScrollBar.Control, color[id], true); hwndValue[id].SetWindowText(color[id].ToString()); // We'll dispose when we set the next brush BrushHandle brush = Gdi.CreateSolidBrush(Color.FromArgb(color[0], color[1], color[2])); window.SetClassBackgroundBrush(brush).Dispose(); window.InvalidateRectangle(rcColor, true); return(0); case MessageType.ControlColorScrollBar: return((BrushHandle)hBrush[(int)((WindowHandle)lParam).GetWindowLong(WindowLong.Id)]); case MessageType.ControlColorStatic: id = (int)((WindowHandle)lParam).GetWindowLong(WindowLong.Id); if (id >= 3 && id <= 8) { DeviceContext dc = (DeviceContext)wParam; dc.SetTextColor(crPrim[id % 3]); dc.SetBackgroundColor(Windows.GetSystemColor(SystemColor.ButtonHighlight)); return((BrushHandle)hBrushStatic); } break; case MessageType.SystemColorChange: hBrushStatic = Gdi.GetSystemColorBrush(SystemColor.ButtonHighlight); return(0); case MessageType.Destroy: window.SetClassBackgroundBrush(StockBrush.White).Dispose(); for (int i = 0; i < 3; i++) { hBrush[i].Dispose(); } break; } return(base.WindowProcedure(window, message, wParam, lParam)); }
protected unsafe override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam) { const string filter = "*.*"; switch (message) { case MessageType.Create: Size baseUnits = Windows.GetDialogBaseUnits(); rect = Rectangle.FromLTRB(20 * baseUnits.Width, 3 * baseUnits.Height, rect.Right, rect.Bottom); // Create listbox and static text windows. hwndList = Windows.CreateWindow( className: "listbox", style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ListBoxStyles.Standard, bounds: new Rectangle(baseUnits.Width, baseUnits.Height * 3, baseUnits.Width * 13 + Windows.GetSystemMetrics(SystemMetric.VerticalScrollWidth), baseUnits.Height * 10), parentWindow: window, menuHandle: (MenuHandle)ID_LIST, instance: ModuleInstance); hwndText = Windows.CreateWindow( className: "static", windowName: Storage.GetCurrentDirectory(), style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Left, bounds: new Rectangle(baseUnits.Width, baseUnits.Height, baseUnits.Width * 260, baseUnits.Height), parentWindow: window, menuHandle: (MenuHandle)ID_TEXT, instance: ModuleInstance); _existingListBoxWndProc = hwndList.SetWindowProcedure(_listBoxProcedure = ListBoxProcedure); fixed(char *f = filter) hwndList.SendMessage(ListBoxMessage.Directory, (uint)DIRATTR, f); return(0); case MessageType.Size: rect = Rectangle.FromLTRB(rect.Left, rect.Top, lParam.LowWord, lParam.HighWord); return(0); case MessageType.SetFocus: hwndList.SetFocus(); return(0); case MessageType.Command: if (wParam.LowWord == ID_LIST && (wParam.HighWord == (ushort)ListBoxNotification.DoubleClick)) { uint i = hwndList.SendMessage(ListBoxMessage.GetCurrentSelection, 0, 0); if (i == WindowDefines.LB_ERR) { break; } int iLength = hwndList.SendMessage(ListBoxMessage.GetTextLength, i, 0) + 1; fixed(char *textBuffer = szFile) { int result = hwndList.SendMessage(ListBoxMessage.GetText, i, textBuffer); SafeFileHandle hFile = null; try { using (hFile = Storage.CreateFile(szFile.AsSpan(0, result), CreationDisposition.OpenExisting, DesiredAccess.GenericRead, ShareModes.Read)) { if (!hFile.IsInvalid) { bValidFile = true; hwndText.SetWindowText(Storage.GetCurrentDirectory()); } } hFile = null; } catch { } Span <char> dir = stackalloc char[2]; if (hFile == null && szFile[0] == ('[')) { bValidFile = false; // If setting the directory doesn’t work, maybe it’s a drive change, so try that. try { szFile[result - 1] = '\0'; Storage.SetCurrentDirectory(szFile.AsSpan(1, result - 2)); } catch { dir[0] = szFile[2]; dir[1] = ':'; try { Storage.SetCurrentDirectory(dir); } catch { } } // Get the new directory name and fill the list box. hwndText.SetWindowText(Storage.GetCurrentDirectory()); hwndList.SendMessage(ListBoxMessage.ResetContent, 0, 0); fixed(char *f = filter) hwndList.SendMessage(ListBoxMessage.Directory, (uint)DIRATTR, f); } } window.Invalidate(); } return(0); case MessageType.Paint: if (!bValidFile) { break; } uint bytesRead; using (var hFile = Storage.CreateFile(szFile, CreationDisposition.OpenExisting, DesiredAccess.GenericRead, ShareModes.Read)) { if (hFile.IsInvalid) { bValidFile = false; break; } bytesRead = Storage.ReadFile(hFile, _buffer); } using (DeviceContext dc = window.BeginPaint()) { dc.SelectObject(StockFont.SystemFixed); dc.SetTextColor(SystemColor.ButtonText); dc.SetBackgroundColor(SystemColor.ButtonFace); Encoding.UTF8.GetDecoder().Convert(_buffer.AsSpan(0, (int)bytesRead), _decoded.AsSpan(), true, out _, out int charCount, out _); dc.DrawText(_decoded.AsSpan(0, charCount), rect, DTFLAGS); } return(0); } return(base.WindowProcedure(window, message, wParam, lParam)); }
private static IntPtr SetWindowLongPtr(IntPtr hWnd, GetWindowLongOffsets nIndex, [MarshalAs(UnmanagedType.FunctionPtr)] WindowProcedure dwNewLong);
public static IntPtr SetWindowProcedure(this WindowHandle window, WindowProcedure newCallback) => WindowMethods.SetWindowProcedure(window, newCallback);
/// <summary> /// Creates a message-only window with the specified procedure /// for processing messages. /// </summary> /// <param name="procs"> /// The procedure for processing messages received by the window. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="wndProc"/> is null. /// </exception> public MessageWindow(WindowProcedure wndProc) : this(new[] { wndProc }) { }
internal static IntPtr SetWindowLong(IntPtr handle, WindowProcedure newValue) { return SetWindowLong(handle, GetWindowLongOffsets.WNDPROC, Marshal.GetFunctionPointerForDelegate(newValue)); }
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, WindowProcedure newProc);
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) { lock (SyncRoot) { // This is the main window procedure callback. We need the callback in order to create the window, so // don't move it below the CreateWindow calls. WindowProcedureDelegate = WindowProcedure; //// This timer callback is called periodically when the window enters a sizing / moving modal loop. //ModalLoopCallback = delegate(IntPtr handle, WindowMessage msg, UIntPtr eventId, int time) //{ // // Todo: find a way to notify the frontend that it should process queued up UpdateFrame/RenderFrame events. // if (Move != null) // Move(this, EventArgs.Empty); //}; // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be // bound to the top-level window, but rather to a child window docked in the parent. window = new WinWindowInfo( CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), null); child_window = new WinWindowInfo( CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window); exists = true; keyboard.Description = "Standard Windows keyboard"; keyboard.NumberOfFunctionKeys = 12; keyboard.NumberOfKeys = 101; keyboard.NumberOfLeds = 3; mouse.Description = "Standard Windows mouse"; mouse.NumberOfButtons = 3; mouse.NumberOfWheels = 1; keyboards.Add(keyboard); mice.Add(mouse); } }
public unsafe WindowClass( string?className = default, ModuleInstance?moduleInstance = default, ClassStyle classStyle = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw, BrushHandle backgroundBrush = default, IconHandle icon = default, IconHandle smallIcon = default, CursorHandle cursor = default, string?menuName = null, int menuId = 0, int classExtraBytes = 0, int windowExtraBytes = 0) { // Handle default values className ??= Guid.NewGuid().ToString(); if (backgroundBrush == default) { backgroundBrush = SystemColor.Window; } else if (backgroundBrush == BrushHandle.NoBrush) { backgroundBrush = default; } if (icon == default) { icon = IconId.Application; } else if (icon == IconHandle.NoIcon) { icon = default; } if (cursor == default) { cursor = CursorId.Arrow; } else if (cursor == CursorHandle.NoCursor) { cursor = default; } moduleInstance ??= new ModuleInstance(Marshal.GetHINSTANCE(Assembly.GetCallingAssembly().Modules.First())); if (menuId != 0 && menuName != null) { throw new ArgumentException($"Can't set both {nameof(menuName)} and {nameof(menuId)}."); } _windowProcedure = WindowProcedure; ModuleInstance = moduleInstance; _className = className; _menuName = menuName ?? string.Empty; _wndClass = new WNDCLASSEX { cbSize = (uint)sizeof(WNDCLASSEX), style = classStyle, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_windowProcedure), cbClassExtra = classExtraBytes, cbWndExtra = windowExtraBytes, hInstance = (IntPtr)moduleInstance, hIcon = icon, hCursor = cursor, hbrBackground = backgroundBrush, hIconSm = smallIcon, lpszMenuName = (char *)menuId }; }
public void Run() { if (this.isDestroyed) { return; } this.isInitialized = false; this.doPostQuitMessage = false; this.doOnWindowSizeChanged = false; this.windowProcedure = new WindowProcedure(this.Callback); var windowProcedurePtr = Marshal.GetFunctionPointerForDelegate(this.windowProcedure); NativeMethods.SetWindowLongPtr(this.handle, -4, windowProcedurePtr); NativeMethods.ShowWindow(this.handle, ShowWindow.ShowDefault); this.PerformanceTime.Start(); this.window.Init(); this.PerformanceTime.StopEvent(); WindowMessage message; while (true) { this.PerformanceTime.Tick(); if (this.doPostQuitMessage) { NativeMethods.PostQuitMessage(0); this.doPostQuitMessage = false; break; } if (this.doOnWindowSizeChanged) { this.PerformanceTime.Start(); this.window.OnWindowSizeChanged(); this.PerformanceTime.StopEvent(); this.doOnWindowSizeChanged = false; if (!this.isInitialized) { this.isInitialized = true; } } if (this.window.IsMinimized || !this.isInitialized) { this.PerformanceTime.Start(); NativeMethods.GetMessage(out message, IntPtr.Zero, WindowMessageType.Null, WindowMessageType.Null); this.PerformanceTime.StopEvent(); } else { if (!NativeMethods.PeekMessage(out message, IntPtr.Zero, WindowMessageType.Null, WindowMessageType.Null, 1)) { if (this.window.UpdateWhenInactive || this.window.IsActive) { this.PerformanceTime.Start(); this.window.Update(); this.PerformanceTime.StopUpdate(); } this.PerformanceTime.Start(); this.window.Render(); this.PerformanceTime.StopRender(); this.PerformanceTime.Start(); this.window.Present(); this.PerformanceTime.StopPresent(); continue; } } if (message.Msg == WindowMessageType.Quit) { break; } this.PerformanceTime.Start(); NativeMethods.TranslateMessage(ref message); NativeMethods.DispatchMessage(ref message); this.PerformanceTime.StopEvent(); } }
internal static IntPtr SetWindowLong(IntPtr handle, WindowProcedure newValue) { return(SetWindowLong(handle, GetWindowLongOffsets.WNDPROC, Marshal.GetFunctionPointerForDelegate(newValue))); }
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) { lock (WinGLNative.SyncRoot) { this.WindowProcedureDelegate = new WindowProcedure(this.WindowProcedure); this.window = new WinWindowInfo(this.CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), (WinWindowInfo) null); this.child_window = new WinWindowInfo(this.CreateWindow(0, 0, this.ClientSize.Width, this.ClientSize.Height, title, options, device, this.window.WindowHandle), this.window); this.exists = true; this.keyboard.Description = "Standard Windows keyboard"; this.keyboard.NumberOfFunctionKeys = 12; this.keyboard.NumberOfKeys = 101; this.keyboard.NumberOfLeds = 3; this.mouse.Description = "Standard Windows mouse"; this.mouse.NumberOfButtons = 3; this.mouse.NumberOfWheels = 1; this.keyboards.Add(this.keyboard); this.mice.Add(this.mouse); } }
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) { lock (SyncRoot) { // This is the main window procedure callback. We need the callback in order to create the window, so // don't move it below the CreateWindow calls. WindowProcedureDelegate = WindowProcedure; //// This timer callback is called periodically when the window enters a sizing / moving modal loop. //ModalLoopCallback = delegate(IntPtr handle, WindowMessage msg, UIntPtr eventId, int time) //{ // // Todo: find a way to notify the frontend that it should process queued up UpdateFrame/RenderFrame events. // if (Move != null) // Move(this, EventArgs.Empty); //}; int scale_width = width; int scale_height = height; int scale_x = x; int scale_y = y; if (Toolkit.Options.EnableHighResolution) { // CreateWindow takes values in pixels. // According to the high-dpi guidelines, // we need to scale these values by the // current DPI. // Search MSDN for "How to Ensure That // Your Application Displays Properly on // High-DPI Displays" scale_width = ScaleX(width); scale_height = ScaleY(height); scale_x = ScaleX(x); scale_y = ScaleY(y); } // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be // bound to the top-level window, but rather to a child window docked in the parent. window = new WinWindowInfo( CreateWindow( scale_x, scale_y, scale_width, scale_height, title, options, device, IntPtr.Zero), null); child_window = new WinWindowInfo( CreateWindow( 0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.Handle), window); exists = true; keyboard.Description = "Standard Windows keyboard"; keyboard.NumberOfFunctionKeys = 12; keyboard.NumberOfKeys = 101; keyboard.NumberOfLeds = 3; mouse.Description = "Standard Windows mouse"; mouse.NumberOfButtons = 3; mouse.NumberOfWheels = 1; keyboards.Add(keyboard); mice.Add(mouse); } }