示例:
class GMXcanvas : public CStatic
{
// Construction
public:
GMXcanvas();
// Operations
public:
using MsgNotifyFn = void(*)(GmxCanvasMsgEn msgType, void *userData);
//typedef void (*MsgNotifyFn)(GmxCanvasMsgEn msgType, void *userData);
void RegisterCallback(MsgNotifyFn fn,void *userData){ _msgCallback=fn;_userMsgCallbackData=userData;}
private:
MsgNotifyFn _msgCallback;
void *_userMsgCallbackData;
};
GMXcanvas::sumbit()
{
...
if(_msgCallback){
(*_msgCallback)(1200,_userMsgCallbackData);
}
...
}
class GMXgraph{
...
void OnCanvasMesage(GmxCanvasMsgEn msgType);
...
};
GMXgraph::GMXgraph(){
...
auto fn_callback=[](GmxCanvasMsgEn msgType,void *userData)->void{
GMXgraph *dlg = (GMXgraph*) userData;
dlg->OnCanvasMessage(msgType);
};
canvas-> RegisterCallback(fn_callback,this);
...
}
GMXgraph::OnCanvasMesage(GmxCanvasMsgEn msgType)
{
//do real things according msgType
...
}
原文地址:https://www.cnblogs.com/reboost/p/10664045.html