The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Adding drop-down menus to SDL surface window?
miker00lz


Joined: 15 Oct 2010
Posts: 4
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!
miker00lz


Joined: 15 Oct 2010
Posts: 4
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!




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! Smile