static LRESULT CALLBACK SubclassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT lr; CSubclassWnd *pSubClass = NULL; if(CSubclassWnd::m_SubclassWndMap.Lookup(hWnd, pSubClass) && pSubClass != NULL) { lr = pSubClass->WindowProc(uMsg, wParam, lParam); } else { lr = ::DefWindowProc(hWnd, uMsg, wParam, lParam); } return lr; }
////////////////// // Subclassed window proc for message hooks. Replaces AfxWndProc (or whatever // else was there before.) // LRESULT CALLBACK HookWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { #ifdef _USRDLL // If this is a DLL, need to set up MFC state AFX_MANAGE_STATE(AfxGetStaticModuleState()); #endif // Set up MFC message state just in case anyone wants it // This is just like AfxCallWindowProc, but we can't use that because // a CSubclassWnd is not a CWnd. // MSG& curMsg = AfxGetThreadState()->m_lastSentMsg; MSG oldMsg = curMsg; // save for nesting curMsg.hwnd = hwnd; curMsg.message = msg; curMsg.wParam = wp; curMsg.lParam = lp; // Get hook object for this window. Get from hook map CSubclassWnd* pSubclassWnd = theHookMap.Lookup(hwnd); ASSERT(pSubclassWnd); LRESULT lr; if (msg==WM_NCDESTROY) { // Window is being destroyed: unhook all hooks (for this window) // and pass msg to orginal window proc // WNDPROC wndproc = pSubclassWnd->m_pOldWndProc; theHookMap.RemoveAll(hwnd); lr = ::CallWindowProc(wndproc, hwnd, msg, wp, lp); } else { // pass to msg hook lr = pSubclassWnd->WindowProc(msg, wp, lp); } curMsg = oldMsg; // pop state return lr; }