Cmd-W not working :(


When I press Cmd-W (in order to close all my App’s windows) - nothing happens?
Can anyone shed any light on why this may be happening?

I have the default menubar shown on all windows, (just in case you ask).

I have the following code in the status item handler for my app - could that be the cause?

// FORCE THE Z-ORDER TO BE ON TOP OF ANY OTHER OPEN WINDOWS Declare Function NSClassFromString Lib "Cocoa" ( inName As CFStringRef ) As Ptr Declare Function sharedApplication Lib "Cocoa" selector "sharedApplication" ( classRef As Ptr ) As Ptr Dim myApp As Ptr = sharedApplication( NSClassFromString( "NSApplication" ) ) Declare Sub activateIgnoringOtherApps Lib "Cocoa" selector "activateIgnoringOtherApps:" ( appRef As Ptr, flag As Boolean ) activateIgnoringOtherApps( myApp, True )

Thank you all in advance.

I don’t think Cmd-W works automatically…
I think you have to deal with it yourself…

and Apple just “suggests” this key should be used…

as I cannot get it to work in a normal project…

  1. Add a WindowClose item to your FileMenu (in MainMenuBar). Give it a shortcut key of W and text property of “Close Window”.
  2. Add a Menu Handler for WindowClose to your window.
  3. Add the line self.close to the top of your Menu Handler code.

You’ll need to add a menu handler to each window you want to be able to close with Cmd-W. That should be, usually, all of them.

If you use a subclass of Window you can implement the menu handler there.
Or you can implement a menu handler in App for this (don’t forget to use the App.EnableMenuItems event for enabling/disabling the item).

Thanks Gavin and Eli - I will try that after my dinner :slight_smile:

  • Add “Close Window” item in the File menu with key W and use modifier
  • Add a menu handler to that item in App (so it works throughout the app) with inside :

Now Cmd-W will close the current window.

Thanks everyone - all working now.

With my method you do not need to add anything in each window Close event…

you might actually want to implement cancel close on them uniquely though

Indeed, but adding a menu handler for FileWindowClose in each window is very cumbersome when a single one in App will do fine.

Sure - nothing wrong with what you suggested