ghiboz's picture

[GameWindow] Retrieve window handle

Project:The Open Toolkit library
Category:support request

Hi! how can I retrieve the window handle of my game window??


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


The window handle is not exposed, as it is an implementation detail. Even if it were part of the public API, you'd still need the display connection, device context or a number of other platform-specific parameters, which would still not be exposed.

OpenTK itself relies on IWindowInfo instances that contain all the necessary parameters. GameWindow provides a WindowInfo property that can be used with other OpenTK APIs (e.g. the GraphicsContext constructor).

Of course, this doesn't help if you need the handle for a non-OpenTK API. To that end, I must ask: what do you need the handle for?

ghiboz's picture


Status:open» closed

thanks, I tried to send a message to change the icon (my other post), but I think that the solution is to set the icon in a clean way and not with the sendmessage


ghiboz's picture


I found how to retrieve the window handle...
if someone needs this:

IWindowInfo ii = ((OpenTK.NativeWindow)this).WindowInfo;
object inf = ((OpenTK.NativeWindow)this).WindowInfo;
PropertyInfo pi = (inf.GetType()).GetProperty("WindowHandle");
IntPtr hnd = ((IntPtr)pi.GetValue(ii, null));