SDL driver window proc

Hello all,

Forgive me if the answer to this has been said before…

I’m looking at the source for a Win32 game that uses SDL for its video. The
game has registered a message handler for windows messages. The handler
simply deals with window resizing and the like (the game can go into
full-screen mode, so that needed to be customized).

At the end of all the custom message handling, the handler makes a call to
the SDL driver window proc. (The proc was found by gathering SDL_SysWMinfo
and using GetWindowLongPtr). Two questions:

  1. What does the SDL driver window proc do (is it necessary to call it on
    events)?
  2. Is there a Mac OS X equivalent?

Any input is greatly appreciated.

Thanks,

Ryan

Hello Michael,

Monday, April 24, 2006, 4:46:16 PM, you wrote:

MRB> Hello all,

MRB> Forgive me if the answer to this has been said before…

MRB> I’m looking at the source for a Win32 game that uses SDL for its video. The
MRB> game has registered a message handler for windows messages. The handler
MRB> simply deals with window resizing and the like (the game can go into
MRB> full-screen mode, so that needed to be customized).

MRB> At the end of all the custom message handling, the handler makes a call to
MRB> the SDL driver window proc. (The proc was found by gathering SDL_SysWMinfo
MRB> and using GetWindowLongPtr). Two questions:

MRB> 1) What does the SDL driver window proc do (is it necessary to call it on
MRB> events)?

YES - if you do not do this things will not work!

MRB> 2) Is there a Mac OS X equivalent?

I would say that if all the author is doing is handling resizable
display and fullscreen/windowmode switching, he should have done this
using SDL’s own messages - SDL_ResizeEvent for the resizing, and
fullscreen/windowmode switching by picking up on some key combination
and making it happen with SDL_SetVideoMode().

What else does the custom wndproc do? Paste it here.–
Best regards,
Peter mailto:@Peter_Mulholland

Thanks for the quick response!

Some further information…I’m porting a Win32 game to Mac, so that’s the
nature of my questions.

I can’t really share too much of the code because of confidentiality, but I
can say that the custom proc is doing the following (this is all Win32):

It checks for the following messages:

  • WM_USER
  • WM_NCLBUTTONDBLCLICK (toggles full screen from windowed mode, simply
    setting a flag, which is later used by SDL)
  • WM_SYSCOMMAND (again, full screen check using SC_MAXIMIZE param of msg;
    this is using ShowWindow to show the window…it could probably use SDL,
    couldn’t it)
  • WM_SIZE (sizing again), and WM_ACTIVATEAPP (upon activation). Both end up
    using SDL.
  • It also checks for a custom message (having to do with only allowing one
    instance of the app).

After this, the main handler calls another function which checks the
following messages:

  • WM_ACTIVEATE (calling ShowWindow…you make a good point about SDL
    probably being able to handle this stuff…I’m not sure why they’re doing it
    custom via Windows)
  • WM_SIZE (saving old window settings)

At the end it makes the call to the driver proc. So everything seems to be
handled by SDL except a few things. I’m new to SDL, so I have to look into
what exactly it’s capable of, but I’m sure I can apply more.

So, what exactly does the SDL driver proc do? Also, regarding Mac
equivalent…how do I get the handle to the Mac SDL driver proc? I
understand what’s going on with the Windows version (correct me if I’m
wrong):

  • get SDL version (using SDL_VERSION)
  • get SDL_SysWMinfo (using SDL_GetWMInfo)
  • get the window handle
  • get the address of the SDL WNDPROC from the handle and offset (using
    GetWindowLongPtr)

This makes sense. I also checked out
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSysWMInfo to decipher the
SDL_SysWMinfo struct. What I can’t figure out is how to get the same info
under Mac OS X?

Thanks,

Ryan

“Peter Mulholland” wrote in message
news:416150622.20060424165637 at freeuk.com…> Hello Michael,

Monday, April 24, 2006, 4:46:16 PM, you wrote:

MRB> Hello all,

MRB> Forgive me if the answer to this has been said before…

MRB> I’m looking at the source for a Win32 game that uses SDL for its
video. The
MRB> game has registered a message handler for windows messages. The
handler
MRB> simply deals with window resizing and the like (the game can go into
MRB> full-screen mode, so that needed to be customized).

MRB> At the end of all the custom message handling, the handler makes a
call to
MRB> the SDL driver window proc. (The proc was found by gathering
SDL_SysWMinfo
MRB> and using GetWindowLongPtr). Two questions:

MRB> 1) What does the SDL driver window proc do (is it necessary to call
it on
MRB> events)?

YES - if you do not do this things will not work!

MRB> 2) Is there a Mac OS X equivalent?

I would say that if all the author is doing is handling resizable
display and fullscreen/windowmode switching, he should have done this
using SDL’s own messages - SDL_ResizeEvent for the resizing, and
fullscreen/windowmode switching by picking up on some key combination
and making it happen with SDL_SetVideoMode().

What else does the custom wndproc do? Paste it here.


Best regards,
Peter mailto:darkmatter at freeuk.com

Hello Michael,

Monday, April 24, 2006, 6:24:57 PM, you wrote:

MRB> Some further information…I’m porting a Win32 game to Mac, so that’s the
MRB> nature of my questions.

That happens to be my job :slight_smile:

MRB> I can’t really share too much of the code because of confidentiality, but I
MRB> can say that the custom proc is doing the following (this is all Win32):

MRB> It checks for the following messages:
MRB> - WM_USER
MRB> - WM_NCLBUTTONDBLCLICK (toggles full screen from windowed mode, simply
MRB> setting a flag, which is later used by SDL)
MRB> - WM_SYSCOMMAND (again, full screen check using SC_MAXIMIZE param of msg;
MRB> this is using ShowWindow to show the window…it could probably use SDL,
MRB> couldn’t it)
MRB> - WM_SIZE (sizing again), and WM_ACTIVATEAPP (upon activation). Both end up
MRB> using SDL.
MRB> - It also checks for a custom message (having to do with only allowing one
MRB> instance of the app).

MRB> After this, the main handler calls another function which checks the
MRB> following messages:
MRB> - WM_ACTIVEATE (calling ShowWindow…you make a good point about SDL
MRB> probably being able to handle this stuff…I’m not sure why they’re doing it
MRB> custom via Windows)
MRB> - WM_SIZE (saving old window settings)

I see absolutely no reason why the original author couldn’t have used
SDL for all of that, except perhaps the instance check (there’s other
ways to do that though).

You get notified of resize events with the SDL_VIDEORESIZE event. You
get the hide/show info with SDL_ACTIVEEVENT. The handling of
WM_NCLBUTTONDBLCLICK (which would happen if the user double clicked in
the window’s title bar) and WM_SYSCOMMAND indicates they wanted to add
Maximise support. Perhaps they wrote the game with an earlier SDL that
didn’t support it. It certainly does support resizable windows now.

MRB> So, what exactly does the SDL driver proc do?

Handles all the message events to do with the window. If you want to
see it, look at wincommon/SDL_sysevents.c and either
windx5/SDL_dx5events.c or windib/SDL_dibevents.c

MRB> Also, regarding Mac equivalent…how do I get the handle to the Mac
MRB> SDL driver proc?

Briefly looking at SDL_syswm.h - you can’t.
Messing with the window proc is a bad idea anyway. There is almost no
need to do it. I’ve only used the syswm stuff once and that was a
quick hack to get a sound driver that wanted the Window handle.–
Best regards,
Peter mailto:@Peter_Mulholland

Man, you’re quick! Thanks again. Very helpful.
Just one thing I’m still not clear on.

Like I said, they have their own windows message handler. Now, normally
this would be done by getting the next message in the queue (GetMessage,
PeekMessage, whatever). However, they did the following:

  • LONG_PTR appWndProc = (LONG_PTR) Application::WindowProc; // our apps
    message handler
  • SetWindowLongPtr(m_hWnd, GWLP_WNDPROC, appWndProc);

Correct me if I’m wrong, but the second line is essentially resetting the
default Window Proc to the apps custom handler. And, as I said before, at
the end of the custom handler it calls the SDL driver window proc. So he
does his custom stuff then uses the SDL driver.

My question is (and I think you’ve already answered it, but I want to be
clear): is all this necessary? I would just use SDL_PollEvent. And it
doesn’t seem like resetting the default window proc is a good idea. (Sorry
if I went off topic a bit…I’m also gonna sk the original authro what’s
going on).

Thanks,

Ryan

“Peter Mulholland” wrote in message
news:163172507.20060424191358 at freeuk.com…> Hello Michael,

Monday, April 24, 2006, 6:24:57 PM, you wrote:

MRB> Some further information…I’m porting a Win32 game to Mac, so that’s
the
MRB> nature of my questions.

That happens to be my job :slight_smile:

MRB> I can’t really share too much of the code because of confidentiality,
but I
MRB> can say that the custom proc is doing the following (this is all
Win32):

MRB> It checks for the following messages:
MRB> - WM_USER
MRB> - WM_NCLBUTTONDBLCLICK (toggles full screen from windowed mode,
simply
MRB> setting a flag, which is later used by SDL)
MRB> - WM_SYSCOMMAND (again, full screen check using SC_MAXIMIZE param of
msg;
MRB> this is using ShowWindow to show the window…it could probably use
SDL,
MRB> couldn’t it)
MRB> - WM_SIZE (sizing again), and WM_ACTIVATEAPP (upon activation). Both
end up
MRB> using SDL.
MRB> - It also checks for a custom message (having to do with only
allowing one
MRB> instance of the app).

MRB> After this, the main handler calls another function which checks the
MRB> following messages:
MRB> - WM_ACTIVEATE (calling ShowWindow…you make a good point about SDL
MRB> probably being able to handle this stuff…I’m not sure why they’re
doing it
MRB> custom via Windows)
MRB> - WM_SIZE (saving old window settings)

I see absolutely no reason why the original author couldn’t have used
SDL for all of that, except perhaps the instance check (there’s other
ways to do that though).

You get notified of resize events with the SDL_VIDEORESIZE event. You
get the hide/show info with SDL_ACTIVEEVENT. The handling of
WM_NCLBUTTONDBLCLICK (which would happen if the user double clicked in
the window’s title bar) and WM_SYSCOMMAND indicates they wanted to add
Maximise support. Perhaps they wrote the game with an earlier SDL that
didn’t support it. It certainly does support resizable windows now.

MRB> So, what exactly does the SDL driver proc do?

Handles all the message events to do with the window. If you want to
see it, look at wincommon/SDL_sysevents.c and either
windx5/SDL_dx5events.c or windib/SDL_dibevents.c

MRB> Also, regarding Mac equivalent…how do I get the handle to the Mac
MRB> SDL driver proc?

Briefly looking at SDL_syswm.h - you can’t.
Messing with the window proc is a bad idea anyway. There is almost no
need to do it. I’ve only used the syswm stuff once and that was a
quick hack to get a sound driver that wanted the Window handle.


Best regards,
Peter mailto:darkmatter at freeuk.com

Hello Michael,

Monday, April 24, 2006, 7:44:13 PM, you wrote:

MRB> Like I said, they have their own windows message handler. Now, normally
MRB> this would be done by getting the next message in the queue (GetMessage,
MRB> PeekMessage, whatever).

That is still being done whenever SDL_PumpEvents() is called.

MRB> However, they did the following:
MRB> - LONG_PTR appWndProc = (LONG_PTR) Application::WindowProc; // our apps
MRB> message handler
MRB> - SetWindowLongPtr(m_hWnd, GWLP_WNDPROC, appWndProc);

MRB> Correct me if I’m wrong, but the second line is essentially resetting the
MRB> default Window Proc to the apps custom handler. And, as I said before, at
MRB> the end of the custom handler it calls the SDL driver window proc. So he
MRB> does his custom stuff then uses the SDL driver.

Yep. This is usually referred to as “chaining”. Prior to the
SetWindowLongPtr() call, the window proc that would be handling the
window’s events would be one inside SDL.

MRB> My question is (and I think you’ve already answered it, but I want to be
MRB> clear): is all this necessary? I would just use SDL_PollEvent. And it
MRB> doesn’t seem like resetting the default window proc is a good idea.

Yep, it’s unneccesary when SDL supports what they’re trying to
implement.

MRB> (Sorry if I went off topic a bit…I’m also gonna sk the original
MRB> authro what’s going on).

I would be intrigued to know why he saw fit to use his own wndproc
too.–
Best regards,
Peter mailto:@Peter_Mulholland

Hello all.

Small fallow-up. The reason that some of the functionality was customized
was because of problems dealing with HW acceleration and not trusting some
of the SDL stuff to deal with resizing and full-screen. I can’t account for
this (as I am very new to SDL). So, for those interested, those were his
reasons.

Thanks,

Ryan

“Peter Mulholland” wrote in message
news:1727359258.20060424195218 at freeuk.com…> Hello Michael,

Monday, April 24, 2006, 7:44:13 PM, you wrote:

MRB> Like I said, they have their own windows message handler. Now,
normally
MRB> this would be done by getting the next message in the queue
(GetMessage,
MRB> PeekMessage, whatever).

That is still being done whenever SDL_PumpEvents() is called.

MRB> However, they did the following:
MRB> - LONG_PTR appWndProc = (LONG_PTR) Application::WindowProc; // our
apps
MRB> message handler
MRB> - SetWindowLongPtr(m_hWnd, GWLP_WNDPROC, appWndProc);

MRB> Correct me if I’m wrong, but the second line is essentially resetting
the
MRB> default Window Proc to the apps custom handler. And, as I said
before, at
MRB> the end of the custom handler it calls the SDL driver window proc.
So he
MRB> does his custom stuff then uses the SDL driver.

Yep. This is usually referred to as “chaining”. Prior to the
SetWindowLongPtr() call, the window proc that would be handling the
window’s events would be one inside SDL.

MRB> My question is (and I think you’ve already answered it, but I want to
be
MRB> clear): is all this necessary? I would just use SDL_PollEvent. And
it
MRB> doesn’t seem like resetting the default window proc is a good idea.

Yep, it’s unneccesary when SDL supports what they’re trying to
implement.

MRB> (Sorry if I went off topic a bit…I’m also gonna sk the original
MRB> authro what’s going on).

I would be intrigued to know why he saw fit to use his own wndproc
too.


Best regards,
Peter mailto:darkmatter at freeuk.com

Hello all.

Small fallow-up. The reason that some of the functionality was customized
was because of problems dealing with HW acceleration and not trusting some
of the SDL stuff to deal with resizing and full-screen. I can’t account for
this (as I am very new to SDL). So, for those interested, those were his
reasons.

If you run into problems with that, try the code in CVS, and if you still
have problems, please let me know.

Thanks!
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment