在多列中显示菜单项 [英] Displaying menu items in multiple columns

查看:37
本文介绍了在多列中显示菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试改进我正在开发的火车指挥游戏的用户界面.

I am trying to improve the user interface for a Train Conductor game I am working on.

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

One of the things I am doing is displaying the list of vehicles in a popup menu. I want to use multiple columns instead of a single long column.

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

The menu's list of vehicles pops up when the right mouse button is clicked.

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

I am not sure how to approach this, I'm sure the answer is simple and I'm just not seeing it.

现在的样子

我想要的样子

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

The following is a code snippet of the part which appends the list to the menu:

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

推荐答案

MF_MENUBARBREAKMF_MENUBREAK 添加到标志以创建菜单栏:

Add MF_MENUBARBREAK or MF_MENUBREAK to the flags to create menu columns:

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

这篇关于在多列中显示菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆