如何把菜单响应函数放到我的一个窗口类里。

opentuxedo 2002-06-11 05:14:43
主程序是基于Doc/View结构的,我在我的MainFrame中加入了一个Docking Window(用CControlBar做的),这个窗口在程序运行过程中一直存在。我现在要作一个菜单,并在Docking Window中响应这个菜单,我的作法是:
重载BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
BOOL result=CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
if(!result)
m_wndDockingWnd.OnCmdMsg(nID,nCode,pExtra,pHandlerInfo);
return result;
}
但是菜单总是灰的。
请问我应该怎么做?
...全文
83 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sterding 2002-06-12
  • 打赏
  • 举报
回复
Please send me your code with main annotation.

I think we can deal with it together.
opentuxedo 2002-06-12
  • 打赏
  • 举报
回复
pcman1990你说的没错,是顺序的问题,200分送上。
opentuxedo 2002-06-11
  • 打赏
  • 举报
回复
pcman1990谢谢,我已经在DockingWindow中加入了消息响应函数,因为我的程序比较大所以我简化一下发再发给你。
sterding:thanx for your concern.
Yeah,i understand you sir.But that isn't my case.Similar to your program,there's also a CDialogBar-derived memember in my MainFrame object named m_wndDockingWnd.But what i wanna do is not to switch between the two or more tabs.I just want to place my reactors to some menu items in a CWnd class which does not belong to any one of CApp,CDoc,CFrame or CView objects.The method which responds the menuitem has been added to my CWnd class,but the corresponding menu doesn't work any way.It always keeps in the tiresome invalidated gray color.Why?I don't know the delivering mechanism of the menu-updating messages.may you give me some kind of clue?
sterding 2002-06-11
  • 打赏
  • 举报
回复
I have successfully dealed with the same problem with yours in my graduation designing work.
First i have a member(CMyDlgBar m_myDlgBar) based on CControlBar in my CMainFrame class. When i want to change the active page of m_menuTab(a member of CTabCtrl) in CMyDlgBar,i have the following code in my CMainFrame::OnChangePage()
m_myDlgBar.m_menuTab.SetCurSel(2);
m_myDlgBar.m_menuTab.Invalidate();
----------------
Do you understand?
If you still have problem, you can mail to me(sterding@seu.edu.cn)
pcman1990 2002-06-11
  • 打赏
  • 举报
回复
你愿意的话,可以把你的代码发过来看看。
pcman1990@sina.com
pcman1990 2002-06-11
  • 打赏
  • 举报
回复
写过类似的代码,好像就是这样做的。
pcman1990 2002-06-11
  • 打赏
  • 举报
回复
DockWindow中相应菜单项ID的处理函数应该是存在的吧?
opentuxedo 2002-06-11
  • 打赏
  • 举报
回复
freelybird(阿愚) 谢谢关注。
不过消息处理函数一般不返回值即使返回值的话,这个值也不会被处理。
还有我之所以这样做是因为我有太多的菜单响应函数要在Docking Window中处理,所以我不想每一个函数都先在CMainFrame中映射一遍再发一个消息给DockingWindow.
再给这个贴子加100分,如果不够我再另开贴子补。
freelybird 2002-06-11
  • 打赏
  • 举报
回复
我也没做过,试试:

重载BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
BOOL result=CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
if(!result)
m_wndDockingWnd.OnCmdMsg(nID,nCode,pExtra,pHandlerInfo);
return TRUE;
}

另外在CMainFrame中写一个该菜单的消息处理函数, 最后return FALSE;
opentuxedo 2002-06-11
  • 打赏
  • 举报
回复
谢谢pcman1990(pcman)
不过还是不行,关键是菜单总是灰的,所以根本不响应我的点击
freelybird 2002-06-11
  • 打赏
  • 举报
回复
我也没做过,试试:

重载BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
BOOL result=CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
if(!result)
m_wndDockingWnd.OnCmdMsg(nID,nCode,pExtra,pHandlerInfo);
return TRUE;
}

另外在CMainFrame中写一个该菜单的消息处理函数, 最后return FALSE;
pcman1990 2002-06-11
  • 打赏
  • 举报
回复
如果不会引起其它问题的话,顺序改一下试试:
BOOL result = m_wndDockingWnd.OnCmdMsg(nID,nCode,pExtra,pHandlerInfo);
if(result) return TRUE;

return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
opentuxedo 2002-06-11
  • 打赏
  • 举报
回复
给个提示就可以。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧