SDL with a Win32 menu.

Started by
6 comments, last by GeoMX 17 years, 9 months ago
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?
Dev Journal - Ride the Spiralhttp://spiralride.blogspot.com/
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.
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?
Dev Journal - Ride the Spiralhttp://spiralride.blogspot.com/
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 MENUEXBEGIN	POPUP "File", IDM_FILE	BEGIN		MENUITEM "Quit", IDM_QUIT	END	POPUP "Edit", IDM_EDIT	BEGIN		MENUITEM "Exit", IDM_QUIT	ENDEND


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.
Hey thanks a lot for your code. That'll get me on the way. Yea I'm not worried about platform dependance. Thanks again.
Dev Journal - Ride the Spiralhttp://spiralride.blogspot.com/
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).
Imagination's the limit.
With win32, no. With something like wxWidgets, yes.
Quote:Original post by agi_shi
With win32, no.

I knew that :P.

Quote:Original post by agi_shi
With something like wxWidgets, yes.


Yes, that's what I was looking for, and here it is:
http://code.technoplaza.net/wx-sdl/

Best wishes,
JJ (GeoMX).
Imagination's the limit.

This topic is closed to new replies.

Advertisement