代码如下:
void CDialogThreadDlg::OnBmenu()
{
// TODO: Add your control notification handler code here
CRect rect;
m_BMenu.GetWindowRect(&rect); CMenu BMenu; BMenu.CreateMenu(); BMenu.AppendMenu(MF_STRING,IDM_ABOUT,"关于");
BMenu.AppendMenu(MF_STRING,IDCANCEL,"退出"); BMenu.TrackPopupMenu(TPM_LEFTALIGN,rect.left,rect.bottom,this);
}
我使用一个按钮响应函数,然后来实现一个下拉菜单
但是菜单只能显示一个竖边,请问这是怎么回事哦
void CDialogThreadDlg::OnBmenu()
{
// TODO: Add your control notification handler code here
CRect rect;
m_BMenu.GetWindowRect(&rect); CMenu BMenu; BMenu.CreateMenu(); BMenu.AppendMenu(MF_STRING,IDM_ABOUT,"关于");
BMenu.AppendMenu(MF_STRING,IDCANCEL,"退出"); BMenu.TrackPopupMenu(TPM_LEFTALIGN,rect.left,rect.bottom,this);
}
我使用一个按钮响应函数,然后来实现一个下拉菜单
但是菜单只能显示一个竖边,请问这是怎么回事哦
没有用,弹出的那个菜单依然不会显示出来,最后那个菜单项是可以显示
代码如下:
void CDialogThreadDlg::OnBmenu()
{
// TODO: Add your control notification handler code here
CRect rect;
m_BMenu.GetWindowRect(&rect); CMenu BMenu; BMenu.CreateMenu(); BMenu.AppendMenu(MF_STRING,IDM_ABOUT,"关于");
BMenu.AppendMenu(MF_STRING,IDCANCEL,"退出"); ///修改的地方如下:
CMenu* pMenu=BMenu.GetSubMenu(0);
pMenu->TrackPopupMenu(TPM_LEFTALIGN,rect.left,rect.bottom,this); //BMenu.TrackPopupMenu(TPM_LEFTALIGN,rect.left,rect.bottom,this); }
搞清楚什么叫主菜单,什么叫弹出菜单。
把BMenu.CreateMenu();
改成BMenu.CreatePopupMenu();
就行了。
TrackPopupMenu事实上也可以显示,但显示出来的会有些问题.如果LZ想要右击的快捷菜单,则也可以通过对WM_CONTEXTMENU消息处理
void CMyPro18View::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
CMenu menu;
menu.LoadMenu(IDR_MENU1);//IDR_MENU1自己添加的要用于显示的菜单
CMenu*pmenu=menu.GetSubMenu(0);
pmenu->TrackPopupMenu(TPM_RIGHTBUTTON|TPM_RIGHTALIGN,point.x,point.y,this);
menu.DestroyMenu();
///原理很相似,这个方法稍微简单些
}
{
// TODO: Add your control notification handler code here
CRect rect;
m_BMenu.GetWindowRect(&rect); CMenu BMenu; BMenu.CreateMenu(); BMenu.AppendMenu(MF_STRING,IDM_ABOUT,"关于");
BMenu.AppendMenu(MF_STRING,IDCANCEL,"退出"); ///修改的地方如下:
CMenu* pMenu=BMenu.GetSubMenu(0);
pMenu->TrackPopupMenu(TPM_LEFTALIGN,rect.left,rect.bottom,this); //BMenu.TrackPopupMenu(TPM_LEFTALIGN,rect.left,rect.bottom,this); } 这样就可以显示了的,没有问题的。