Home > Software engineering >  Two object corresponding to the same response function, how to implement different functions
Two object corresponding to the same response function, how to implement different functions

Time:04-03

A CMYList class in two classes: CWnd1 and CWnd2 respectively defined CMYList m_List and CMYList m_List,
Then CMYList class NM_RCLICK response and pop-up menus, menu response function in CMYList (if the response function is written in the CWnd1 and CWnd2 won't response after click),
CWnd1 and CWnd2 the I need, please click on the menu not achieve the same function, but they were CMYList can only corresponds to a function, how to implement?

CodePudding user response:

Stupid way is, I can think of to write a class CMYList2 inheritance CMYList class, CWnd1 and CWnd2 respectively defined CMYList m_List and CMYList2 m_List, so that we can in CMYList and CMYList2 write separate menu response function, but it is not good, want to know is there a better way

CodePudding user response:

id=: : GetDlgCtrlID (pMsg - & gt; HWND);
AfxDump & lt; the switch (id)
{
Case IDC_BUTTON8://X +
DoJogging (AXIS_X, 0.25, 0.25, 100.0);
break;
Case IDC_BUTTON9://X -
DoJogging (AXIS_X, 0.25, 0.25, 100.0);
break;

CodePudding user response:

Can convey the message to the parent class, let the parent class processing

CMYList: : OnCommand (WPARAM WPARAM, LPARAM LPARAM)
{
The GetParent () - & gt; PostMessage (wParam, lParam);

Return __super: : OnCommand (wParam, lParam);
}

  • Related