File, Edit, View etc... Menus?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

File, Edit, View etc... Menus?

Post by ibly31 »

Hi, I have seen some of the "Adventure in game develoment" series, and I see the File, Edit, View type menus in Marcel's level editor. I want to know, are you guys using C++? If so, are you doing this in a Win32 application, or a Windows Form application, and how to do this?

What I mean is, is the code to have a top menu with drop down menus from that very complex and difficult? Or is it not code at all? Please help. =(AH)

EDIT: Actually, lol, I just went into Visual Studio C++, and created a Windows Form application, and inserted a MenuStrip from the Toolbox. That was a nooby question. Don't answer that part.

I can't fool around right now, because I have to go to bed, but how do you tell the computer what to do when a certain part of the menu is pressed? What does the code look like to do:

*psuedocode*

if(form.menustrip1.File.Save_As.Clicked == true){
Save_As_Dialog.open();
}

*end psuedocode*
Last edited by ibly31 on Mon Mar 02, 2009 8:34 pm, edited 1 time in total.
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
deryni21
Chaos Rift Regular
Chaos Rift Regular
Posts: 124
Joined: Wed Dec 24, 2008 9:55 pm

Re: File, Edit, View etc... Menus?

Post by deryni21 »

ibly31 wrote:Hi, I have seen some of the "Adventure in game develoment" series, and I see the File, Edit, View type menus in Marcel's level editor. I want to know, are you guys using C++? If so, are you doing this in a Win32 application, or a Windows Form application, and how to do this?

What I mean is, is the code to have a top menu with drop down menus from that very complex and difficult? Or is it not code at all? Please help. =(AH)
he did it in blitz right?
Image
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: File, Edit, View etc... Menus?

Post by ibly31 »

Oh, I guess... well, I guess what I am asking now is how to do it in C++. :D 'Cause blitz costs a fortune. At least I think(never checked).
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: File, Edit, View etc... Menus?

Post by MarauderIIC »

ibly31 wrote:*psuedocode*

if(form.menustrip1.File.Save_As.Clicked == true){
Save_As_Dialog.open();
}

*end psuedocode*
IIRC it's done in the resource file, sorry I can't be of more help, I'm not sure how many of us can, I'd recommend googling c++ menu tutorial, or something.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: File, Edit, View etc... Menus?

Post by wtetzner »

Hmm, it's been a long time since I've done any Win32 stuff in C++. But yeah, you use a resource file. In the file, say resourceFile.rc, you would put something like this:

Code: Select all

#include "resource.h"
MainMenu MENU DISCARDABLE
{
   POPUP "&File"
   {
      MENUITEM "New", MENU_FILE_NEW
      MENUITEM "OPEN", MENU_FILE_OPEN
      MENUITEM SEPARATOR
      MENUITEM "&Save", MENU_FILE_SAVE
      MENUITEM "Save As", MENU_FILE_SAVE_AS
      MENUITEM SEPARATOR
      MENUITEM "E&xit", MENU_FILE_EXIT
   }
   POPUP "&Help"
   {
      MENUITEM "&Controls", MENU_HELP_CONTROLS
      MENUITEM SEPARATOR
      MENUITEM "&About", MENU_HELP_ABOUT
   }
}
The & in the menu item names it used to select which letter is used to access the item after pressing alt.

And you're resource.h would include the defines for the constant values used in the resource file (MENU_FILE_NEW etc).

Code: Select all

// Menu Defines
#define MENU_FILE_NEW             2000
#define MENU_FILE_OPEN            2001
#define MENU_FILE_SAVE            2002
#define MENU_FILE_SAVE_AS         2003
#define MENU_FILE_EXIT            2004
#define MENU_HELP_CONTROLS        2005
#define MENU_HELP_ABOUT           2006
Of course, you can use whatever values you want (2000, 2001, etc.)

The when you initialize your window in C++, you would do something like this:

Code: Select all

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include "resource.h"

int WINAPI WinMain(HINSTANCE hinstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpszArgument,
                   int nCmdShow)
{
    HWND hwnd;
    WNDCLASSEX wndclass;
    wndclass.lpszMenuName = "MainMenu"; // Name of the menu
    ...
    // Initialize the rest of wndclass
    ...
Then in your callback function, you would do something like this to give functionality to the menu items:

Code: Select all

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch (msg)                  // handle the messages
    {
        case WM_COMMAND:
        {
            switch(LOWORD(wparam))
            {
                case MENU_GAME_EXIT:
                {
                    SendMessage(hwnd, WM_CLOSE, 0, 0);
                } break;
                
                case MENU_FILE_NEW:
                {
                    // Code for new file goes here
                } break;

                case MENU_FILE_OPEN:
                {
                    // Code for opening a file goes here
                } break;
                
                case MENU_FILE_SAVE:
                {
                     // Code for save goes here
                } break;
                
                case MENU_FILE_SAVE_AS:
                {
                    // Code for save as goes here
                } break;
                
                case MENU_FILE_EXIT:
                {
                    // Exit the program
                } break;
                
                case MENU_HELP_CONTROLS:
                {
                    // Help code goes here
                } break;

                default:
                    break;
            } // End menu switch
        } break;
        
        case WM_DESTROY:
        {
            PostQuitMessage(0);
        } break;
        
        default:
        {
            // Let the default window procedure handle the rest of the messages
            return DefWindowProc (hwnd, msg, wparam, lparam);
        } break;
    }
    return 0;
}
That should help, if you know how to do any Win32 programming. If you don't, well, then it probably didn't mean much :).
If you're interested in doing Win32 programming, I recommend looking at the tutorials on this site: catch22.net

Also, there is a book called "Tricks of the Windows Game Programming Gurus".
It has an entire chapter on Win32 programming, and the rest of the book is a really good game programming book. It uses DirectX, but the concepts can all be applied to SDL or whatever you're using in your games.
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: File, Edit, View etc... Menus?

Post by ibly31 »

Oh, I don't understand why anyone wants to make win32 programs... Isn't it just cmd prompt?

2 questions:

I have visual basic studio, I think that would be better for a utility, not an actual engine. Does anyone know how to parse/change/save text files in c++ and/or visual basic?

XML seems very useful, I understand HTML so I shouldn't be too much of a hassle, but how would one to about writing an XML parser?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: File, Edit, View etc... Menus?

Post by wtetzner »

ibly31 wrote:Oh, I don't understand why anyone wants to make win32 programs... Isn't it just cmd prompt?
No, Win32 is the windows programming api. It's used for creating windows, responding to events (mouse clicks, keyboard presses, etc.), and in general access OS functionality. SDL on windows, for example, uses the Win32 api to create a window for you. To create menus and buttons in C++, you would use the Win32 api. Or if you wanted, something like MFC, which is just a C++ wrapper around the Win32 api.
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: File, Edit, View etc... Menus?

Post by ibly31 »

Sorry, what's a wrapper? Is it like a library/API?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: File, Edit, View etc... Menus?

Post by wtetzner »

ibly31 wrote:Sorry, what's a wrapper? Is it like a library/API?
It's could be function calls, or classes, that "wrap" some other functionality. So MFC is a collection of C++ classes that use the Win32 api, so you don't have to.

An example of a wrapper class would be std::string. It wraps a char array, and exposes methods to manipulate it.
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: File, Edit, View etc... Menus?

Post by ibly31 »

oh, okay. Well what about my other two questions? VB and XML parser
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: File, Edit, View etc... Menus?

Post by wtetzner »

ibly31 wrote: I have visual basic studio, I think that would be better for a utility, not an actual engine. Does anyone know how to parse/change/save text files in c++ and/or visual basic?

XML seems very useful, I understand HTML so I shouldn't be too much of a hassle, but how would one to about writing an XML parser?
Yes, visual basic would be fine for writing utilities (level editor etc.), but I wouldn't use it for the game engine. As for parsing XML, there are libraries designed for this. I don't know of any specific ones for C++, but visual basic might have it. If you're using VB.NET, then there are definitely XML parser libraries for it, as part of the .NET framework.

If you don't have VB.NET, you can get the express edition here. Although I would personally use C# (also available on that page), but it's really just a personal preference. Both have access to the same libraries.
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: File, Edit, View etc... Menus?

Post by ibly31 »

I'm making ALL local games and utilities. And what exactly is C#? How much more different Is it then C and C++? BEcause, I'm looking for a simple language to make the easy things. I have the engine made in C++, so I'm good to go with VB
What's the difference between VB express and VB.NET?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
Post Reply