Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create a window using Native_Window parameter #16

Open
rveenker opened this issue Feb 8, 2018 · 3 comments
Open

Unable to create a window using Native_Window parameter #16

rveenker opened this issue Feb 8, 2018 · 3 comments

Comments

@rveenker
Copy link

rveenker commented Feb 8, 2018

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

@Lucretia
Copy link
Collaborator

Lucretia commented Feb 8, 2018

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
Copy link
Collaborator

Lucretia commented Feb 8, 2018

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
Copy link
Collaborator

Lucretia commented Feb 8, 2018

Test Native windows on:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants