How to put SDL window into an application on Windows

Hi All,
I’m developing a media player using SDL on Windows.
I want to put the SDL window into my own application, as a draw region
instead of a new window. But I can’t find a way to do that. As long as I
call SDL_SetVideoMode, a new windows is popped. Also I checked the source
code of SDL, it shows that the window is created when initializing video sub
system, after SetVideoMode, the size and position is set and it is shown as
a new window.
Is there any way to set the window as a “Control” in MFC (e.g. picture
control), instead of creating a new window?–
Mine

I don’t think that’s possible with how SDL is structured (at least
without rewriting a lot of the video code). If you wanted to still use
the blitting functions with an SDL_Surface you would probably have to
write your own surface to picturebox (or similar) copying code.

Josh

Mine wrote:> Hi All,

I'm developing a media player using SDL on Windows.
I want to put the SDL window into my own application, as a draw

region instead of a new window. But I can’t find a way to do that. As
long as I call SDL_SetVideoMode, a new windows is popped. Also I checked
the source code of SDL, it shows that the window is created when
initializing video sub system, after SetVideoMode, the size and position
is set and it is shown as a new window.
Is there any way to set the window as a “Control” in MFC (e.g.
picture control), instead of creating a new window?


Mine



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Did you check http://sourceforge.net/projects/gtksdl/ ?

Apparently it uses some tricks to make SDL use an existing window.–
Sylvain

On Thu, Aug 16, 2007 at 07:53:14PM -0400, Josh Nikaji Stefanski wrote:

I don’t think that’s possible with how SDL is structured (at least
without rewriting a lot of the video code). If you wanted to still use
the blitting functions with an SDL_Surface you would probably have to
write your own surface to picturebox (or similar) copying code.

Josh

Mine wrote:

Hi All,
I’m developing a media player using SDL on Windows.
I want to put the SDL window into my own application, as a draw
region instead of a new window. But I can’t find a way to do that. As
long as I call SDL_SetVideoMode, a new windows is popped. Also I checked
the source code of SDL, it shows that the window is created when
initializing video sub system, after SetVideoMode, the size and position
is set and it is shown as a new window.
Is there any way to set the window as a “Control” in MFC (e.g.
picture control), instead of creating a new window?


Mine

I still think, that in situations like this (just speculating) that it is
letting SDL still create the window and setting the environment variable
(HWND) and then GTK or Ogre (in my experience) will pick it up via that.–
-Bryan P. Arant
[Brin || AfroFire]

On 8/16/07, Sylvain Beucler wrote:

Did you check http://sourceforge.net/projects/gtksdl/ ?

Apparently it uses some tricks to make SDL use an existing window.


Sylvain

On Thu, Aug 16, 2007 at 07:53:14PM -0400, Josh Nikaji Stefanski wrote:

I don’t think that’s possible with how SDL is structured (at least
without rewriting a lot of the video code). If you wanted to still use
the blitting functions with an SDL_Surface you would probably have to
write your own surface to picturebox (or similar) copying code.

Josh

Mine wrote:

Hi All,
I’m developing a media player using SDL on Windows.
I want to put the SDL window into my own application, as a draw
region instead of a new window. But I can’t find a way to do that. As
long as I call SDL_SetVideoMode, a new windows is popped. Also I
checked

the source code of SDL, it shows that the window is created when
initializing video sub system, after SetVideoMode, the size and
position

is set and it is shown as a new window.
Is there any way to set the window as a “Control” in MFC (e.g.
picture control), instead of creating a new window?


Mine


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I still think, that in situations like this (just speculating) that it is
letting SDL still create the window and setting the environment variable
(HWND) and then GTK or Ogre (in my experience) will pick it up via that.

No, it’s the other way around. The app is setting the environment variable
and SDL is using that as that window. You might search for SDL and MFC, I
know many people have asked about it and I think someone figured it out.

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

I believe the OP is looking for: SDL_WINDOWID

To OP (sorry I do not have the original email):

char sdl_var[64];

sprintf(sdl_var, "SDL_WINDOWID=0x%lx", window_id);

putenv(sdl_var);

SDL_Surface *surface = SDL_SetVideoMode(xres, yres, bpp, mode);

Where,
window_id: The Window ID of the widget you want to place the SDL Surface
into.

xres, yres: Typically the dimensions of the widget

bpp: i.e. 32 as in 32 bpp

mode: All the SDL flags for creating the SDL surface

Hope this helps to point you onto the right track.

Here’s some the link to the docs:
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fenvvars

Good luck,

AlvinOn Friday 17 August 2007 11:27:50 Bryan Arant wrote:

I still think, that in situations like this (just speculating) that it is
letting SDL still create the window and setting the environment variable
(HWND) and then GTK or Ogre (in my experience) will pick it up via that.

Yes, I made a liitle change in SDL’s source code, add function like “HWND
SDL_GetWnd” (it’s just for WIndows), and return SDL_Window. Then we can
modify the style of this window as needed.
In my application, it’s OK now :slight_smile:
Thanks guys.On 8/17/07, Bryan Arant wrote:

I still think, that in situations like this (just speculating) that it is
letting SDL still create the window and setting the environment variable
(HWND) and then GTK or Ogre (in my experience) will pick it up via that.


-Bryan P. Arant
[Brin || AfroFire]

On 8/16/07, Sylvain Beucler wrote:

Did you check http://sourceforge.net/projects/gtksdl/ ?

Apparently it uses some tricks to make SDL use an existing window.


Sylvain

On Thu, Aug 16, 2007 at 07:53:14PM -0400, Josh Nikaji Stefanski wrote:

I don’t think that’s possible with how SDL is structured (at least
without rewriting a lot of the video code). If you wanted to still use
the blitting functions with an SDL_Surface you would probably have to
write your own surface to picturebox (or similar) copying code.

Josh

Mine wrote:

Hi All,
I’m developing a media player using SDL on Windows.
I want to put the SDL window into my own application, as a draw
region instead of a new window. But I can’t find a way to do that.
As

long as I call SDL_SetVideoMode, a new windows is popped. Also I
checked

the source code of SDL, it shows that the window is created when
initializing video sub system, after SetVideoMode, the size and
position

is set and it is shown as a new window.
Is there any way to set the window as a “Control” in MFC ( e.g.
picture control), instead of creating a new window?


Mine


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


!!!

Yes, I made a liitle change in SDL’s source code, add function like “HWND
SDL_GetWnd” (it’s just for WIndows), and return SDL_Window. Then we can
modify the style of this window as needed.

Actually, you can already get the Window from SDL. Here’s an example:
http://www.libsdl.org/projects/scrap/

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Oh Great!
Yeah, with your sample, I don’t have to modify SDL at all :slight_smile:
Thanks a lot!On 8/17/07, Sam Lantinga wrote:

Yes, I made a liitle change in SDL’s source code, add function like
"HWND
SDL_GetWnd" (it’s just for WIndows), and return SDL_Window. Then we can
modify the style of this window as needed.

Actually, you can already get the Window from SDL. Here’s an example:
http://www.libsdl.org/projects/scrap/

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


!!!

Yep, scrap works. Problem is, at least on my CentOS KDE system, running scrap
borks up other things (nedit refuses to run after running scrap–haven’t
tested anything else because what’s the point? If scrap messes up X11 such
that I have to restart X11 to use software that otherwise runs fine, then
there are some serious problems with whatever scrap does to X11.)On Fri August 17 2007 19:14, Mine wrote:

Oh Great!
Yeah, with your sample, I don’t have to modify SDL at all :slight_smile:
Thanks a lot!

On 8/17/07, Sam Lantinga wrote:

Yes, I made a liitle change in SDL’s source code, add function like

"HWND

SDL_GetWnd" (it’s just for WIndows), and return SDL_Window. Then we can
modify the style of this window as needed.

Actually, you can already get the Window from SDL. Here’s an example:
http://www.libsdl.org/projects/scrap/

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

I didn’t really use scrap, I just use the such code below to get the window.
It just gets the window handler, it shouldn’t break anything…

SDL_SysWMinfo info;
/* Grab the window manager specific information /
SDL_VERSION(&info.version);
if ( SDL_GetWMInfo(&info) )
{
/
info.window is the HWND on Windows */
}On 8/18/07, Jeff <j_post at pacbell.net> wrote:

Yep, scrap works. Problem is, at least on my CentOS KDE system, running
scrap
borks up other things (nedit refuses to run after running scrap–haven’t
tested anything else because what’s the point? If scrap messes up X11 such
that I have to restart X11 to use software that otherwise runs fine, then
there are some serious problems with whatever scrap does to X11.)

On Fri August 17 2007 19:14, Mine wrote:

Oh Great!
Yeah, with your sample, I don’t have to modify SDL at all :slight_smile:
Thanks a lot!

On 8/17/07, Sam Lantinga wrote:

Yes, I made a liitle change in SDL’s source code, add function like

"HWND

SDL_GetWnd" (it’s just for WIndows), and return SDL_Window. Then we
can

modify the style of this window as needed.

Actually, you can already get the Window from SDL. Here’s an example:
http://www.libsdl.org/projects/scrap/

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


!!!