sdi - mfc问题的子框架中的上下文菜单 [英] contextmenu in childframe of a sdi - mfc problem

查看:57
本文介绍了sdi - mfc问题的子框架中的上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

i有一个mfc-sdi program.i我的视图通过静态分割器解析为3子视图,在其中一个视图中,我创建了一个子框架,上面有一个可停靠的工具栏。 br />
有我的代码:



1.这就是我创建子框架的方式:

 BOOL CMainFrame :: OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext * pContext)
{
// TODO:在这里添加您的专业代码和/或调用基类
如果(!m_wndSpMain.CreateStatic( 2 1 ,WS_CHILD | WS_VISIBLE,AFX_IDW_PANE_FIRST) ){
TRACE0( CreateStaticSplitter \ n无法);
return FALSE;
}
if (!m_wndSpMain.CreateView( 0 0 ,RUNTIME_CLASS(COutputView),CSize( 100 100 ),pContext)){
TRACE0( 无法创建第一个窗格\ n );
return FALSE;
}
如果(!m_wndSpSub.CreateStatic(& m_wndSpMain, 1 2 ,WS_CHILD | WS_VISIBLE,m_wndSpMain.IdFromRowCol( 1 0 ))){
TRACE0( 无法创建嵌套拆分器\ n< /跨度>);
return FALSE;
}
if (!m_wndSpSub.CreateView( 0 0 ,RUNTIME_CLASS(CTab),CSize( 200 0 ),pContext)){
TRACE0( 无法创建第二个窗格\ n );
return FALSE;
}
// *************** ************************************************** ***********
// 最重要的代码是这里:
// ************** ************************************************** ************
pContext-> m_pNewViewClass = RUNTIME_CLASS(CMainView);
if (!m_wndSpSub.CreateView( 0 1 ,RUNTIME_CLASS(CmainSPFrame),CSize( 0 0 ),pContext)) {
TRACE0( 无法创建第三个窗格\ n);
return FALSE;
}
返回 TRUE; // CFrameWndEx :: OnCreateClient(lpcs,pContext);
}



因为你可以看到我有一个Cview类(CMainview)子框架(CmainSPFrame)。



2.这就是我在我的CMainview课上创建上下文菜单的方式:



向App添加上下文菜单

  void  CLedMatrixAnimatorApp :: PreLoadState()
{
GetContextMenuManager() - > AddMenu(_T( First View菜单),IDR_FIRSTVIEW );
}





添加上下文菜单查看

 < span class =code-keyword> void  CMainView :: OnContextMenu(CWnd *  / *   pWnd * / ,CPoint point)
{
#ifndef SHARED_HANDLERS

theApp.GetContextMenuManager() - > ShowPopupMenu(IDR_FIRSTVIEW,
point.x,point.y, this );
#endif
}





现在这个是我的问题:

我将菜单处理程序添加到我的CMainView类后,似乎没有ON_COMMAND消息发送到veiw并且所有菜单项仍然是灰色的,是否有somthin丢失?



抱歉我的英文不好,希望你回答我的问题。

最好的问候 - D rasool

解决方案

如果菜单项是灰色的,则禁用这些项目。



检查this类中的定义和消息处理程序。


thnx karstenk回复。

i解决问题。当添加contextmenu查看:

 theApp.GetContextMenuManager() - > ShowPopupMenu(IDR_FIRSTVIEW,
point.x,point.y,,TRUE);


theApp.GetContextMenuManager()->ShowPopupMenu(IDR_FIRSTVIEW, 
point.x,point.y,this, TRUE FALSE );





最后一个参数设置为TRUE,这应该是 FALSE ,因为你想使用你为

BEGIN_MESSAGE_MAP


hi.
i have a mfc- sdi program.i parse my view to 3 subview by static splitter and in one of the views i created a child frame to have a dockable toolbar on it.
there is my codes:

1.this is how i create the child frame:

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
	// TODO: Add your specialized code here and/or call the base class
if(!m_wndSpMain.CreateStatic(this, 2, 1, WS_CHILD | WS_VISIBLE, AFX_IDW_PANE_FIRST)){
TRACE0("Failed to CreateStaticSplitter\n");
return FALSE;
}
if(!m_wndSpMain.CreateView(0, 0, RUNTIME_CLASS(COutputView), CSize(100, 100), pContext)){
TRACE0("Failed to create first pane\n");
return FALSE;
}
if(!m_wndSpSub.CreateStatic(&m_wndSpMain, 1, 2,WS_CHILD | WS_VISIBLE, m_wndSpMain.IdFromRowCol(1, 0))){
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
if(!m_wndSpSub.CreateView(0, 0, RUNTIME_CLASS(CTab), CSize(200, 0), pContext)){
TRACE0("Failed to create second pane\n");
return FALSE;
}
//****************************************************************************
//the most important codes are here:
//****************************************************************************
pContext->m_pNewViewClass = RUNTIME_CLASS(CMainView);
if(!m_wndSpSub.CreateView(0, 1, RUNTIME_CLASS(CmainSPFrame), CSize(0, 0), pContext)){
TRACE0("Failed to create third pane\n");
return FALSE;
}
	return TRUE;//CFrameWndEx::OnCreateClient(lpcs, pContext);
}


as u can see i have a Cview class (CMainview) on my child frame (CmainSPFrame).

2.and this is how i create context menu on my CMainview class:

add context menu to App

void CLedMatrixAnimatorApp::PreLoadState()
{
GetContextMenuManager()->AddMenu(_T("First View menu"), IDR_FIRSTVIEW);
}



add context menu to view

void CMainView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
{
#ifndef SHARED_HANDLERS

theApp.GetContextMenuManager()->ShowPopupMenu(IDR_FIRSTVIEW,
	                                              point.x, point.y, this);
#endif
}



now this is my problem:
after i add menu handlers to my CMainView class,seems no ON_COMMAND message is send to veiw and all of the menu items are still gray, is there somthin missing?

sorry for my bad english,and hope u answer my question.
best regards - D rasool

解决方案

the items are disabled if the menu item are gray.

Check the defines and message handlers in the "this" class.


thnx karstenk for reply.
i solve the problem.when add contextmenu to view :

theApp.GetContextMenuManager()->ShowPopupMenu(IDR_FIRSTVIEW,
	                            point.x, point.y, this, TRUE);


theApp.GetContextMenuManager()->ShowPopupMenu(IDR_FIRSTVIEW,
	                            point.x, point.y, this,TRUE FALSE);



The last parameter is by set as TRUE, this should be FALSE since you want to use the ON_COMMAND macros you defined for your other menu items in the

BEGIN_MESSAGE_MAP

.


这篇关于sdi - mfc问题的子框架中的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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