Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
6.8 KiB

  1. #ifndef __HANDLERS_H__
  2. #define __HANDLERS_H__
  3. //---------------------------------------------------------------------------//
  4. #define _MSG_SWITCH_ // determines handler selection implementation
  5. // (switch block vs. linear array search (vs. hash table lookup?) )
  6. //-------------------//
  7. // Forwards
  8. class CThemeWnd;
  9. struct _NCTHEMEMET;
  10. typedef struct _NCTHEMEMET NCTHEMEMET;
  11. //---------------------------------------------------------------------------
  12. // Hook modification
  13. BOOL ApiHandlerInit( const LPCTSTR pszTarget, USERAPIHOOK* puahTheme, const USERAPIHOOK* puahReal );
  14. //---------------------------------------------------------------------------
  15. // Window message handler support
  16. //---------------------------------------------------------------------------
  17. //---------------------------------------------------------------------------
  18. typedef enum _MSGTYPE
  19. {
  20. MSGTYPE_PRE_WNDPROC, // pre-wndproc override
  21. MSGTYPE_POST_WNDPROC, // post-wndproc override
  22. MSGTYPE_PRE_DEFDLGPROC, // pre-DefDlgProc override
  23. MSGTYPE_POST_DEFDLGPROC,// post-DefDlgProc override
  24. MSGTYPE_DEFWNDPROC, // DefWindowProc hook.
  25. }MSGTYPE;
  26. //---------------------------------------------------------------------------
  27. typedef struct _THEME_MSG
  28. {
  29. HWND hwnd; // message target.
  30. UINT uMsg; // message id.
  31. WPARAM wParam; // message WPARAM
  32. LPARAM lParam; // message LPARAM
  33. MSGTYPE type; // type of message (dwp, sent, posted)
  34. UINT uCodePage; // message codepage. This will invariably be CP_WINUNICODE for
  35. // a message processed via the wide-char defwindowproc, or
  36. // the current user default codepage for messages passed through
  37. // the ansi defwindowproc.
  38. WNDPROC pfnDefProc; // address of function handler should call to do default processing
  39. LRESULT lRet; // Post overrides only: msg result from default handler.
  40. BOOL fHandled; // handler should set this value.
  41. }THEME_MSG, *PTHEME_MSG;
  42. //---------------------------------------------------------------------------
  43. // Message handler prototype
  44. typedef LRESULT (CALLBACK * HOOKEDMSGHANDLER)(CThemeWnd* pwnd, THEME_MSG *ptm );
  45. //---------------------------------------------------------------------------
  46. // Message handler array element
  47. typedef struct _MSGENTRY
  48. {
  49. UINT nMsg; // message identifier (zero if registered message)
  50. UINT *pnRegMsg; // address of registered message var (NULL if stock message)
  51. HOOKEDMSGHANDLER pfnHandler; // primary handler
  52. HOOKEDMSGHANDLER pfnHandler2; // secondary handler (optional for DWP, WH handlers)
  53. } MSGENTRY, *PMSGENTRY;
  54. //---------------------------------------------------------------------------
  55. // Performs default processing on the message
  56. LRESULT WINAPI DoMsgDefault( const THEME_MSG* ptm );
  57. //---------------------------------------------------------------------------
  58. inline void WINAPI MsgHandled( const THEME_MSG *ptm, BOOL fHandled = TRUE ) {
  59. ((PTHEME_MSG)ptm)->fHandled = fHandled;
  60. }
  61. //---------------------------------------------------------------------------
  62. // message mask helpers
  63. #define MAKE_MSGBIT( nMsg ) ((BYTE)(1 << (nMsg & 7)))
  64. #define SET_MSGMASK( prgMsgMask, nMsg ) (prgMsgMask[nMsg/8] |= MAKE_MSGBIT(nMsg))
  65. #define CLEAR_MSGMASK( prgMsgMask, nMsg ) (prgMsgMask[nMsg/8] &= ~MAKE_MSGBIT(nMsg))
  66. #define CHECK_MSGMASK( prgMsgMask, nMsg ) ((prgMsgMask[nMsg/8] & MAKE_MSGBIT(nMsg)) != 0)
  67. //---------------------------------------------------------------------------//
  68. // Message handler table access
  69. extern void HandlerTableInit();
  70. DWORD GetOwpMsgMask( LPBYTE* prgMsgList );
  71. DWORD GetDdpMsgMask( LPBYTE* prgMsgList );
  72. DWORD GetDwpMsgMask( LPBYTE* prgMsgList );
  73. BOOL FindOwpHandler( UINT uMsg,
  74. OUT OPTIONAL HOOKEDMSGHANDLER* ppfnPre,
  75. OUT OPTIONAL HOOKEDMSGHANDLER* ppfnPost );
  76. BOOL FindDdpHandler( UINT uMsg,
  77. OUT OPTIONAL HOOKEDMSGHANDLER* ppfnPre,
  78. OUT OPTIONAL HOOKEDMSGHANDLER* ppfnPost );
  79. BOOL FindDwpHandler( UINT uMsg,
  80. OUT OPTIONAL HOOKEDMSGHANDLER* ppfn );
  81. //---------------------------------------------------------------------------//
  82. // table decl helpers
  83. #define DECL_MSGHANDLER(handler) LRESULT CALLBACK handler(CThemeWnd*, THEME_MSG *)
  84. #define DECL_REGISTERED_MSG(msg) extern UINT msg;
  85. #define BEGIN_HANDLER_TABLE(rgEntries) static MSGENTRY rgEntries[] = {
  86. #define END_HANDLER_TABLE() };
  87. #define DECL_MSGENTRY(msg,pfnPre,pfnPost) {msg, NULL, pfnPre, pfnPost},
  88. //---------------------------------------------------------------------------
  89. // SystemParametersInfo handler support
  90. //---------------------------------------------------------------------------
  91. //---------------------------------------------------------------------------
  92. // SystemParametersInfo handler prototype
  93. typedef BOOL (CALLBACK * SPIHANDLER)(
  94. NCTHEMEMET *pnctm,
  95. IN UINT uiAction, IN UINT uiParam, IN OUT PVOID pvParam, IN UINT fWinIni,
  96. SYSTEMPARAMETERSINFO pfnDefault, BOOL& fHandled );
  97. BOOL FindSpiHandler( IN UINT uiAction, OUT SPIHANDLER* pfnHandler );
  98. //---------------------------------------------------------------------------//
  99. // table decl helpers
  100. #define DECL_SPIHANDLER(handler) BOOL CALLBACK handler(NCTHEMEMET*, UINT, UINT, PVOID, UINT, SYSTEMPARAMETERSINFO, BOOL& )
  101. #define BEGIN_SPIHANDLER_TABLE() BOOL FindSpiHandler( UINT uiAction, SPIHANDLER* pfnHandler ) {\
  102. switch(uiAction){
  103. #define DECL_SPIENTRY(uiAction, handler) case uiAction: {*pfnHandler = handler; return TRUE;}
  104. #define END_SPIHANDLER_TABLE() }return FALSE;}
  105. //---------------------------------------------------------------------------
  106. // GetSystemMetrics handler support
  107. //---------------------------------------------------------------------------
  108. //---------------------------------------------------------------------------
  109. // GetSystemMetrics handler prototype
  110. typedef int (CALLBACK * GSMHANDLER)(
  111. NCTHEMEMET *pnctm, IN int iMetric,
  112. GETSYSTEMMETRICSPROC pfnDefault, BOOL& fHandled );
  113. typedef struct _GSMENTRY {
  114. int iMetric;
  115. GSMHANDLER pfnHandler;
  116. } GSMENTRY;
  117. BOOL FindGsmHandler( IN int iMetric, OUT GSMHANDLER* pfnHandler );
  118. #define DECL_GSMHANDLER(handler) int CALLBACK handler(NCTHEMEMET*, int, GETSYSTEMMETRICSPROC, BOOL& )
  119. #define BEGIN_GSMHANDLER_TABLE(rgEntries) static GSMENTRY rgEntries[] = {
  120. #define END_GSMHANDLER_TABLE() };
  121. #define DECL_GSMENTRY(iMetric, handler) {iMetric, handler},
  122. #endif __HANDLERS_H__