CompuServe Messages

#Subclassing CWnd

    10-Jul-94 20:23:43
Sb: #Subclassing CWnd
Fm: Poon T. Fung 73503,2515
To: all
I have problem trying to subclass a CWnd do that I can pass some of its messages to its parent. The classes look like: class CMyView : CView { CMyChildWnd m_wndChild; CEdit m_edit; } class CMyChildWnd : CWnd { } The child window is created to clip the edit control if it is partially visuable. Since the edit control and all other data resided in CMyDoc and CMyView, it is necessary to place CEdit and other controls in CMyView. In this case, I need to intercept the control messages and WM_CTLCOLOR send to CMyCHildWnd and pass them to CMyView. I try to implement this by subclassing a CWnd a second time. i.e. The messages will pass thru: CMyChildWndProc –> AfxWndProc –> DefWndProc I cannot get this working. Some how when I create the CEdit control, the WM_PARENTNOTIFY message appeared repeatedly on the stack until it overflow. I appreciate if anyone can tell me what I did wrong. The following is the code of the CMyChildWnd. =============================CMyChildWnd header================================= class CVariableClipWnd : public CWnd { friend LRESULT CALLBACK __export VariableClipWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam); // Construction public: CVariableClipWnd(); virtual BOOL Create(LPCSTR lpszClassName, LPCSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); // Implementation public: virtual ~CVariableClipWnd(); virtual WNDPROC* GetSuperWndProcAddr(void); static WNDPROC m_pfnSuperWndProc; // Generated message map functions protected: //{{AFX_MSG(CVariableClipWnd) afx_msg BOOL OnEraseBkgnd(CDC* pDC); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ===========================CMyChildWnd Implementation============================= WNDPROC CVariableClipWnd::m_pfnSuperWndProc = NULL; LRESULT CALLBACK __export VariableClipWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam); CVariableClipWnd::CVariableClipWnd() { } CVariableClipWnd::~CVariableClipWnd() { } BEGIN_MESSAGE_MAP(CVariableClipWnd, CWnd) //{{AFX_MSG_MAP(CVariableClipWnd) ON_WM_ERASEBKGND() //}}AFX_MSG_MAP END_MESSAGE_MAP() BOOL CVariableClipWnd::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default // return CWnd::OnEraseBkgnd(pDC); // Do nothing return TRUE; } WNDPROC* CVariableClipWnd::GetSuperWndProcAddr(void) { return &m_pfnSuperWndProc; } BOOL CVariableClipWnd::Create(LPCSTR lpszClassName, LPCSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { if (CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext)) { WNDPROC wndProcOld = WNDPROC(::SetWindowLong(m_hWnd, GWL_WNDPROC, DWORD(VariableClipWndProc))); ASSERT(wndProcOld == WNDPROC(AfxWndProc)); if (m_pfnSuperW