Hello,
Use CriticalSection like this :
Add CriticalSection in CXTPSkinObject Class
static CCriticalSection CS_Skin;
//////////////////////////////////////////////////////////
XTPSkinObject.cpp
//////////////////////////////////////////////////////////
CCriticalSection CXTPSkinObject::CS_Skin;
void CXTPSkinObject::OnBeginHook(UINT nMessage, XTPSkinDefaultProc defProc, PROC defProcAddr, LPVOID defProcPrevWndFunc) { CS_Skin.Lock(); InternalAddRef();
DEFWINDOW_DESCRIPTIOR des;
des.defProc = defProc; des.nMessage = nMessage; des.defProcAddr = defProcAddr; des.lpPrev = defProcPrevWndFunc;
m_arrDescriptors.AddHead(des); CS_Skin.Unlock(); } void CXTPSkinObject::OnEndHook() { CS_Skin.Lock(); m_arrDescriptors.RemoveHead(); InternalRelease(); CS_Skin.Unlock(); }
////////////////////////////////////////////////////////////////
XTPSkinManagerApiHook.cpp
////////////////////////////////////////////////////////////////
BOOL CXTPSkinManagerApiHook::CallHookDefWindowProc(HWND hWnd, PROC pfnOrig, XTPSkinDefaultProc defProc, LPVOID lpPrev, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& lResult) { if (!XTPSkinManager()->IsEnabled()) return FALSE;
CXTPSkinObject* pSkinObject = XTPSkinManager()->Lookup(hWnd);
if (!pSkinObject || pSkinObject->m_bCustomDraw) return FALSE;
CXTPSkinObject::CS_Skin.Lock(); if (!pSkinObject->m_arrDescriptors.IsEmpty()) { if (nMessage == pSkinObject->m_arrDescriptors.GetHead().nMessage) { CXTPSkinObject::CS_Skin.Unlock(); return FALSE; } } CXTPSkinObject::CS_Skin.Unlock();
if (defProc == xtpSkinDefaultCallWindowProc && pSkinObject->IsDefWindowProcAvail(nMessage)) { BOOL bAvail = FALSE; WNDPROC lpWndProc = (WNDPROC)lpPrev;
if (IsSystemWindowModule(lpWndProc, &bAvail) || !bAvail) { lpWndProc = 0; }
if (lpWndProc != 0 && (!XTPSkinManager()->IsWin9x() || ((DWORD_PTR)lpWndProc < (DWORD_PTR)0x70000000))) { return FALSE; } }
MSG& curMsg = AfxGetThreadState()->m_lastSentMsg; MSG oldMsg = curMsg; curMsg.hwnd = hWnd; curMsg.message = nMessage; curMsg.wParam = wParam; curMsg.lParam = lParam;
pSkinObject->OnBeginHook(nMessage, defProc, pfnOrig, lpPrev);
BOOL bResult = pSkinObject->OnHookDefWindowProc(nMessage, wParam ,lParam, lResult);
pSkinObject->OnEndHook();
curMsg = oldMsg;
if (bResult) return TRUE;
return FALSE; }
|