请教高手,在BCG中关联右键处理函数 我用BCG界面开发包做了个小东西,不过我的右键菜单好象没关联上,显示为灰色,处理函数已写,请高手指教啊,第一次用BCG,先谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用ClassWizard,找到菜单的ID,然后选择一个处理消息的类,添加一个消息处理函数就行拉 呵呵,在BCG下好象不太一样啊,我看见它自带的例子里面根本没消息处理函数,却能显示出菜单来,好奇怪 // 在头文件声明CMenu m_menu;// 在cpp初始化函数里VERIFY(m_menu.LoadMenu(IDR_MENU_GROUP));// 在OnContextMenu消息响应函数里CMenu *pPopupMenu = m_menu.GetSubMenu(0);ASSERT(pPopupMenu != NULL);AfxGetApp()->GetContextMenuManager()->ShowPopupMenu(pPopupMenu->GetSafeHmenu(), point.x, point.y, this, TRUE); void COutputList::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu menu; menu.LoadMenu(IDR_POPUP_OUTPUT); CMenu* pSumMenu = menu.GetSubMenu(0); if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CBCGPMDIFrameWnd))) { CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu; if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE)) return; ((CBCGPMDIFrameWnd*)AfxGetMainWnd())->OnShowPopupMenu (pPopupMenu); UpdateDialogControls(this, FALSE); } SetFocus ();} 我要实现的菜单是在CWorkspaceBar中,一共有三个CImageList,也就是三个菜单,菜单能显示出来,不过处理函数好象没关联上,点了也没反映 我的系统也是跟四楼一样用的.CMenu menu;menu.LoadMenu(IDR_xxxxx);CMenu* pPopupMenu = menu.GetSubMenu(0);theApp.GetContextMenuManager()->ShowPopupMenu(pPopupMenu->GetSafeHmenu(),point.x,point.y,this); 可以正常弹出右键菜单. BEGIN_MESSAGE_MAP(CPlaneTreeWnd, CTreeCtrl) //{{AFX_MSG_MAP(CPlaneTreeWnd) ON_COMMAND(ID_MNADDPLANE, OnMnAddPlane) ON_COMMAND(ID_MNDELETEPLANE, OnMnDeletePlane) ON_COMMAND(ID_MNMODIFYPLANE, OnMnModifyPlane) //}}AFX_MSG_MAPEND_MESSAGE_MAP()处理函数void CPlaneTreeWnd::OnMnAddPlane() { // TODO: Add your command handler code here AfxMessageBox("测试的!");可以弹出菜单,但是单击没反映 } void CWorkspaceBar::OnContextMenu(CWnd* pWnd, CPoint point) { int iActiveTab = m_wndTabs.GetActiveTab (); if (iActiveTab < 0) { return; } CTreeCtrl* pWndTree = (CTreeCtrl*) m_wndTabs.GetActiveWnd (); ASSERT_VALID (pWndTree); if (point != CPoint (-1, -1)) { //--------------------- // Select clicked item: //--------------------- CPoint ptTree = point; pWndTree->ScreenToClient (&ptTree); HTREEITEM hTreeItem = pWndTree->HitTest (ptTree); if (hTreeItem != NULL) { pWndTree->SelectItem (hTreeItem); } } UINT uiMenuResId = 0; switch (iActiveTab) { case 0: uiMenuResId = IDR_PLANEMENU; break; case 1: // Example: uiMenuResId = IDR_POPUP_RESOURCE_VIEW; break; case 2: // Example: uiMenuResId = IDR_POPUP_FILE_VIEW; break; default: ASSERT (FALSE); return; } if (uiMenuResId != 0) { pWndTree->SetFocus (); theApp.ShowPopupMenu (uiMenuResId, point, AfxGetMainWnd ()); }} 有用过BCG的高手指教下啊,急!! CTreeCtrl* pWndTree = (CTreeCtrl*) m_wndTabs.GetActiveWnd ();改为:CPlaneTreeWnd* pWndTree = (CPlaneTreeWnd*) m_wndTabs.GetActiveWnd (); 如何提注册表的操作权限? 如何才能改变单文档程序非客户区的背景色? 光标样式更改的问题? 问一个弄了好久都没没弄懂的问题 如何利用winpcap实现远程监测? 关于文件读写问题--频繁的!!!100分! 准备换工作...深圳的... 利用ODBC如何得到空表字段的名称和类型 那位大侠可以给出仿真MFC的Sericalize的源代码吗? test 串口超时判断的问题 cstdiofile 写文件怎么换行?
CMenu m_menu;
// 在cpp初始化函数里
VERIFY(m_menu.LoadMenu(IDR_MENU_GROUP));
// 在OnContextMenu消息响应函数里
CMenu *pPopupMenu = m_menu.GetSubMenu(0);
ASSERT(pPopupMenu != NULL);
AfxGetApp()->GetContextMenuManager()->ShowPopupMenu(pPopupMenu->GetSafeHmenu(),
point.x, point.y, this, TRUE);
{
CMenu menu;
menu.LoadMenu(IDR_POPUP_OUTPUT); CMenu* pSumMenu = menu.GetSubMenu(0); if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CBCGPMDIFrameWnd)))
{
CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu; if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
return; ((CBCGPMDIFrameWnd*)AfxGetMainWnd())->OnShowPopupMenu (pPopupMenu);
UpdateDialogControls(this, FALSE);
} SetFocus ();
}
CMenu menu;
menu.LoadMenu(IDR_xxxxx);
CMenu* pPopupMenu = menu.GetSubMenu(0);
theApp.GetContextMenuManager()->ShowPopupMenu(pPopupMenu->GetSafeHmenu(),point.x,point.y,this);
可以正常弹出右键菜单.
//{{AFX_MSG_MAP(CPlaneTreeWnd)
ON_COMMAND(ID_MNADDPLANE, OnMnAddPlane)
ON_COMMAND(ID_MNDELETEPLANE, OnMnDeletePlane)
ON_COMMAND(ID_MNMODIFYPLANE, OnMnModifyPlane)
//}}AFX_MSG_MAPEND_MESSAGE_MAP()
处理函数
void CPlaneTreeWnd::OnMnAddPlane()
{
// TODO: Add your command handler code here
AfxMessageBox("测试的!");
可以弹出菜单,但是单击没反映
}
{
int iActiveTab = m_wndTabs.GetActiveTab ();
if (iActiveTab < 0)
{
return;
} CTreeCtrl* pWndTree = (CTreeCtrl*) m_wndTabs.GetActiveWnd ();
ASSERT_VALID (pWndTree); if (point != CPoint (-1, -1))
{
//---------------------
// Select clicked item:
//---------------------
CPoint ptTree = point;
pWndTree->ScreenToClient (&ptTree); HTREEITEM hTreeItem = pWndTree->HitTest (ptTree);
if (hTreeItem != NULL)
{
pWndTree->SelectItem (hTreeItem);
}
} UINT uiMenuResId = 0;
switch (iActiveTab)
{
case 0:
uiMenuResId = IDR_PLANEMENU;
break; case 1:
// Example: uiMenuResId = IDR_POPUP_RESOURCE_VIEW;
break; case 2:
// Example: uiMenuResId = IDR_POPUP_FILE_VIEW;
break; default:
ASSERT (FALSE);
return;
} if (uiMenuResId != 0)
{
pWndTree->SetFocus ();
theApp.ShowPopupMenu (uiMenuResId, point, AfxGetMainWnd ());
}}
CTreeCtrl* pWndTree = (CTreeCtrl*) m_wndTabs.GetActiveWnd ();
改为:
CPlaneTreeWnd* pWndTree = (CPlaneTreeWnd*) m_wndTabs.GetActiveWnd ();