16,548
社区成员




// CMyDlg 是你的主对话框类吧
// 1.建议你用消息,大概思路如下代码,随手写的,可能有错误
#define WM_MY_MESSAGE WM_USER+1
class CMyClass{
CMyClass(CWnd* pParentWnd);
void DoSomething();
private:
CWnd* m_pParentWnd;
};
CMyClass::CMyClass(CWnd* pParentWnd)
{
this->m_pParentWnd = pParentWnd;
}
void CMyClass::DoSomething()
{
if (m_pParentWnd != NULL)
{
m_pParentWnd->SendMessage(WM_MY_MESSAGE, 0, 0);
}
}
class CMyDlg{
void Function();
afx_msg LRESULT OnMyClassMessage(WPARAM wParam, LPARAM lParam);
};
ON_MESSAGE(WM_MY_MESSAGE, OnMyClassMessage)
void CMyDlg::Function()
{
CMyClass myClass(this);
}
LRESULT CMyDlg::OnMyClassMessage(WPARAM wParam, LPARAM lParam)
{
this->function();
}
// 2.学习下观察者模式