Class WindowComponent
Win32 implementation of IWindowComponent.
Inherited Members
Namespace: OpenTK.Platform.Native.Windows
Assembly: OpenTK.Platform.dll
Syntax
public class WindowComponent : IWindowComponent, IPalComponent
Fields
CLASS_NAME
Class name used to create windows.
Declaration
public const string CLASS_NAME = "OpenTK Window"
Field Value
Type | Description |
---|---|
string |
HInstance
The applications HInstance.
Declaration
public static readonly nint HInstance
Field Value
Type | Description |
---|---|
nint |
Properties
CanCaptureCursor
True when the driver supports capturing the cursor in a window using SetCursorCaptureMode(WindowHandle, CursorCaptureMode).
Declaration
public bool CanCaptureCursor { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
CanGetDisplay
True when the driver can provide the display the window is in using GetDisplay(WindowHandle).
Declaration
public bool CanGetDisplay { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
CanSetCursor
True when the driver supports setting the cursor of the window using SetCursor(WindowHandle, CursorHandle?).
Declaration
public bool CanSetCursor { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
CanSetIcon
True when the driver supports setting the window icon using SetIcon(WindowHandle, IconHandle).
Declaration
public bool CanSetIcon { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
HelperHWnd
The helper window used to load wgl extensions.
Declaration
public static nint HelperHWnd { get; }
Property Value
Type | Description |
---|---|
nint |
Logger
Provides a logger for this component.
Declaration
public ILogger? Logger { get; set; }
Property Value
Type | Description |
---|---|
ILogger |
Name
Name of the abstraction layer component.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
string |
Provides
Specifies which PAL components this object provides.
Declaration
public PalComponents Provides { get; }
Property Value
Type | Description |
---|---|
PalComponents |
SupportedEvents
Read-only list of event types the driver supports.
Declaration
public IReadOnlyList<PlatformEventType> SupportedEvents { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<PlatformEventType> |
SupportedModes
Read-only list of window modes the driver supports.
Declaration
public IReadOnlyList<WindowMode> SupportedModes { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<WindowMode> |
SupportedStyles
Read-only list of window styles the driver supports.
Declaration
public IReadOnlyList<WindowBorderStyle> SupportedStyles { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<WindowBorderStyle> |
Methods
ClientToScreen(WindowHandle, int, int, out int, out int)
Converts window relative coordinates to screen coordinates.
Declaration
public void ClientToScreen(WindowHandle handle, int clientX, int clientY, out int x, out int y)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | The window handle. |
int | clientX | The client x coordinate. |
int | clientY | The client y coordinate. |
int | x | The screen x coordinate. |
int | y | The screen y coordinate. |
Create(GraphicsApiHints)
Create a window object.
Declaration
public WindowHandle Create(GraphicsApiHints hints)
Parameters
Type | Name | Description |
---|---|---|
GraphicsApiHints | hints | Graphics API hints to be passed to the operating system. |
Returns
Type | Description |
---|---|
WindowHandle | Handle to the new window object. |
Destroy(WindowHandle)
Destroy a window object. After a window has been destroyed the handle should no longer be used in any function other than IsWindowDestroyed(WindowHandle).
Declaration
public void Destroy(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window object. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
FocusWindow(WindowHandle)
Gives the window input focus.
Declaration
public void FocusWindow(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to the window to focus. |
GetBorderStyle(WindowHandle)
Get the border style of a window.
Declaration
public WindowBorderStyle GetBorderStyle(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to window. |
Returns
Type | Description |
---|---|
WindowBorderStyle | The border style of the window. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
GetBounds(WindowHandle, out int, out int, out int, out int)
Get the bounds of the window.
Declaration
public void GetBounds(WindowHandle handle, out int x, out int y, out int width, out int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | x | X coordinate of the window. |
int | y | Y coordinate of the window. |
int | width | Width of the window in pixels. |
int | height | Height of the window in pixels. |
GetClientBounds(WindowHandle, out int, out int, out int, out int)
Get the client area bounds (drawing area) of a window.
Declaration
public void GetClientBounds(WindowHandle handle, out int x, out int y, out int width, out int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | x | X coordinate of the client area. |
int | y | Y coordinate of the client area. |
int | width | Width of the client area in pixels. |
int | height | Height of the client area in pixels. |
GetClientPosition(WindowHandle, out int, out int)
Get the position of the client area (drawing area) of a window.
Declaration
public void GetClientPosition(WindowHandle handle, out int x, out int y)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | x | X coordinate of the client area. |
int | y | Y coordinate of the client area. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
GetClientSize(WindowHandle, out int, out int)
Get the size of the client area (drawing area) of a window.
Declaration
public void GetClientSize(WindowHandle handle, out int width, out int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | width | Width of the client area in pixels. |
int | height | Height of the client area in pixels. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
GetCursorCaptureMode(WindowHandle)
Gets the current cursor capture mode. See SetCursorCaptureMode(WindowHandle, CursorCaptureMode) for more details.
Declaration
public CursorCaptureMode GetCursorCaptureMode(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
Returns
Type | Description |
---|---|
CursorCaptureMode | The current cursor capture mode. |
GetDisplay(WindowHandle)
Get the display handle a window is in.
Declaration
public DisplayHandle GetDisplay(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
Returns
Type | Description |
---|---|
DisplayHandle | The display handle the window is in. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
PalNotImplementedException | Backend does not support finding the window display. CanGetDisplay. |
See Also
GetFramebufferSize(WindowHandle, out int, out int)
Get the size of the window framebuffer in pixels. Use this value when calls to graphics APIs that want pixels, e.g. GL.Viewport().
Declaration
public void GetFramebufferSize(WindowHandle handle, out int width, out int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | width | Width in pixels of the window framebuffer. |
int | height | Height in pixels of the window framebuffer. |
GetFullscreenDisplay(WindowHandle, out DisplayHandle?)
Gets the display that the specified window is fullscreen on, if the window is fullscreen.
Declaration
public bool GetFullscreenDisplay(WindowHandle window, out DisplayHandle? display)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | window | |
DisplayHandle | display | The display where the window is fullscreen or null if the window is not fullscreen. |
Returns
Type | Description |
---|---|
bool |
|
GetHWND(WindowHandle)
Returns the underlying win32 HWND
for the specified window.
Modifying things about the window outside of OpenTK functions may cause inconsistent behaviour of OpenTK functions.
Declaration
public nint GetHWND(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | The window to get the |
Returns
Type | Description |
---|---|
nint | The |
GetIcon(WindowHandle)
Get a handle to the window icon object.
Declaration
public IconHandle GetIcon(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
Returns
Type | Description |
---|---|
IconHandle | Handle to the windows icon object, or null if none is set. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
PalNotImplementedException | Driver does not support getting the window icon. See CanSetIcon. |
GetMaxClientSize(WindowHandle, out int?, out int?)
Gets the maximum size of the client area.
Declaration
public void GetMaxClientSize(WindowHandle handle, out int? width, out int? height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int? | width | The maximum width of the client area of the window, or null if no limit is set. |
int? | height | The maximum height of the client area of the window, or null if no limit is set. |
GetMinClientSize(WindowHandle, out int?, out int?)
Gets the minimum size of the client area.
Declaration
public void GetMinClientSize(WindowHandle handle, out int? width, out int? height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int? | width | The minimum width of the client area of the window, or null if no limit is set. |
int? | height | The minimum height of the client area of the window, or null if no limit is set. |
GetMode(WindowHandle)
Get the mode of a window.
Declaration
public WindowMode GetMode(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
Returns
Type | Description |
---|---|
WindowMode | The mode of the window. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
GetPosition(WindowHandle, out int, out int)
Get the window position in display coordinates (top left origin).
Declaration
public void GetPosition(WindowHandle handle, out int x, out int y)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | x | X coordinate of the window. |
int | y | Y coordinate of the window. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
GetScaleFactor(WindowHandle, out float, out float)
Returns the current scale factor of this window.
Declaration
public void GetScaleFactor(WindowHandle handle, out float scaleX, out float scaleY)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | The window handle. |
float | scaleX | The x scale factor of the window. |
float | scaleY | The y scale factor of the window. |
See Also
GetSize(WindowHandle, out int, out int)
Get the size of the window.
Declaration
public void GetSize(WindowHandle handle, out int width, out int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | width | Width of the window in pixels. |
int | height | Height of the window in pixels. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
GetTitle(WindowHandle)
Get the title of a window.
Declaration
public string GetTitle(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
Returns
Type | Description |
---|---|
string | The title of the window. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Initialize(ToolkitOptions)
Initialize the component.
Declaration
public void Initialize(ToolkitOptions options)
Parameters
Type | Name | Description |
---|---|---|
ToolkitOptions | options | The options to initialize the component with. |
IsAlwaysOnTop(WindowHandle)
Gets if the current window is always on top or not.
Declaration
public bool IsAlwaysOnTop(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | A handle to the window to get whether or not is always on top. |
Returns
Type | Description |
---|---|
bool | Whether the window is always on top or not. |
IsFocused(WindowHandle)
Returns true if the given window has input focus.
Declaration
public bool IsFocused(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
Returns
Type | Description |
---|---|
bool | If the window has input focus. |
IsWindowDestroyed(WindowHandle)
Checks if Destroy(WindowHandle) has been called on this handle.
Declaration
public bool IsWindowDestroyed(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | The window handle to check if it's destroyed or not. |
Returns
Type | Description |
---|---|
bool | If Destroy(WindowHandle) was called with the window handle. |
ProcessEvents(bool)
Processes platform events and sends them to the EventQueue.
Declaration
public void ProcessEvents(bool waitForEvents)
Parameters
Type | Name | Description |
---|---|---|
bool | waitForEvents | Specifies if this function should wait for events or return immediately if there are no events. |
RequestAttention(WindowHandle)
Requests that the user pay attention to the window.
Declaration
public void RequestAttention(WindowHandle handle)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | A handle to the window that requests attention. |
ScreenToClient(WindowHandle, int, int, out int, out int)
Converts screen coordinates to window relative coordinates.
Declaration
public void ScreenToClient(WindowHandle handle, int x, int y, out int clientX, out int clientY)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | The window handle. |
int | x | The screen x coordinate. |
int | y | The screen y coordinate. |
int | clientX | The client x coordinate. |
int | clientY | The client y coordinate. |
SetAlwaysOnTop(WindowHandle, bool)
Set if the window is an always on top window or not.
Declaration
public void SetAlwaysOnTop(WindowHandle handle, bool floating)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | A handle to the window to make always on top. |
bool | floating | Whether the window should be always on top or not. |
SetBorderStyle(WindowHandle, WindowBorderStyle)
Set the border style of a window.
Declaration
public void SetBorderStyle(WindowHandle handle, WindowBorderStyle style)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
WindowBorderStyle | style | The new border style of the window. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
PalNotImplementedException | Driver does not support the value set by |
SetBounds(WindowHandle, int, int, int, int)
Set the bounds of the window.
Declaration
public void SetBounds(WindowHandle handle, int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | x | New X coordinate of the window. |
int | y | New Y coordinate of the window. |
int | width | New width of the window in pixels. |
int | height | New height of the window in pixels. |
SetClientBounds(WindowHandle, int, int, int, int)
Set the client area bounds (drawing area) of a window.
Declaration
public void SetClientBounds(WindowHandle handle, int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | x | New X coordinate of the client area. |
int | y | New Y coordinate of the client area. |
int | width | New width of the client area in pixels. |
int | height | New height of the client area in pixels. |
SetClientPosition(WindowHandle, int, int)
Set the position of the client area (drawing area) of a window.
Declaration
public void SetClientPosition(WindowHandle handle, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | x | New X coordinate of the client area. |
int | y | New Y coordinate of the client area. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
SetClientSize(WindowHandle, int, int)
Set the size of the client area (drawing area) of a window.
Declaration
public void SetClientSize(WindowHandle handle, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | width | New width of the client area in pixels. |
int | height | New height of the client area in pixels. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
SetCursor(WindowHandle, CursorHandle?)
Set the cursor object for a window.
Declaration
public void SetCursor(WindowHandle handle, CursorHandle? cursor)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
CursorHandle | cursor | Handle to a cursor object, or null for hidden cursor. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
PalNotImplementedException | Backend does not support setting the window mouse cursor. See CanSetCursor. |
See Also
SetCursorCaptureMode(WindowHandle, CursorCaptureMode)
Sets the cursor capture mode of the window. A cursor can be confined to the bounds of the window, or locked to the center of the window.
Declaration
public void SetCursorCaptureMode(WindowHandle handle, CursorCaptureMode mode)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
CursorCaptureMode | mode | The cursor capture mode. |
See Also
SetFullscreenDisplay(WindowHandle, DisplayHandle?)
Put a window into 'windowed fullscreen' on a specified display or the display the window is displayed on.
If display
is null
then the window will be made fullscreen on the 'nearest' display.
Declaration
public void SetFullscreenDisplay(WindowHandle window, DisplayHandle? display)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | window | |
DisplayHandle | display | The display to make the window fullscreen on. |
Remarks
To make an 'exclusive fullscreen' window see SetFullscreenDisplay(WindowHandle, DisplayHandle, VideoMode).
SetFullscreenDisplay(WindowHandle, DisplayHandle, VideoMode)
Put a window into 'exclusive fullscreen' on a specified display and change the video mode to the specified video mode. Only video modes accuired using GetSupportedVideoModes(DisplayHandle) are expected to work.
Declaration
public void SetFullscreenDisplay(WindowHandle window, DisplayHandle display, VideoMode videoMode)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | window | |
DisplayHandle | display | The display to make the window fullscreen on. |
VideoMode | videoMode | The video mode to use when making the window fullscreen. |
Remarks
To make an 'windowed fullscreen' window see SetFullscreenDisplay(WindowHandle, DisplayHandle?).
SetHitTestCallback(WindowHandle, HitTest?)
Sets a delegate that is used for hit testing. Hit testing allows the user to specify if a click should start a drag or resize operation on the window.
Hit testing is not always done in respone to the user clicking the mouse. The operating system can do hit testing for any reason and doesn't need to be in respose to some user action. It is recommended to keep this code efficient as it will be called often.
Declaration
public void SetHitTestCallback(WindowHandle handle, HitTest? test)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | The window for which this hit test delegate should be used for. |
HitTest | test | The hit test delegate. |
SetIcon(WindowHandle, IconHandle)
Set window icon object handle.
Declaration
public void SetIcon(WindowHandle handle, IconHandle icon)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
IconHandle | icon | Handle to an icon object, or null to revert to default. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
PalNotImplementedException | Backend does not support setting the window icon. See CanSetIcon. |
See Also
SetMaxClientSize(WindowHandle, int?, int?)
Sets the maximum size of the client area.
Declaration
public void SetMaxClientSize(WindowHandle handle, int? width, int? height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int? | width | New maximum width of the client area of the window, or null to remove limit. |
int? | height | New maximum height of the client area of the window, or null to remove limit. |
SetMinClientSize(WindowHandle, int?, int?)
Sets the minimum size of the client area.
Declaration
public void SetMinClientSize(WindowHandle handle, int? width, int? height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int? | width | New minimum width of the client area of the window, or null to remove limit. |
int? | height | New minimum height of the client area of the window, or null to remove limit. |
SetMode(WindowHandle, WindowMode)
Set the mode of a window.
Declaration
public void SetMode(WindowHandle handle, WindowMode mode)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
WindowMode | mode | The new mode of the window. |
Remarks
Setting WindowedFullscreen or ExclusiveFullscreen will make the window fullscreen in the nearest monitor to the window location. Use SetFullscreenDisplay(WindowHandle, DisplayHandle?) or SetFullscreenDisplay(WindowHandle, DisplayHandle, VideoMode) to explicitly set the monitor.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
PalNotImplementedException | Driver does not support the value set by |
SetPosition(WindowHandle, int, int)
Set the window position in display coordinates (top left origin).
Declaration
public void SetPosition(WindowHandle handle, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | x | New X coordinate of the window. |
int | y | New Y coordinate of the window. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
SetSize(WindowHandle, int, int)
Set the size of the window.
Declaration
public void SetSize(WindowHandle handle, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
int | width | New width of the window in pixels. |
int | height | New height of the window in pixels. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
SetTitle(WindowHandle, string)
Set the title of a window.
Declaration
public void SetTitle(WindowHandle handle, string title)
Parameters
Type | Name | Description |
---|---|---|
WindowHandle | handle | Handle to a window. |
string | title | New window title string. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|