Thread: Adding a Menu to a Dialogbox?

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    9

    Adding a Menu to a Dialogbox?

    Hello,

    I was wondering if it's possible to add a menu to my Dialogbox as I use it as the main window for my entire program.

    My RC file looks like this
    Code:
    IDD_MAIN_DLG DIALOGEX 200, 100, 329, 200
    STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
        WS_SYSMENU
    CAPTION "Removed"
    FONT 8, "MS Shell Dlg" // , 400, 0, 0x1
    BEGIN
        LTEXT           "Server Address:",IDC_STATIC,68,14,72,8
        EDITTEXT        IDC_SERVER_ADDRESS,125,10,100,12,ES_CENTER | ES_AUTOHSCROLL
        LTEXT           "From:",IDC_STATIC,18,44,72,8
        EDITTEXT        IDC_FROM,40,40,100,12,ES_CENTER | ES_AUTOHSCROLL
        LTEXT           "To:",IDC_STATIC,185,44,72,8
        EDITTEXT        IDC_TO,200,40,100,12,ES_CENTER | ES_AUTOHSCROLL
        LTEXT           "Subject:",IDC_STATIC,18,64,72,8
        EDITTEXT        IDC_FROM,45,60,250,12,ES_RIGHT | ES_AUTOHSCROLL
    The rest is not implemented yet but it is working thus far. It is invoked through this command in the main program.

    Code:
            DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DLG),
                      hWnd, reinterpret_cast<DLGPROC>(DlgProc));
    I'm not sure where I would specifiy a menu, I know a couple ways of creating them, but you need to load them using loadMenu and createwindowex which I don't use. If it's possible to add a menu to the dialogbox, I'd really appreciate knowing how.
    Last edited by TCM; 08-24-2004 at 09:45 AM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Use the MENU statement which is one of a number of optional parameters of the DIALOGEX resource definition statement to associate a menu with your dialog box resource. For example, if you have defined a menu in your resource script with an id of ID_MENU then your script becomes:
    Code:
    IDD_MAIN_DLG DIALOGEX 200, 100, 329, 200
    STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
        WS_SYSMENU
    CAPTION "Removed"
    MENU ID_MENU
    FONT 8, "MS Shell Dlg" // , 400, 0, 0x1
    BEGIN
    LTEXT           "Server Address:",IDC_STATIC,68,14,72,8
        EDITTEXT        IDC_SERVER_ADDRESS,125,10,100,12,ES_CENTER | ES_AUTOHSCROLL
        LTEXT           "From:",IDC_STATIC,18,44,72,8
        EDITTEXT        IDC_FROM,40,40,100,12,ES_CENTER | ES_AUTOHSCROLL
        LTEXT           "To:",IDC_STATIC,185,44,72,8
        EDITTEXT        IDC_TO,200,40,100,12,ES_CENTER | ES_AUTOHSCROLL
        LTEXT           "Subject:",IDC_STATIC,18,64,72,8
        EDITTEXT        IDC_FROM,45,60,250,12,ES_RIGHT | ES_AUTOHSCROLL
    END
    
    /*example menu resource
    You must #define ID_MENU with some suitable value*/
    ID_MENU MENU
    BEGIN
      POPUP "&File"
        BEGIN
          MENUITEM "&Open...\tCtrl+O", IDM_FILE_OPEN, GRAYED
          MENUITEM "&Save...\tCtrl+S", IDM_FILE_SAVE
          MENUITEM SEPARATOR
          MENUITEM "E&xit",            IDCANCEL
        END
    END
    A list of the available resource defintion statements can be found on this msdn page.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    9
    It worked perfect, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM