Jump to content
  • Advertisement
Sign in to follow this  
Taymo

SDL with a Win32 menu.

This topic is 4430 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to grab the HWND from windows via SDL and create a Win32 menu from it to use in something like a map editor that uses SDL for rendering. Also if I created a new thread could I create a new window and use it?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Taymo
Is it possible to grab the HWND from windows via SDL and create a Win32 menu from it to use in something like a map editor that uses SDL for rendering.


See here and here

Quote:

Also if I created a new thread could I create a new window and use it?


Since Im not sure about win32, I will just say that SDL 1.2 can only use a single window. Multiple windows are planned for 1.3.

Share this post


Link to post
Share on other sites
Ok so I tryed this:

HMENU menu, subMenu;
menu = CreateMenu();

subMenu = CreatePopupMenu();
AppendMenu(subMenu, MF_STRING, ID_NEW, "&New");
SetMenu(hwnd, menu);


Doesn't seem to do anything. Is this the right approtch?

Share this post


Link to post
Share on other sites
I did something like this a while ago. Here's my source:

sdl_winmenu_main.cpp

//-----------------------------------------------------------------------------
// Name: sdl_winmenu_main.cpp
// Purpose: Shows how to use a typical windows menu with an sdl application
//
// Created: June 09, 2004 by Casey Dunham. Credit to Rhay on the
// www.gamedev.net forums.
//
// Notes: Make sure sdl.lib sdlmain.lib winmm.lib are linked in.
//-----------------------------------------------------------------------------

//
// Includes
//
#include "SDL.h"

// This is the windows specific stuff
#include "windows.h"

// This contains the structs we need for working with system messages
#include "SDL_syswm.h"

// These are our menu definitions
#include "res.h"


//
// Globals
//
SDL_Surface* g_pMainSurface = 0;


//
// Functions
//
int main(int argc, char *argv[]) {

if (SDL_Init(SDL_INIT_VIDEO) == -1) {
fprintf(stderr, "Failed to Initialize SDL!\n");
exit(1);
}

// This structure contains the relevant windows information that we must fill
// with the version of SDL and send it to SDL_GetWMInfo to retrieve the
// handle of the window
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);

if (!SDL_GetWMInfo(&wmInfo)) {
fprintf(stderr, "Failed to get WM Info!\n");
exit(1);
}

// Store the windows handle
HWND hWindow = wmInfo.window;

// Load our menu definitions
HMENU hMenu = LoadMenu(GetModuleHandle(0),MAKEINTRESOURCE(IDR_MENU));

// Attach the menu to the window
SetMenu(hWindow, hMenu);

// This tells SDL we want to process system events
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);

atexit(SDL_Quit);

// Setup the main surface
g_pMainSurface = SDL_SetVideoMode(640, 480, 0, SDL_ANYFORMAT);

if (!g_pMainSurface) {
fprintf(stderr, "Failed to Initialize MainSurface!\n");
exit(1);
}

// The main program loop
SDL_Event event;
bool bDone = false;

// Repeat until we're done...
while(!bDone)
{
if (SDL_PollEvent(&event) != 0)
{
switch(event.type)
{
case SDL_QUIT:
bDone = true;
break;

// This checks for an window event
case SDL_SYSWMEVENT:

// event.syswm.msg contains a pointer to SDL_SysWMmsg
// which contains the event information
switch(event.syswm.msg->msg)
{

// The user selected the command from the menu or used
// a hot key
case WM_COMMAND:

// Find which sub command was selected
switch(LOWORD(event.syswm.msg->wParam))
{
// File->Quit selected, so we're done
case IDM_QUIT:
bDone = true;
break;
}
break;
}
break;
default:
break;
}

// No events so do some game code
}
}

// Clear everything up
DestroyMenu(hMenu);
SDL_FreeSurface(g_pMainSurface);

return 0;

}




res.rc

#include "res.h"

IDR_MENU MENUEX
BEGIN
POPUP "File", IDM_FILE
BEGIN
MENUITEM "Quit", IDM_QUIT
END

POPUP "Edit", IDM_EDIT
BEGIN
MENUITEM "Exit", IDM_QUIT
END
END




res.h

#define IDR_MENU 10000
#define IDM_FILE 10001
#define IDM_QUIT 10002

#define IDM_EDIT 20001




That should do it. Realize however, that this will break any platform independence.

I also don't think it's possible to use multiple windows in SDL. But I'm not totally sure about that.

Share this post


Link to post
Share on other sites
Hey thanks a lot for your code. That'll get me on the way. Yea I'm not worried about platform dependance. Thanks again.

Share this post


Link to post
Share on other sites
I did it sometime ago too (I used AppendMenu since I didn't need so many options).

I was wondering, is there a way of making it platform independant? Sometime ago I read about a GTK + SDL component, but never got finished.

Regards,
JJ (GeoMX).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!