@hwnd%

Discussions related to graphics (2D and 3D), animation and games programming
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Fri 09 Jan 2026, 12:29 I have researched SDL_getWindowInfo and the information meant nothing to me
The only slightly fiddly aspect, as previously discussed, is the required structure: it looks complicated at first sight but that's because it has to cover a large number of different platforms, which it does by using a union. Although you can fabricate a union in BBC BASIC, indeed there's a Wiki article about that, it's not necessary in this case because the only platform you are interested in is Windows.

So you can simply ignore everything other than the part of the structure relevant to Windows, and mercifully that leaves you with something quite simple. I listed the BBC BASIC equivalent in a previous post, here it is again except that this time I've listed the 64-bit version because I assume that's what you are most interested in:

Code: Select all

      DIM SDL_SysWMinfo{ \
      \    version%,     \
      \    subsystem%,   \ 
      \    window%%,     \ The window handle
      \    hdc%%,        \ The device context
      \    hinstance%%   \ The instance handle
      \ }
As an aside, and at the risk of seeming to make it more complicated than it is, you can successfully access the 64-bit members in the rest of your program as SDL_SysWMinfo.window% etc. (just one percent sign). This feature makes it easier to write code which runs on both 32-bit and 64-bit platforms: you need to define the structure twice, but when accessing the members you can use common code for both 32 and 64-bits.

Once you have declared the structure it should be straightforward (admittedly I haven't tried it myself, for one thing I would have no way of knowing whether the returned native window handle is correct or not). If it doesn't seem to be working for you, list the code you tried.
Ric
Posts: 261
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Again, I don't know how to implement what you have just written, can you show me what the code is for calling the API
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 261
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

OK, I have tried to do what you suggested. This is what ive come up with

Code: Select all

   10 DIM SDL_SysWMinfo{ \
   20 \    version%,     \
   30 \    subsystem%,   \
   40 \    window%%,     \ The window handle
   50 \    hdc%%,        \ The device context
   60 \    hinstance%%   \ The instance handle
   70 \ }
   80 SYS "SDL_GetWindowWMInfo",SDL_SysWMinfo{}
   90 PRINT SDL_SysWMinfo{}.window%%
The answer is zero, which i assume is incorrect. Could you please show me whats wrong.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Sun 18 Jan 2026, 15:09 Could you please show me whats wrong.
The SDL_GetWindowWMInfo function takes two parameters window and info as you can see from its declaration:

Code: Select all

SDL_bool SDL_GetWindowWMInfo(SDL_Window * window, SDL_SysWMinfo * info)
                                          ^^^^^^                  ^^^^
The accompanying documentation explains what these parameters are:
  • window	the window about which information is being requested.
  • info	an SDL_SysWMinfo structure filled in with window information.
In your code you are not passing the first parameter window at all, but only the second parameter info. Not surprisingly it doesn't work! :o

Apart from it being explicitly stated in the documentation, I would have hoped it would be obvious that a function which returns a native window handle needs to know which window it should return the native window handle of. :?
Ric
Posts: 261
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Simple question then. How do I find the window info, after all that's what I'm trying to get? Right?
I have clicked on the link in the link to sdl_window and get to this

Code: Select all

typedef struct SDL_Window SDL_Window;
I have tried putting a few random numbers into

Code: Select all

SYS "SDL_GetWindowWMInfo",W%,SDL_SysWMinfo{}
but that just crashes the program!
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Sun 18 Jan 2026, 15:48 How do I find the window info, after all that's what I'm trying to get? Right?
The "window info" is what SDL_GetWindowWMInfo returns (in the SDL_SysWMinfo structure), that's the whole point. You just have to tell it which window you want to find the info for.

It might be BBC BASIC's main output window @hwnd%, or it might be one of the windows created by the multiwin.bbc library (using the FN_createwindow function), or it might be a window created in your own code using SYS "SDL_CreateWIndow".

All return a valid window ID, and SDL_GetWindowWMInfo should return a valid corresponding native window handle (and other values in the structure), but only you know which of them is the right one in your particular application.
I have tried putting a few random numbers into

Code: Select all

SYS "SDL_GetWindowWMInfo",W%,SDL_SysWMinfo{}
but that just crashes the program!
Which is entirely reasonable, since the chance of a random number happening to correspond to an actual open window is approximately one in 18,446,744,073,709,551,620 (in a 64-bit system). :lol:

I would add that W% is a 32-bit number, so the chances are high that the ID you should have used won't even fit in W%. :roll:
Ric
Posts: 261
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I am now even more confused, if BBC Basic window is the @hwnd% then why am I trying to get the handle another way ie sdl_windowWMinfo? All I want is @hwnd% in a form that can access the d3d APIs. The window I am trying to get the handle of, I assume it's the handle I want, is the BBC Basic output window.
Some time ago you asked me if I could port my d3d program in to SDL, I was trying this because I have started again with the scene rendering and and it seemed like a good opportunity given the limited number of sys calls at this juncture. I have repeatedly asked for help and received none, maybe a few pointers, but as I have stated, I need the answer, not hints, I can not learn from something I don't understand. So for the last time what does the code look like for the Sys call I need to get @hwnd% in 64 but form. This is the first step of what I consider many very challenging problems and if I can't even get answers to this then there is no hope and the answer to whether I can port my program, is, NO.
PS I used w% to represent any old number 16, 32 or 64 but style. If you want to pick holes in something so trivial, ho hum.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Sun 18 Jan 2026, 20:01 I am now even more confused, if BBC Basic window is the @hwnd% then why am I trying to get the handle another way
I'm confused too! @hwnd% is the SDL 2.0 window handle, i.e. the ID by which the window is known to the SDL 2.0 API. What I assumed you wanted was the native Windows window handle, i.e. the ID by which the window is known to the Windows API. Hence my suggestion to use the SDL_GetWindowWMInfo API function, which does that (amongst other things).

But from your most recent comments it may well be that I misunderstood what you were trying to achieve. Sorry.
I have repeatedly asked for help and received none, maybe a few pointers
I have on every occasion tried to provide as much information in as much detail as I can - bar actually supplying working code which I cannot do because I don't know what you are trying to achieve - and if it's to do with Direct3D 11 or Direct3D 12 I know nothing about them at all (anything I might have once known I've long since forgotten).

Indeed, from what you have now said, what little I thought I understood about your requirement was incorrect, so any code I created would have been useless. If you can't achieve what you want without somebody else supplying working code, I'm afraid you will have difficulty finding anybody with the right knowledge to provide it.
So for the last time what does the code look like for the Sys call I need to get @hwnd% in 64 but form.
You are (I think, but maybe I was wrong about that too) running the 64-bit version of BBCSDL - if you're unsure about that you can use the Help... About menu item to tell you whether it's 32 or 64-bits. If so, @hwnd% is already 64 bits. I know that's confusing - because it has a single % suffix when you might well expect it to have a %% suffix. But it makes life much easier for the programmer and is documented.

I don't like to give up, as it's an admission of failure on both our parts, but I honestly think that having already spent so long on this problem and seemingly having got nowhere, it would be best to call it a day and perhaps try something less challenging. You can always come back to it when you've gained some more experience with BBCSDL.
Ric
Posts: 261
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Experience of SDL is not what i need, i have written several programs in SDL, not to mention the light controlling system in my house that uses 6 raspberry PIs and an old phone as a server for the system.

Now i know that @hwnd% can be 64 bits I have changed the proceedure to accept thid using OW%%, instead of OW%, but that then brings up the error of unknown system call as the procedure tries to set up d3d. I can summise from this that there are a whole set of calls to the d3d api that are 64bit and thus chenging over could be very difficult. Questions like does d3d still operate with float4 variables etc.
In better times i would send you the code to have a look at, but from what you say this would not be fruitful, so i will keep d3d on BB4W(which i prefer to use anyway, (except for the dark mode and lack of memory available)), and use SDL for my PI projects.

Thanks for looking and keep plugging on.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 261
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

My apologies Richard, it was not my intention to insult or belittle, I was just very frustrated. Thanks for all the replies. They have helped me make an informed decision to keep BB4W and SDL separate and use each ones strengths and not try to force an issue on the other.
Kind regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023