Subclass.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /************************************************************************/
  2. /* Copyright (C), 2016-2020, [IT], 保留所有权利;
  3. /* 模 块 名:;
  4. /* 描 述:;
  5. /*
  6. /* 版 本:[V];
  7. /* 作 者:[IT];
  8. /* 日 期:[8/19/2016];
  9. /*
  10. /*
  11. /* 注 意:;
  12. /*
  13. /* 修改记录:[IT];
  14. /* 修改日期:;
  15. /* 修改版本:;
  16. /* 修改内容:;
  17. /************************************************************************/
  18. #ifndef _SUBCLASSW_H
  19. #define _SUBCLASSW_H
  20. ////////////////////////////////////////////////////////////////
  21. // Copyright 1998 Paul DiLascia
  22. // If this code works, it was written by Paul DiLascia.
  23. // If not, I don't know who wrote it.
  24. //
  25. /////////////////////////////////////////////////////////////////////////////
  26. /****************************************************************************
  27. *
  28. * $Date: 10/26/99 10:50p $
  29. * $Revision: 4 $
  30. * $Archive: /CodeJock/Include/Subclass.h $
  31. *
  32. * $History: Subclass.h $
  33. *
  34. * ***************** Version 4 *****************
  35. * User: Kirk Stowell Date: 10/26/99 Time: 10:50p
  36. * Updated in $/CodeJock/Include
  37. * Made class methods virtual for inheritance purposes.
  38. *
  39. * ***************** Version 3 *****************
  40. * User: Kirk Stowell Date: 10/14/99 Time: 12:41p
  41. * Updated in $/CodeJock/Include
  42. * Added source control history to file header.
  43. *
  44. ***************************************************************************/
  45. /////////////////////////////////////////////////////////////////////////////
  46. //////////////////
  47. // Generic class to hook messages on behalf of a CWnd.
  48. // Once hooked, all messages go to CSubclassWnd::WindowProc before going
  49. // to the window. Specific subclasses can trap messages and do something.
  50. //
  51. // To use:
  52. //
  53. // * Derive a class from CSubclassWnd.
  54. //
  55. // * Override CSubclassWnd::WindowProc to handle messages. Make sure you call
  56. // CSubclassWnd::WindowProc if you don't handle the message, or your
  57. // window will never get messages. If you write seperate message handlers,
  58. // you can call Default() to pass the message to the window.
  59. //
  60. // * Instantiate your derived class somewhere and call HookWindow(pWnd)
  61. // to hook your window, AFTER it has been created.
  62. // To unhook, call HookWindow(NULL).
  63. //
  64. // This is a very important class, crucial to many of the widgets Window
  65. // widgets implemented in PixieLib. To see how it works, look at the HOOK
  66. // sample program.
  67. //
  68. class CSubclassWnd : public CObject {
  69. public:
  70. DECLARE_DYNAMIC(CSubclassWnd);
  71. CSubclassWnd();
  72. ~CSubclassWnd();
  73. // Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY)
  74. virtual BOOL HookWindow(HWND hwnd);
  75. virtual BOOL HookWindow(CWnd* pWnd) { return HookWindow(pWnd->GetSafeHwnd()); }
  76. virtual BOOL IsHooked() { return m_hWnd!=NULL; }
  77. friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM);
  78. friend class CSubclassWndMap;
  79. #ifdef _DEBUG
  80. virtual void AssertValid() const;
  81. virtual void Dump(CDumpContext& dc) const;
  82. #endif
  83. protected:
  84. HWND m_hWnd; // the window hooked
  85. WNDPROC m_pOldWndProc; // ..and original window proc
  86. CSubclassWnd* m_pNext; // next in chain of hooks for this window
  87. // Override this to handle messages in specific handlers
  88. virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
  89. virtual LRESULT Default(); // call this at the end of handler fns
  90. };
  91. #endif // _SUBCLASSW_H