Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:33:57+00:00 2026-05-29T09:33:57+00:00

I have created a gaming application that has only one window. Application is created

  • 0

I have created a gaming application that has only one window. Application is created without a help of .xib files as described here: How can I create a GUI and react to Cocoa events programmatically?

Now, I can catch standard ‘key up/down’ events in application’s main loop:

 NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
 NSEventType eventType = [event type];
 if (eventType == NSKeyDown)
 {
    my_uint32 keycode = [event keyCode];
    input::doSomeWork(keycode);
 }

Also, I can properly quit an application when a red cross is pressed on the window with the following code:

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
    g_myEngine.stop();
    return NSTerminateNow;
}

But how do I:

a) Catch when a menu item ‘Quit MyApplicationName’ is chosen?

b) Handle Cmd-Q event?


update:
I have added this code:

id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id appName = [[NSProcessInfo processInfo] processName];
id quitTitle = [@"Quit " stringByAppendingString:appName];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];

and now application exits from the menu, but Cmd-Q still does not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:33:58+00:00Added an answer on May 29, 2026 at 9:33 am

    Try setting the menu item’s key equivalent modifier mask.

    Don’t forget to also add menu items for Close Window, Minimize, Hide, Enter/Exit Full Screen, etc., plus the entire Edit menu, including all text-editing features, current and future. (Why the Edit menu? I assume that, at the least, you’ll enable the user to name their save games, their high scores (if applicable), or their character. If you have any text editing anywhere in the application, you should support the full Edit menu.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a UserControl that has a ListView in it. The ListView is
Have created a custom navigation menu in wordpress that has some pages and some
I have created a small daemon (basically a console application that hides the console
I have created a mac application using the WebView. But issue is that webView
I have created a PHP-script to update a web server that is live inside
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
Have created simple Ajax enabled contact forms before that have around 12 fields -
Have created an attribute property in TableView1.h and pushing that attributes value to another
I have a JPanel that I have created a MouseListener for and I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.