Subclass.h 3.1 KB

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