Adding drop-down menus to SDL surface window?

Hi, I need to add some standard drop-down menus to an SDL surface window under Win32. I don’t mind changing some SDL code and recompiling, I’m sure that will have to be done. I just need some pointers in the right direction. There is a way to, knowing the window’s handle, add some menus to it - right? Just need File, Help, and a couple others. Then, of course, I’ll need to make it so when menu items are clicked, they run some different functions that I link with them. I am using plain C.

Under the file menu, one item needs to be able to open a standard Windows “open file” dialog. This is for a NES emulator I’m writing. I’ve been using the command line to pass options and ROM filenames, but I really need to add a simple GUI. I do not want to make my own menuing system in SDL, I’d much rather have it use the standard Windows components.

Thanks!

Ah, I figured out a way to do it myself. I will post how in case anybody in the future comes across this thread in a search.

I #include “SDL_syswm.h” and <windows.h> and created a function to return the SDL surface window’s hWnd value like this:

Code:
HWND GetHwnd() {
SDL_SysWMinfo windowinfo;

if (!SDL_GetWMInfo(&windowinfo)) return(NULL);
return(windowinfo.window);

}

I’m using MS Visual Studio 2003, so I created a menu using it’s resource editor tools. My menu’s resource number is 102, so knowing that I made a function to attach the menu resource to SDL’s window:

Code:
void AttachMenu() {
HWND myWindow;
HMENU myMenu;

myWindow = GetHwnd();
myMenu = LoadMenu(NULL, MAKEINTRESOURCE(102));
SetMenu(myWindow, myMenu);

}

And voila, we have a menubar!

[Image: http://rubbermallet.org/mm2.png ]

Now I just need to figure out how to intercept SDL’s WndProc function to handle the menu items getting clicked. I am thinking I can do this with GetWindowLong to get the old procedure’s pointer, and replace it with my own using SetWindowLong. I will need to forward callbacks I do not handle to SDL’s old procedure handler though. Time to do some experimentation. If anybody knows a better way to do this, let me know please! :slight_smile:

Before you reinvent the wheel I’d take a look at the scads of projects
where people have made a gui for use with sdl and windows.On Sun, Dec 4, 2011 at 9:46 PM, miker00lz wrote:

**
Hi, I need to add some standard drop-down menus to an SDL surface window
under Win32. I don’t mind changing some SDL code and recompiling, I’m sure
that will have to be done. I just need some pointers in the right
direction. There is a way to, knowing the window’s handle, add some menus
to it - right? Just need File, Help, and a couple others. Then, of course,
I’ll need to make it so when menu items are clicked, they run some
different functions that I link with them. I am using plain C.

Under the file menu, one item needs to be able to open a standard Windows
"open file" dialog. This is for a NES emulator I’m writing. I’ve been using
the command line to pass options and ROM filenames, but I really need to
add a simple GUI. I do not want to make my own menuing system in SDL, I’d
much rather have it use the standard Windows components.

Thanks!


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