在多列中显示菜单项

时间:2019-06-06 17:42:51

标签: c++ winapi win32gui

我正在尝试改善我正在研究的《火车指挥》游戏的用户界面。

我正在做的一件事是在弹出菜单中显示车辆列表。我想使用多列而不是单个长列。

单击鼠标右键时,会弹出菜单中的车辆列表。

我不确定该如何处理,我确定答案很简单,只是看不到。

现在看起来如何

image

我希望它看起来如何

image

以下是将列表添加到菜单的部分的代码片段:

Guide::GetTrainList(&TrainList); //this receives the list of the trains

if(TrainList.size() > 0) //this will tell the code to continue if the trains exist (decided by the player which trains to play with)
{
    for(int j = 0; j < TrainList.size(); j++)
    {
        CString FollowTrain = TrainList[j]->GetMenuName();
        FollowTrain.Append((m_FollowTrain != NULL && m_FollowTrain == TrainList[j])?L" (Followed)":L"");
        GoToTrainMenu.AppendMenu(MF_STRING, Counter++, TrainList[j]->GetMenuName());
        FollowTrainMenu.AppendMenu(MF_STRING, Counter++, FollowTrain);
        MoveTrainMenu.AppendMenu(MF_STRING, Counter++, TrainList[j]->GetMenuName());
    }

    PopupMenu.AppendMenu(MF_POPUP, (unsigned int)GoToTrainMenu.Detach(), GetStringFromResource(GOTOTRAIN));
    PopupMenu.AppendMenu(MF_POPUP, (unsigned int)FollowTrainMenu.Detach(), GetStringFromResource(FOLLOWTRAIN));
    PopupMenu.AppendMenu(MF_POPUP, (unsigned int)MoveTrainMenu.Detach(), GetStringFromResource(MOVETRAIN));
}

1 个答案:

答案 0 :(得分:0)

在标记中添加MF_MENUBARBREAKMF_MENUBREAK,以创建菜单列:

HMENU hMenu = CreatePopupMenu();
AppendMenuA(hMenu, MF_STRING, 1, "Foo");
AppendMenuA(hMenu, MF_STRING|MF_MENUBREAK, 2, "Bar");
AppendMenuA(hMenu, MF_STRING, 3, "Baz");
AppendMenuA(hMenu, MF_STRING, 4, "A");
AppendMenuA(hMenu, MF_STRING|MF_MENUBARBREAK, 5, "B");
AppendMenuA(hMenu, MF_STRING, 6, "C");
UINT cmd = TrackPopupMenuEx(hMenu, TPM_RETURNCMD|TPM_RIGHTBUTTON, pt.x, pt.y, hWnd, NULL);