Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Windows Menus and Allegro 5

This thread is locked; no one can reply to it. rss feed Print
Windows Menus and Allegro 5
Desmond Taylor
Member #11,943
May 2010
avatar

I am messing about testing to see weather I can add a menu with allegro 5's displays and it turns out that I can. However I have no idea on how I can interact with it :/

Screenshot of the menu.
{"name":"604334","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/b\/7bb82cebd2746f0c51d3cf92a43e1675.png","w":646,"h":508,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/b\/7bb82cebd2746f0c51d3cf92a43e1675"}604334

Code for menu creation.

#SelectExpand
7 HMENU hMenuBar; 8 HMENU hMenu; 9 10 hMenuBar = CreateMenu(); 11 hMenu = CreateMenu(); 12 13 #define IDM_FILE_NEW 1 14 #define IDM_FILE_OPEN 2 15 #define IDM_FILE_QUIT 3 16 17 AppendMenu( hMenu, MF_STRING, IDM_FILE_NEW, "&New" ); 18 AppendMenu( hMenu, MF_STRING, IDM_FILE_OPEN, "&Open" ); 19 AppendMenu( hMenu, MF_SEPARATOR, 0, NULL ); 20 AppendMenu( hMenu, MF_STRING, IDM_FILE_QUIT, "&Quit" ); 21 22 AppendMenu( hMenuBar, MF_POPUP, (UINT_PTR)hMenu, "&File" ); 23 24 HWND hWnd = engine->GetHWND(); 25 SetMenu( hWnd, hMenuBar );

Is it possible to do this?

Edit: I have looked around the MSDN and I have found this.

#SelectExpand
1UINT WINAPI GetMenuState( 2 __in HMENU hMenu, 3 __in UINT uId, 4 __in UINT uFlags 5);

I am just about to go out so I cannot test it yet but fingers crossed this is what I was looking for.

I shall edit this post or reply when I get back and have tested it. I shall be a few hours though.

jmasterx
Member #11,410
October 2009

Usually the way you interact with it is via the WNDPROC function, when the window gets a WM_COMMAND message, you respond to it. I don't think you can access it though since Allegro is the one that accesses it.

Desmond Taylor
Member #11,943
May 2010
avatar

Nope, my idea didn't work. Oh well, Back to messing with something else instead.

Matthew Leverton
Supreme Loser
January 1999
avatar

I just committed to SVN a function that would help:

bool al_add_win_window_callback(ALLEGRO_DISPLAY *display,
   bool (*callback)(ALLEGRO_DISPLAY *, UINT, WPARAM, LPARAM))

It could be used to intercept the messages that the menu generates:

bool handle_menu_message(ALLEGRO_DISPLAY *d, UINT m, WPARAM w, LPARAM l)
{
  if (m == WM_COMMAND)
  {
    int id = LOWORD(w);
    // generate some event
    return true; // tells Allegro not to process message
  }
  return false;
}

al_add_win_window_callback(display, handle_menu_message);

There's also a good chance that the native dialogs addon will support cross platform menus in SVN/5.2 within the next couple of weeks.

Evert
Member #794
November 2000
avatar

There's also a good chance that the native dialogs addon will support cross platform menus in SVN/5.2 within the next couple of weeks.

About that, it occurred to me that it might be a good idea to look at cross-platform APIs like Qt or GTK and see how they handle the per application/per window issue on different platforms to get some pointers on how to do this (if GTK now has a proper OS X port, the last time I looked at it I could only get the X11 port to work).

Matthew Leverton
Supreme Loser
January 1999
avatar

http://doc.qt.nokia.com/4.7-snapshot/mac-differences.html#menu-bar

It sounds as if it updates the main system menu as you switch windows. That probably involves "deleting" the current system menu and rebuilding it from scratch on every display switch. If that's doable on OS X/Allegro, then I think it makes the most sense from a cross platform standpoint.

If a person wants the same menu on every window, then he should call al_set_window_menu(display, menu) after every time he creates a display.

Somewhere else it states that if one window has multiple menus (a case we wouldn't support in Allegro), only the outermost/first menu is uses.

Desmond Taylor
Member #11,943
May 2010
avatar

I so want to test this out but my machine has broken so now I'm stuck on Puppy Linux with no compiling tools or anything. I tried using Windows XP on here and it just crashes and so does Debian 6.0.

Looks like there will be a good update when I get my new PC in about 4-5 weeks.

Go to: