WM_NOTIFY and ON_NOTIFY_REFLECT

by --MSDN
The message-map macro for reflected messages is slightly different than for regular notifications: it has _REFLECT appended to its usual name. For instance, to handle a WM_NOTIFY message in the parent, you use the macro ON_NOTIFY in the parent’s message map. To handle the reflected message in the child control, use the ON_NOTIFY_REFLECT macro in the child control’s message map. In some cases, the parameters are different, as well. Note that ClassWizard can usually add the message-map entries for you and provide skeleton function implementations with correct parameters.
阅读更多

ON_NOTIFY 和 ON_NOTIFY_REFLECT

12-03

我有一个类 CImageSortListCtrl (父类是CListCtrl)rn在MESSAGE_MAP里面有:rnON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag)rn目的是CImageSortListCtrl自己处理一些控件内部的拖动操作。rn但现在需要重用这个控件,我在CDialog中使用它,想使用 rnON_NOTIFY(LVN_BEGINDRAG, IDC_LST_IMAGE, OnBeginDragLstImage)来映射函数OnBeginDragLstImage,以使其支持控件之间的拖动操作。IDC_LST_IMAGE是一个CListCtrl的资源号。rn但我的ON_NOTIFY得不到响应,查阅MSDN TN062:消息反射觉得很含糊。rnrn如下:rn如果你在控件的父窗口类中为一个或一定范围特定的消息提供了一个处理函数,对于同样的消息,如果在您的处理中您并没有调用其基类的处理函数它就会覆盖掉被反射的消息处理。例如,如果你在一个对话框类中试图处理 WM_CTLCOLOR,您的处理将覆盖掉任何被反射的消息处理函数。rnIf you have supplied a handler for a specific message, or for a range of messages, in your parent window''''s class, it will override reflected message handlers for the same message provided you don''''t call the base class handler function in your own handler. For example, if you handle WM_CTLCOLOR in your dialog box class, your handling will override any reflected message handlers.rnrn如果你在父窗口中为一个或一系列一定范围的特定的 WM_NOTIFY 消息提供一个处理函数,您的处理函数只有当这些发送消息的子控件通过ON_NOTIFY_REFLECT() 宏就不会有一个被反射消息处理了。如果该处理返回 TRUE,消息就也会给父窗口来处理,而如果它返回的是一个 FALSE值,就不会让父窗口来处理该消息。请注意:被反射的消息是在通知消息之前被处理。rnrnIf, in your parent window class, you supply a handler for a specific WM_NOTIFY message or a range of WM_NOTIFY messages, your handler will be called only if the child control sending those messages does not have a reflected message handler through ON_NOTIFY_REFLECT(). If you use ON_NOTIFY_REFLECT_EX() in your message map, your message handler may or may not allow the parent window to handle the message. If the handler returns TRUE, the message will be handled by the parent as well, while a call that returns FALSE does not allow the parent to handle it. Note that the reflected message is handled before the notification message.rnrn当一个 WM_NOTIFY 消息被发送后,控件就得到了第一次的机会来处理它。如果任何其他的被反射消息被发送,父窗口会有第一个机会来处理之,而控件将能接收被反射的消息。为了达到这样的目的,在控件类消息映射中需要一个处理函数和一个合适的入口。rnWhen a WM_NOTIFY message is sent, the control is offered the first chance to handle it. If any other reflected message is sent, the parent window has the first chance to handle it and the control will receive the reflected message. To do so, it will need a handler function and an appropriate entry in the control''''s class message map.

单文档CListCtrl的ON_NOTIFY_REFLECT无效

12-07

为了实现clistctrl这个控件可以动态的改变行列的背景色,生成了一个类CListCtrlEx继承自CListCtrl,然后在里面响应了消息ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw),在OnCustomDraw函数里实现了:rn NMLVCUSTOMDRAW* lplvcd = (NMLVCUSTOMDRAW*)(pNMHDR);rn int nRow = (int)lplvcd->nmcd.dwItemSpec; rn switch (lplvcd->nmcd.dwDrawStage)rn rn case CDDS_PREPAINT:rn *pResult |= CDRF_NOTIFYITEMDRAW;rn break;rn rn case CDDS_ITEMPREPAINT: rnrn if(nRow == g_row) rn rn lplvcd->clrTextBk = RGB(0x00,0x00,0x00);rn *pResult = CDRF_NEWFONT; rn else rn lplvcd->clrTextBk = RGB(0xBB,0xCC,0xFF);rn lplvcd->clrText = RGB(0x44,0x33,0x00);rn *pResult = CDRF_NEWFONT; rn rn rn break;rnrn default:rn *pResult = CDRF_DODEFAULT; rn break;rn rn程序在对话框程序里正常执行,均达到了目的,可是放到一个单文档的工程里,就只能进入CDDS_PREPAINT选项,也就是说后面的选项都无法执行,造成无法重绘背景色,这里为什么呢?rn为什么一样的类,在单文档中就不行,在对话框中就可以呢,网上有很多这种现象,都没有完美的解决方案。rn单文档中应用的方法:rnint CtestctrlView::OnCreate(LPCREATESTRUCT lpCreateStruct)rnrn if (CFormView::OnCreate(lpCreateStruct) == -1)rn return -1;rnrn // TODO: Add your specialized creation code herern m_pListCtrl = new CListCtrlEx;rn m_pListCtrl->Create(WS_CHILD | LVS_SINGLESEL | LVS_REPORT |LVS_SORTASCENDING ,CRect(0,0,400,200), this, IDC_LISTCTRL); rnrn m_pListCtrl->SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);rnrn m_pListCtrl->InsertColumn (0,_T("Code"),LVCFMT_CENTER);rn m_pListCtrl->InsertColumn (1,_T("Title"),LVCFMT_LEFT);rn m_pListCtrl->InsertColumn (2,_T("Author"),LVCFMT_LEFT);rn m_pListCtrl->InsertColumn (3,_T("Publish House"),LVCFMT_CENTER);rn m_pListCtrl->InsertColumn (4,_T("Category"),LVCFMT_CENTER);rn return 0;rnrnrnvoid CtestctrlView::OnSize(UINT nType, int cx, int cy)rnrn CFormView::OnSize(nType, cx, cy);rnrn // TODO: Add your message handler code herern CRect r;rn GetClientRect(r);rn //m_ListCtrl.SetColumnWidth (0,r.right /3);rn m_pListCtrl->SetColumnWidth (1,r.right /3);rn m_pListCtrl->SetColumnWidth (2,r.right /3);rn m_pListCtrl->SetColumnWidth (3,(r.right /3) /2 );rn m_pListCtrl->SetColumnWidth (4,(r.right /3) /2 );rnrnrnrn m_pListCtrl->SetWindowPos (&wndTop,0,0,r.right,r.bottom ,SWP_SHOWWINDOW);rnrn请大家指教。

ON_NOTIFY 和 ON_NOTIFY_REFLECT 消息传递 ++急

02-08

SOSrn我真是疯了,几天都没搞好。rn我动态创建工具栏,然后创建BUTTON。现在想在BUTTON上创建个下拉列表。rn工具栏ID 555,por-up菜单ID = ID_TEXTrnrn if (!m_ToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0,0,0,0), 555))rn rn TRACE0("Failed to create ToolBar\n");rn return -1;rn rn if (!m_ReBar.Create(this/*,RBS_BANDBORDERS*/))rn rn TRACE0("Failed to create rebar\n");rn return -1; // fail to creatern rn ...rn 添加冷图,热图 rn ...rn// m_ToolBar.ModifyStyle(0, TBSTYLE_FLAT |CBRS_TOOLTIPS | TBSTYLE_TRANSPARENT | TBBS_CHECKBOX );rn m_ToolBar.SetButtons(NULL,6);rnrn m_ToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);rnrn DWORD dwStyle = m_ToolBar.GetButtonStyle(5);rn dwStyle |= TBSTYLE_DROPDOWN;rn m_ToolBar.SetButtonStyle(5, dwStyle);rnrn     ...rn m_ToolBar.SetButtonInfo(4, MS_HOME, TBBS_BUTTON, 4);rn m_ToolBar.SetButtonInfo(5, MS_SEARCH, TBBS_DROPDOWN, 5);rn ...rn然后我在CMainFrame 加入rn 1. afx_msg void OnToolbarDropDown(NMTOOLBAR* pnmh, LRESULT* plRes); //或(NMHDR * pNotifyStruct,LRESULT* result )rn ON_NOTIFY(TBN_DROPDOWN, 555, OnToolbarDropDown) //555改成网上例子的AFX_IDW_TOOLBAR也无效果rn void CMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)rn ... rnrn 2.afx_msg void OnToolbarDropDown(NMHDR * pNotifyStruct , LRESULT* result)rn ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown)rn ...rnrn上面两种都没效果,不知道怎么的.按扭图是灰色.rn之后我又加了COMMAND响应后,按扭有了效果.可就是dropdown 没反映...rnOnToolbarDropDown函数里面是没问题...用资源建菜单和BUTTON我试过可行.rnrn请讲详细些,先谢谢了.rn

没有更多推荐了,返回首页