本文介绍了Trackpopupmenu访问冲突读取位置C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在对话框中的任意位置右键单击弹出菜单



我在资源中创建了一个菜单


使用带有菜单的TrackPopupMenu时
我正在瘦窗口



和使用子菜单时我收到了这个错误



我尝试过:



I wanted to show popup menu on right click anywhere in the dialog

I created one menu in resource

while using the TrackPopupMenu with menu I'm getting thin window

and while using with submenu I'm getting that error

What I have tried:

void CMenuPraticeDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{

	GetCursorPos(&point);
	CMenu menu;
    VERIFY(menu.LoadMenu(IDR_MENU_POPUP));
    CMenu *pSub = menu.GetSubMenu(1);
    // Modify menu items here if necessary (e.g. gray out items)
//Here I'm getting error
    int nCmd = pSub->TrackPopupMenuEx(
        TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_VERPOSANIMATION | TPM_RETURNCMD | TPM_NONOTIFY,
        point.x, point.y, AfxGetMainWnd(), NULL);
    if (nCmd)
        SendMessage(WM_COMMAND, nCmd);

}










POINT pt;
//getting the current cursor point
GetCursorPos(&pt);
//Here I'm getting thin window
menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON,pt.x,pt.y,this );

推荐答案

CMenu *pSub = menu.GetSubMenu(1);

何时从资源加载的菜单只包含一个弹出菜单(这是常见的情况) GetSubMenu()返回 NULL



所以改为通过仓位 0





当使用 TrackPopupMenu [ex] 时,菜单必须是通过调用 CMenu检索的弹出菜单:: GetSubMenu()或者是使用 CMenu :: CreatePopupMenu 创建的。使用普通菜单无效。

[/ EDIT]

When the menu loaded from the resources contains only one popup menu (which is a common case) GetSubMenu() returns NULL.

So pass the position 0 instead.


When using TrackPopupMenu[Ex], the menu must be a popup menu retrieved by calling CMenu::GetSubMenu() or having been created using CMenu::CreatePopupMenu. Using a normal menu will not work.
[/EDIT]


这篇关于Trackpopupmenu访问冲突读取位置C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 09:38