/** * @file XTPHookManager.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPHOOKMANAGER_H__) # define __XTPHOOKMANAGER_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPSimpleCriticalSection; /** * @brief * HookAble interface. * @see * CXTPHookManager, CXTPHookManager::SetHook */ class _XTP_EXT_CLASS CXTPHookManagerHookAble { public: /** * @brief * Constructs a CXTPHookManagerHookAble object */ CXTPHookManagerHookAble(); /** * @brief * Destroys a CXTPHookManagerHookAble object, handles cleanup and deallocation. */ virtual ~CXTPHookManagerHookAble(); public: /** * @brief * This member function is called by WindowProc, or is called during message reflection. * @param hWnd Window handle that the message belongs to. Always NULL for windows hooks. * @param nMessage Specifies the message to be sent. For windows hooks it contains the hook code * value. * @param wParam Specifies additional message-dependent information. * @param lParam Specifies additional message-dependent information. * @param lResult The return value of WindowProc. Depends on the message; may be NULL. * For windows hooks it is a return value from a hook procedure. Refer to * SetWindowsHookEx documentation for your platform SDK for more details. * @return * TRUE if message was processed. Ignored for windows hooks. * @see * OnPostHookMessage */ virtual int OnHookMessage(HWND hWnd, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& lResult); /** * @brief * This member function is called after a message has been processed by default window * procedure. Never called for windows hooks. * @param hWnd Window handle that the message belongs to. * @param nMessage Specifies the message to be sent. * @param wParam Specifies additional message-dependent information. * @param lParam Specifies additional message-dependent information. * @param lResult The return value of WindowProc. Depends on the message; may be NULL. * @return * TRUE if message was processed. * @see * OnHookMessage */ virtual int OnPostHookMessage(HWND hWnd, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& lResult); /** * @brief * This member function is called right after a hook is attached to the window. * @param hWnd Window handle to which a hook is being attached. Always NULL * for windows hooks. * @see * OnHookDetached */ virtual void OnHookAttached(HWND hWnd); /** * @brief * This member function is called right before a hook is to be detached from the window. * @see * OnHookAttached */ virtual void OnHookDetached(); public: BOOL m_bAutoDestroy; /**< TRUE to automatically delete hook */ }; /** * @brief * CXTPHookManager is standalone class. It is used to hook a CWnd object * in order to intercept and act upon window messages that are received. * @details * To access CXTPHookManager methods use XTPHookManager function * @see * XTPHookManager, CXTPHookManagerHookAble */ class _XTP_EXT_CLASS CXTPHookManager { friend class CXTPSingleton; private: class CHookSink; protected: /** * @brief * Constructs a CXTPHookManager object. */ CXTPHookManager(); public: /** * @brief * Destroys a CXTPHookManager object, handles cleanup and de- * allocation. */ ~CXTPHookManager(); public: /** * @brief * This member function will hook a window so that its messages are * intercepted before they are passed on to the specified window. * @param hWnd A handle to a window that represents that represents the window to hook. * @param pHook Hookable class that will receive messages */ void SetHook(HWND hWnd, CXTPHookManagerHookAble* pHook); /** * @brief * Sets local windows hook. * @param idHook Local windows hook ID. See platform SDK documentation of SetWindowsHooksEx. * @param pHook Hookable class that will receive messages * @param dwThreadId Target thread identified. If 0 the calling thread ID is used. * @return * TRUE if local windows hook is installed.. */ BOOL SetHook(int idHook, CXTPHookManagerHookAble* pHook, DWORD dwThreadId = 0); /** * @brief * Removes a hook associated with a window. * @param hWnd A handle to a window that hooks need to remove * @param pHook Hookable class that hooks need to remove */ void RemoveHook(HWND hWnd, CXTPHookManagerHookAble* pHook); /** * @brief * Removes all hooks associated with a window. * @param hWnd A handle to a window that hooks need to remove */ void RemoveAll(HWND hWnd); /** * @brief * Removes a hookable object and associated hooks if applicable. * @param pHook Hookable class that hooks need to remove */ void RemoveAll(CXTPHookManagerHookAble* pHook); /** * @brief * Removes a local windows hook and all its associated hookable objects. * @param idHook Local windows hook ID. See platform SDK documentation of SetWindowsHooksEx. */ void RemoveAll(int idHook); /** * @brief * Searches collection of Hookable interfaces that receive hooks of specified window. * @param hWnd A handle to a window need to test * @return * CHookSink pointer if found; otherwise returns NULL; */ CHookSink* Lookup(HWND hWnd); public: /** * @brief * Calls the default window procedure. * @return Result value of default message processing. */ LRESULT Default(); /** * @brief * Calls the default window procedure. * @param wParam [in] Specifies additional message information. The content of this parameter * depends on the value of the Msg parameter. * @param lParam [in] Specifies additional message * information. The content of this parameter depends on the value of the Msg * parameter. * @return Result value of default message processing. */ LRESULT Default(WPARAM wParam, LPARAM lParam); /** * @brief * Calls the default window procedure. * @param hWnd [in] handle to HWND * @param message [in] message id * @param wParam [in] Specifies additional message information. The content of this parameter * depends on the value of the Msg parameter. * @param lParam [in] Specifies additional message * information. The content of this parameter depends on the value of the Msg * parameter. * @return Result value of default message processing. */ LRESULT Default(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); private: static LRESULT CALLBACK HookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_MSGFILTER(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_KEYBOARD(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_GETMESSAGE(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_CALLWNDPROC(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_CBT(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_MOUSE(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_HARDWARE(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_DEBUG(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_SHELL(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_FOREGROUNDIDLE(int nCode, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK OnWH_CALLWNDPROCRET(int nCode, WPARAM wParam, LPARAM lParam); LRESULT OnWindowsHookProc(int idHook, int nCode, WPARAM wParam, LPARAM lParam); public: static UINT m_nMsgSinkRemoved; private: void RemoveAll(); void RemoveAll(HWND hWnd, BOOL bLastMessage); CXTPSimpleCriticalSection* m_pGuard; CMap m_mapHooks; typedef CMap WindowsHookMap; CArray m_WindowsHooks; friend _XTP_EXT_CLASS CXTPHookManager* AFX_CDECL XTPHookManager(); friend class CHookSink; }; /** * @brief * Call this function to access CXTPHookManager members. * Since this class is designed as a single instance object you can * only access version info through this method. You cannot * directly instantiate an object of type CXTPHookManager. * * Example: *
XTPHookManager()->SetHook(hWnd, this);
* @return A global hook manager object pointer. */ _XTP_EXT_CLASS CXTPHookManager* AFX_CDECL XTPHookManager(); /** * @brief * Shadow options of selected paint manager * @see * CXTPPaintManager::GetShadowOptions() */ enum XTPShadowOptions { xtpShadowOfficeAlpha = 1, /**< Office alpha shadow */ xtpShadowShowPopupControl = 2 /**< Draw shadow for popup controls */ }; /** * @brief * CXTPShadowManager is standalone class used to manage CommandBars' shadows. * It should not be confused with a frame shadow (read more about CXTPFrameShadowManager). */ class _XTP_EXT_CLASS CXTPShadowManager : public CXTPCmdTarget { private: typedef BOOL(WINAPI* LPFNUPDATELAYEREDWINDOW)(HWND hwnd, HDC hdcDst, POINT* pptDst, SIZE* psize, HDC hdcSrc, POINT* pptSrc, COLORREF crKey, BLENDFUNCTION* pblend, DWORD dwFlags); private: class CShadowWnd; class CShadowList; public: /** * @brief * Constructs a CXTPShadowManager object. */ CXTPShadowManager(); public: /** * @brief * Destroys a CXTPShadowManager object, handles cleanup and deallocation. */ ~CXTPShadowManager(); public: /** * @brief * Check the system alpha shadow ability. * @return * TRUE if alpha shadow available; otherwise returns FALSE */ BOOL IsAlphaShadow(); /** * @brief * Sets the command bar shadow. * @param rcWindow Bounding rectangle of parent window * @param pShadowOwner Points to a parent windows */ void SetShadow(CRect rcWindow, CWnd* pShadowOwner); /** * @brief * Sets the command bar shadow. * @param pShadowOwner Points to a parent windows * @param rcExclude Excluded rectangle. * @param nLevel Recursive level of the parent window */ void SetShadow(CWnd* pShadowOwner, const CRect& rcExclude = CRect(0, 0, 0, 0), int nLevel = 0); /** * @brief * Removes shadows for the command bar. * @param pShadowOwner Points to a CXTPCommandBar object */ void RemoveShadow(CWnd* pShadowOwner); /** * @brief * Call this method to move shadow to specified offset * @param pShadowOwner Shadow to move * @param szOffset Window move offset */ void OffsetShadow(CWnd* pShadowOwner, CSize szOffset); /** * @brief * This method used to enumerate all shadows of specific parent window * @param pShadowOwner Point to parent owner of shadows * @return * Position to first element in list of shadows. Use GetNext method to retrieve it. */ POSITION GetHeadPosition(CWnd* pShadowOwner) const; /** * @brief * This method used to enumerate all shadows of specific parent window. Call * GetHeadPosition to get position of first shadow * @param pos Current position of shadow in the list * @return * Pointer to Shadow corresponded to pos position. */ CWnd* GetNext(POSITION& pos) const; /** * @brief * Returns combination of XTPShadowOptions flags for shadows * @return * Combination of XTPShadowOptions flags */ int GetShadowOptions() const; /** * @brief * Call this method to set shadow options. * @param nOptions Combination of XTPShadowOptions flags to set. It can be the following values: * xtpShadowOfficeAlpha: Office alpha shadow. * xtpShadowShowPopupControl: Draw shadow for pop-up controls. */ void SetShadowOptions(int nOptions); /** * @brief * Call this method to set specific color for shadows * @param clrShadow New color to set */ void SetShadowColor(COLORREF clrShadow); public: BOOL m_bUseSystemSaveBitsStyle; /**< If this flag is set CS_SAVEBITS style will be used for shadow windows. */ private: void DestroyShadow(CShadowWnd*); CShadowWnd* CreateShadow(BOOL bHoriz, CRect rc, CRect rcExclude, CWnd* pShadowOwner, BOOL bControlPopup, int nLevel); private: LPFNUPDATELAYEREDWINDOW m_pfnUpdateLayeredWindow; CShadowList* m_pShadows; BOOL m_bAlphaShadow; int m_nShadowOptions; COLORREF m_clrShadowFactor; friend class CShadowWnd; }; /** @cond */ AFX_INLINE int CXTPShadowManager::GetShadowOptions() const { return m_nShadowOptions; } AFX_INLINE void CXTPShadowManager::SetShadowOptions(int nOptions) { m_nShadowOptions = nOptions; } AFX_INLINE void CXTPShadowManager::SetShadowColor(COLORREF clrShadow) { m_clrShadowFactor = clrShadow; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif //#if !defined(__XTPHOOKMANAGER_H__) /** @endcond */