共用方式為


CSplitButton::SetDropDownMenu

Sets the drop-down menu that is displayed when a user clicks the drop-down arrow of the current split button control.

void SetDropDownMenu(
    UINT nMenuId, 
    UINT nSubMenuId
);
void SetDropDownMenu(
    CMenu* pMenu
);

Parameters

Parameter

Description

[in] nMenuId

The resource ID of the menu bar.

[in] nSubMenuId

The resource ID of a submenu.

[in] pMenu

Pointer to a CMenu object that specifies a submenu. The CSplitButton object deletes the CMenu object and its associated HMENU when the CSplitButton object goes out of scope.

Requirements

Header: afxcmn.h

This method is supported in Windows Vista and later.

Additional requirements for this method are described in Build Requirements for Windows Vista Common Controls.

Remarks

The nMenuId parameter identifies a menu bar, which is a horizontal list of menu bar items. The nSubMenuId parameter is a zero-based index number that identifies a submenu, which is the drop-down list of menu items associated with each menu bar item. For example, a typical application has a menu that contains the menu bar items, "File," "Edit," and "Help." The "File" menu bar item has a submenu that contains the menu items, "Open," "Close" and "Exit." When the drop-down arrow of the split-button control is clicked, the control displays the specified submenu, not the menu bar.

The following figure depicts a dialog box that contains a pager control and a (1) split button control. The (2) drop-down arrow has already been clicked and the (3) submenu is displayed.

Dialog with a splitbutton and pager control.

Example

The first statement in the following code example demonstrates the CSplitButton::SetDropDownMenu method. We created the menu with the Visual Studio resource editor, which automatically named the menu bar ID, IDR_MENU1. The nSubMenuId parameter, which is zero, refers to the only submenu of the menu bar.

    // Initialize the dropdown menu of the splitbutton control.
    m_splitButton.SetDropDownMenu(IDR_MENU1, 0);

    // Create the pager control.
    BOOL nRet;
    CRect rect;
    GetClientRect(&rect);
    nRet = m_pager.Create(
        (WS_VISIBLE | WS_CHILD | PGS_HORZ),
        CRect(rect.Width()/4, 5, (rect.Width() * 3)/4, 55),
        this,
        IDC_PAGER1); 

    m_pager.GetClientRect( &rect );
    nRet = m_button.Create(
        _T("This is a very, very long button. 012345678901234567890"), 
        (WS_VISIBLE | WS_CHILD), // Do not use CCS_NORESIZE.
        CRect(0,0,rect.Width(),30), 
        &m_pager, IDC_BUTTON1);

    m_pager.SetChild(m_button.m_hWnd);
    m_pager.SetButtonSize( 20 );
    m_pager.SetBorder( 1 );

See Also

Reference

CSplitButton Class

Hierarchy Chart

Other Resources

CSplitButton Members