void CCtrlMessageBarDblSubclassWnd::UnSubclassWindow(HWND hWnd) { if (hWnd == NULL) return; if (IsSubclassed(hWnd)) SetWindowLong(hWnd, GWL_WNDPROC, (LONG)AfxGetAfxWndProc()); }
BOOL CWnd::SubclassWindow(HWND hWnd) { if (!Attach(hWnd)) return FALSE; // allow any other subclassing to occur PreSubclassWindow(); // now hook into the AFX WndProc WNDPROC* lplpfn = GetSuperWndProcAddr(); WNDPROC oldWndProc = (WNDPROC)::SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)AfxGetAfxWndProc()); ASSERT(oldWndProc != (WNDPROC)AfxGetAfxWndProc); if (*lplpfn == NULL) *lplpfn = oldWndProc; // the first control of that type created #ifdef _DEBUG else if (*lplpfn != oldWndProc) { TRACE0("Error: Trying to use SubclassWindow with incorrect CWnd\n"); TRACE0("\tderived class.\n"); TRACE3("\thWnd = $%04X (nIDC=$%04X) is not a %hs.\n", (UINT)hWnd, _AfxGetDlgCtrlID(hWnd), GetRuntimeClass()->m_lpszClassName); ASSERT(FALSE); // undo the subclassing if continuing after assert ::SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)oldWndProc); } #endif return TRUE; }
BOOL CCtrlMessageBarDblSubclassWnd::SubclassWindow(HWND hWnd, CCtrlMessageBar* pBar/*=NULL*/) { if (hWnd == NULL) return FALSE; CWnd* pWnd = CWnd::FromHandlePermanent(hWnd); // if not subclassed once, let us subclass. if (pWnd == NULL) { _CTempWndSubclass *pNewWnd = new _CTempWndSubclass; ASSERT(pNewWnd != NULL); VERIFY(pNewWnd->SubclassWindow(hWnd)); ASSERT(CWnd::FromHandlePermanent(hWnd) != NULL); } if (IsSubclassed(hWnd)) // we've already subclassed it return TRUE; // attach the bar to the window, using properties SetProp(hWnd, szInstancePropertyName, (HANDLE)pBar); #ifdef _DEBUG WNDPROC oldWndProc = (WNDPROC) #endif // _DEBUG ::SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)OurWndProc); ASSERT(oldWndProc == AfxGetAfxWndProc()); ASSERT(oldWndProc != OurWndProc); return TRUE; }