MFC成员回调 [英] MFC Member Callbacks

查看:106
本文介绍了MFC成员回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我离开MFC太久了,对回调有一个新手问题.

我正在尝试对CListCtrl列表框进行更改,询问列表行是否有效,然后将其变为红色(如果无效).回调或函数指针将是完美的,但我无法使其正常工作.

这基本上就是我想要做的:

  class  CListCtrl2: public  CListCtrl
{
公共:
    布尔(* DataIsValidCheck)( void  * data); // 远程功能
受保护的:
     void  DrawItem( void  * data);
}
无效 CListCtrl2 :: DrawItem(无效 *数据)
{
    布尔 showNormal =  false ;
    如果(DataIsValidCheck!= NULL)// (如果已设置) ,然后命名为
       showNormal = DataIsValidCheck(data);
    如果(显示正常)
       textcolor = black;
    其他
       textcolor = red;
    ...
}

 class  MyWindow: public  CDialog
{
公共:
    布尔 CheckItemValidity( void  * data); // 具有验证项目功能的父窗口
受保护的:
    CListCtrl2 ListCtrl; // 列表控件
}
MyWindow :: MyWindow()
{
    ListCtrl2.DataIsValidCheck = -> CheckItemValidity;
}
布尔 MyWindow :: CheckItemValidity( void  * itemData)
{
   如果(...)
      返回 其他
      返回 ;
} 



在MFC C ++中执行此调用的正确方法是什么?
感谢您的帮助!

解决方案

您可能需要添加通知处理程序,如class CListCtrl2 : public CListCtrl { public: bool (*DataIsValidCheck)(void *data); // a remote function protected: void DrawItem(void *data); } void CListCtrl2::DrawItem(void *data) { bool showNormal=false; if(DataIsValidCheck!=NULL) // if its set, then call it showNormal=DataIsValidCheck(data); if(showNormal) textcolor=black; else textcolor=red; ... } class MyWindow : public CDialog { public: bool CheckItemValidity(void *data); // parent window with ability to validate item protected: CListCtrl2 ListCtrl; // the list control } MyWindow::MyWindow() { ListCtrl2.DataIsValidCheck = this->CheckItemValidity; } bool MyWindow::CheckItemValidity(void *itemData) { if(...) return true; else return false; }



What is the right way to do this call in MFC C++?
Thanks for any help!

解决方案

You will probably need to add a notification handler(s) as described here[^], and react to particular status changes within the control.


Thanks Richard - that got me in the right direction.
I ended up using ON_NOTIFY_REFLECT (NM_CUSTOMDRAW, OnCustomDraw)
to then send the calling window a user message that verifies the data
(rookie stuff :/ )


这篇关于MFC成员回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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