sdlada icon indicating copy to clipboard operation
sdlada copied to clipboard

Unable to create a window using Native_Window parameter

Open rveenker opened this issue 7 years ago • 3 comments

Luke,

For my project I need to create a video window inside an existing windows control. This can be done by specifying the hwnd of this control, and use it in SDL.Video.Windows.Makers.Create. However I can not create the necessary parameter (Native : in Native_Window) based on my hwnd (i.e. Win32 handle or simply an Integer). For now I added a function in SDL.Video.Windows that uses unchecked_conversion to create a Native_Window variable:

function From_Hwnd (Hwnd : Integer) return Native_Window is function To_Address is new Ada.Unchecked_Conversion (Source => Integer, Target => System.Address); begin return Native_Window (To_Address (Hwnd)); end From_Hwnd;

I have already tested this and it works!

Kind regards, Rob

rveenker avatar Feb 08 '18 12:02 rveenker

Yes, this is what needs to happen on a platform specific basis if you want to create your window outside of SDL.

SDL.Video.Windows.Makers.Create handles this with the Native_Window type inside SDL.Video.Windows. HWND is just a handle so having it as as address shouldn't be an issue, you say it works, which is good! :)

I left it this way as I cannot say which Windows bindings people will use, so U_C shouldn't have a problem converting between the two types. But your code really should be:

function To_NW is new Ada.Unchecked_Conversion (Source => Integer, -- Your HWND
                                                Target => SDL.Video.Windows.Native_Window);

or

function To_NW is new Ada.Unchecked_Conversion (Source => API.HWND,
                                                Target => SDL.Video.Windows.Native_Window);

Where API is your Windows binding.

Native_Window is already a System.Address.

Lucretia avatar Feb 08 '18 15:02 Lucretia

In other words, platform specifics like this, it shouldn't be added to the library, you should just create a function that will handle the conversion for you and put it in a platform specific directory and pick it up that way, unless the application isn't portable, then just in standard source somewhere.

As I've not tested on Windows yet, this could be a size issue, not sure.

As Windows32 is being phased out, i.e. AMD don't even have 32 bit drivers for R9 3xx series anymore for Windows 10, I'll only be supporting 64 bit windows with this lib.

Can you provide a small test app which requires a native window with either a binding to the HWND or a link to the Windows API binding you're using?

Lucretia avatar Feb 08 '18 15:02 Lucretia

Test Native windows on:

  • [ ] Windows 10 (64-bit)
  • [ ] Mac OS X
  • [ ] Linux (32-bit)

Lucretia avatar Feb 08 '18 15:02 Lucretia