IDC_FUNCTIONALITY MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "E&xit",                IDM_EXIT
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&About ...",           IDM_ABOUT
    END
END

This is an example of a part of the default Foo.rc file distributed with VisualC++ 2010(Express), this is how this section of code was shipped. I'm interested in knowing why Exit is expressed in the code as "E&xit" and all the other elements are the 'right way around'. Obviously, it's a string, it means nothing in terms of code, which leads me onto my next point. Why do these strings require "&" at all? Removing them has no effect, as I assumed, so why are they there in the first place?

As for any oddity in any language, it's either there, 'for historical or hysterical reasons'. Or it's not an oddity, which is it?

I recognise that this is not really a C++ question, more of a win32 API question.

The ampersand actually marks the character which is to be used as the hotkey; if you look at the menu as it actually is rendered, you'll see that those letters all are underscored. In the case of 'Exit', the 'x' is the hotkey character (that is to say, if you hit ALT-X, it would cause the program to exit), so the ampersand is directly before it. It only seems out of place because all of the other items have hotkeys with the first letter of the word, but this does not need to be the case, as you can see.

As for why 'x' is used for exit rather than 'E', it is because, according to the Windows style standard, Alt-E is used as the hotkey for the Edit menu, even if it isn't present in the application.

Thanks! I can't help but feel that I should have recognised that, admittedly I rarely use shortcuts at all. If only google had supplied the answer before I made myself look like a tool, again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.