home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / DEMOT.ZIP / Src / Include / Subclass.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-23  |  2.0 KB  |  62 lines

  1. ////////////////////////////////////////////////////////////////
  2. // 1997 Microsoft Sytems Journal
  3. // If this code works, it was written by Paul DiLascia.
  4. // If not, I don't know who wrote it.
  5. //
  6.  
  7. #if !defined(SUBCLASS_H_INCLUDED)
  8. #define SUBCLASS_H_INCLUDED
  9.  
  10. #if _MSC_VER >= 1000
  11. #pragma once
  12. #endif // _MSC_VER >= 1000
  13.  
  14. //////////////////
  15. // Generic class to hook messages on behalf of a CWnd.
  16. // Once hooked, all messages go to CSubclassWnd::WindowProc before going
  17. // to the window. Specific subclasses can trap messages and do something.
  18. //
  19. // To use:
  20. //
  21. // * Derive a class from CSubclassWnd.
  22. //
  23. // * Override CSubclassWnd::WindowProc to handle messages. Make sure you call
  24. //   CSubclassWnd::WindowProc if you don't handle the message, or your
  25. //   window will never get messages. If you write seperate message handlers,
  26. //   you can call Default() to pass the message to the window.
  27. //
  28. // * Instantiate your derived class somewhere and call HookWindow(pWnd)
  29. //   to hook your window, AFTER it has been created.
  30. //      To unhook, call HookWindow(NULL).
  31. //
  32. // This is a very important class, crucial to many of the widgets Window
  33. // widgets implemented in PixieLib. To see how it works, look at the HOOK
  34. // sample program.
  35. //
  36.  
  37. class CLASS_EXPORT CSubclassWnd : public CObject {
  38. public:
  39.     DECLARE_DYNAMIC(CSubclassWnd);
  40.     CSubclassWnd();
  41.     ~CSubclassWnd();
  42.  
  43.     // Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY)
  44.     BOOL    HookWindow(CWnd* pRealWnd);
  45.     BOOL    IsHooked()            { return m_pWndHooked!=NULL; }
  46.  
  47.     friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM);
  48.     friend class CSubclassWndMap;
  49.  
  50. protected:
  51.     CWnd*                m_pWndHooked;        // the window hooked
  52.     WNDPROC            m_pOldWndProc;        // ..and original window proc
  53.     CSubclassWnd*    m_pNext;                // next in chain of hooks for this window
  54.  
  55.     // Override this to handle messages in specific handlers
  56.     virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
  57.     LRESULT Default();                // call this at the end of handler fns
  58. };
  59.  
  60. #endif // SUBCLASS_H_INCLUDED
  61.  
  62.