【问题标题】:Displaying menu items in multiple columns在多列中显示菜单项
【发布时间】:2019-10-22 06:30:41
【问题描述】:

我正在努力改进我正在开发的 Train Conductor 游戏的用户界面。

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

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

我不知道如何解决这个问题,我确定答案很简单,但我只是没有看到它。

现在的样子

我希望它看起来如何

以下是将列表附加到菜单的部分的代码sn-p:

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));
}

【问题讨论】:

    标签: c++ winapi win32gui


    【解决方案1】:

    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);
    

    【讨论】:

    • 嗨,我会将它添加到哪些标志?我在 MF_POPUP 和 MF_STRING 之后尝试过,但都没有成功
    • @RayH99 见the documentation
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多