简体   繁体   中英

Meaning of Ampersand(&), in .rc files

When coding Windows Applications using WIN32 on Windows, to non-dynamically load resources, one must load a *.rc file, which contains resource definition statements meant for defining common features in apps, such as buttons and menus. While reading a tutorial for the WIN32 API, from WinProg , I came across this code that confused me:

IDR_MYMENU MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "E&xit", ID_FILE_EXIT
    END

    POPUP "&Stuff"
    BEGIN
        MENUITEM "&Go", ID_STUFF_GO
        MENUITEM "G&o somewhere else", 0, GRAYED
    END
END

Looking at the code above, it is understandable what the function is. I myself understand what the code is doing in the .rc file, but the one thing that confused me was the ampersands,( & ), that are visible in the middle of the strings, such as "G&o somewhere else" (Between G and O), or "E&xit" (Between E and X). My specific questions to Stack Overflow are: What do the ampersands mean in the .rc files? Where do I have to put them when coding apps? I already looked in the MSDN link describing the function of the files, but I couldn't get an answer in the docs.

Those & s are only for menus, and they define the "menu access keys", or "mnemonics" , also called accelerators and shortcuts by others. And yes, the terminology is overloaded and confusing.

More reading: why you probably didn't realize these were there .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM