joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.76k stars 381 forks source link

How to add items to the Win32 System Menu (source code modification) #484

Open emendelson opened 6 years ago

emendelson commented 6 years ago

Using old dbDOS code as a basis, I once added items like a web link and a message box to the Win32 system menu of DOSBox, as described here:

http://www.vogons.org/viewtopic.php?t=33612

I've been trying to apply this to DOSBox-X's menu.cpp without success. My main goal is to add a "Keyboard help..." box that would display key assignments, but nothing I've tried gets the job done. I'm not asking anyone else to do my work for me, but if anyone thinks this is a good idea, and knows how to put it into effect, I'll be grateful.

emendelson commented 6 years ago

Ignore that request: I figured it out for myself...

joncampbell123 commented 6 years ago

DOSBox-X has a central function in menu.cpp to set up the system menu and add items. Did you find it?

emendelson commented 6 years ago

EDIT: I can't get the code to display correctly, but I hope this is clear...

Yes, I did. I don't actually know what I'm doing, but this seemed to work (I removed your Show Menubar item because my project doesn't need the menu toolbar).

  1. I added a couple of identifiers to resource.h, incrementing the ID_WIN_SYSMENU_RESTOREMENU item already there.

  2. Then, using those identifiers, I added this to menu.cpp:

` { const char *msg = "&Keyboard help...";

    memset(&mii, 0, sizeof(mii));
    mii.cbSize = sizeof(mii);
    mii.fMask = MIIM_ID | MIIM_STRING | MIIM_STATE;
    mii.fState = MFS_DEFAULT;
    mii.wID = ID_WIN_SYSMENU_KEYBOARDHELP;
    mii.dwTypeData = (LPTSTR)(msg);
    mii.cch = strlen(msg) + 1;

    s = InsertMenuItem(sysmenu, GetMenuItemCount(sysmenu), TRUE, &mii);
}

{
    const char *msg = "&About DOSBox-X...";

    memset(&mii, 0, sizeof(mii));
    mii.cbSize = sizeof(mii);
    mii.fMask = MIIM_ID | MIIM_STRING | MIIM_STATE;
    mii.fState = MFS_DEFAULT;
    mii.wID = ID_WIN_SYSMENU_ABOUTWIN31;
    mii.dwTypeData = (LPTSTR)(msg);
    mii.cch = strlen(msg) + 1;

    s = AppendMenu(sysmenu, MF_STRING, ID_WIN_SYSMENU_ABOUTWIN31, msg);
}

`

  1. And then I added these items to sdlmain.cpp, after your show-menubar item:

`case ID_WIN_SYSMENU_KEYBOARDHELP: ::MessageBoxA(HWND(), ( "Ctrl-Alt-Enter : Toggle full-screen\r" "Alt-Pause : Pause DOSBox-X\r" "Ctrl-Alt-F4 : Paste ASCII text from host clipboard\r" // "Ctrl-Alt-F5 : Refresh directories if needed\r" "Ctrl-Alt-F7 : Decrease frameskip (faster graphics)\r" "Ctrl-Alt-F8 : Increase frameskip (slower graphics)\r" "Ctrl-Alt-F10 : Capture/release mouse\r" "Ctrl-Alt-F11 : Slow down emulation\r" "Ctrl-Alt-F12 : Speed up emulation\r" "Ctrl-Alt-Home : Restart DOSBox-X\r" ), "Win31DOSBox-X Keyboard help", MB_OK); break;

                    case ID_WIN_SYSMENU_ABOUTWIN31:
                        ::MessageBoxA(HWND(), (
                            "DOSBox-X for Win31DOSBOX\r"
                            "\r"
                            "Description to follow...\r"
                            ),
                            "About DOSBox-X", MB_OK);
                        break;

`

I used AppendMenu in item 2 above because I couldn't figure out how to make InsertMenuItem work for anything after the first item. My programming method is to throw code at the screen until something seems to work, and I know this is all very clumsy...