65,208
社区成员
发帖
与我相关
我的任务
分享#include <vector>
using namespace std;
typedef void (CALLBACK *MSGCALLBACK)(DWORD dwMsgID, WPARAM wParam, LPARAM lParam );
class core
{
public:
void RegMsgDeal(DWORD dwMsgID, MSGCALLBACK pCB)
{
}
void Dispatch(DWORD dwMsg, WPARAM wParam, LPARAM lParam)
{
}
};
class A
{
public:
void __stdcall Test( DWORD dwMsg, WPARAM wParam, LPARAM lParam );
};
#define WM_MSG WM_USER+1000
core g_mycore;
A g_a;
void CZafDlg::OnButton1()
{
DWORD dwMsg = WM_MSG;
g_mycore.RegMsgDeal( dwMsg, g_a.Test );
}class A
{
public:
void Test( DWORD dwMsg, WPARAM wParam, LPARAM lParam );
};
typedef void (A::*MSGCALLBACK)(DWORD dwMsgID, WPARAM wParam, LPARAM lParam );
typedef struct tagInfo
{
DWORD MsgID;
MSGCALLBACK pCB;
}tInfo;
class core
{
public:
void RegMsgDeal(DWORD dwMsgID, MSGCALLBACK pCB);
void Dispatch(DWORD dwMsg, WPARAM wParam, LPARAM lParam);
vector<tInfo>m_vct;
};
void core::RegMsgDeal(DWORD dwMsgID, MSGCALLBACK pCB)
{
tInfo tTmp;
tTmp.MsgID = dwMsgID;
tTmp.pCB = pCB;
m_vct.push_back(tTmp);
}
void core::Dispatch(DWORD dwMsg, WPARAM wParam, LPARAM lParam)
{
((tInfo)m_vct[0]).pCB( dwMsg, wParam, lParam );//这里出错
}
void A::Test( DWORD dwMsg, WPARAM wParam, LPARAM lParam )
{
TRACE("dwMsg = %d, wParam = %d, lParam = %d\n", dwMsg, wParam, lParam);
}class A
{
public:
void Test( int dwMsg, int wParam, int lParam ){};
};
typedef void (A::*MSGCALLBACK)(int dwMsgID, int wParam, int lParam );
class core
{
public:
void RegMsgDeal(int dwMsgID, MSGCALLBACK pCB)
{
}
void Dispatch(int dwMsg, int wParam, int lParam)
{
}
};
core g_mycore;
A g_a;
int main()
{
int dwMsg = 1000;
g_mycore.RegMsgDeal( dwMsg, &A::Test );
}