MFC成员回调 [英] MFC Member Callbacks
本文介绍了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 ++中执行此调用的正确方法是什么?
感谢您的帮助!
解决方案
您可能需要添加通知处理程序,如 ^ ],并对控件中的特定状态更改做出反应.正确的方向.
我最终使用了ON_NOTIFY_REFLECT(NM_CUSTOMDRAW,OnCustomDraw)
然后向调用窗口发送一条验证数据的用户消息
(菜鸟的东西:/)
I''ve been away from MFC for way too long and have a newbie question regarding callbacks.
I''m trying to make a variation of the CListCtrl listbox that asks if a line is valid, then turns the line red if it isn''t. A callback or function pointer would be perfect, but I''m having trouble making it work.
This is basically what I''m trying to do:
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屋!
查看全文