Subclass.h
上传用户:sunh8215
上传日期:2010-02-13
资源大小:1616k
文件大小:2k
源码类别:

酒店行业

开发平台:

Visual C++

  1. ////////////////////////////////////////////////////////////////
  2. // VCKBASE -- August 2000
  3. // Compiles with Visual C++ 6.0, runs on Windows 98 and probably NT too.
  4. //
  5. #ifndef _SUBCLASSW_H
  6. #define _SUBCLASSW_H
  7. //////////////////
  8. // Generic class to hook messages on behalf of a CWnd.
  9. // Once hooked, all messages go to CSubclassWnd::WindowProc before going
  10. // to the window. Specific subclasses can trap messages and do something.
  11. //
  12. // To use:
  13. //
  14. // * Derive a class from CSubclassWnd.
  15. //
  16. // * Override CSubclassWnd::WindowProc to handle messages. Make sure you call
  17. //   CSubclassWnd::WindowProc if you don't handle the message, or your
  18. //   window will never get messages. If you write seperate message handlers,
  19. //   you can call Default() to pass the message to the window.
  20. //
  21. // * Instantiate your derived class somewhere and call HookWindow(pWnd)
  22. //   to hook your window, AFTER it has been created.
  23. //   To unhook, call Unhook or HookWindow(NULL).
  24. //
  25. // This is a very important class, crucial to many of the widgets Window
  26. // widgets implemented in PixieLib. To see how it works, look at the HOOK
  27. // sample program.
  28. //
  29. class CSubclassWnd : public CObject {
  30. public:
  31. CSubclassWnd();
  32. ~CSubclassWnd();
  33. // Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY)
  34. BOOL HookWindow(HWND  hwnd);
  35. BOOL HookWindow(CWnd* pWnd) { return HookWindow(pWnd->GetSafeHwnd()); }
  36. void Unhook() { HookWindow((HWND)NULL); }
  37. BOOL IsHooked() { return m_hWnd!=NULL; }
  38. friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM);
  39. friend class CSubclassWndMap;
  40. virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
  41. LRESULT Default(); // call this at the end of handler fns
  42. #ifdef _DEBUG
  43. virtual void AssertValid() const;
  44. virtual void Dump(CDumpContext& dc) const;
  45. #endif
  46. protected:
  47. HWND m_hWnd; // the window hooked
  48. WNDPROC m_pOldWndProc; // ..and original window proc
  49. CSubclassWnd* m_pNext; // next in chain of hooks for this window
  50. DECLARE_DYNAMIC(CSubclassWnd);
  51. };
  52. #endif // _SUBCLASSW_H