Leaked source code of windows server 2003
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.

107 lines
2.5 KiB

  1. // Copyright (c) 2000 Microsoft Corporation
  2. //
  3. // windows control subclassing wrapper
  4. //
  5. // 22 Nov 2000 sburns
  6. #ifndef CONTROLSUBCLASSER_HPP_INCLUDED
  7. #define CONTROLSUBCLASSER_HPP_INCLUDED
  8. // Class for hooking the window proc of a control.
  9. class ControlSubclasser
  10. {
  11. protected:
  12. ControlSubclasser();
  13. // reverses the subclassing by calling UnhookWindowProc.
  14. virtual
  15. ~ControlSubclasser();
  16. // Hooks the window proc of the supplied window so that all future messages
  17. // are routed to the OnMessage method. The OnInit of the parent dialog
  18. // where the control resides is a good place to call this method.
  19. //
  20. // The hook requires that that the GWLP_USERDATA portion of the window
  21. // be overwritten with the this pointer to this instance. If you need
  22. // that data, then you could derive a class from this one, and add
  23. // members for your extra data.
  24. //
  25. // Your overrided Init method must call this base method.
  26. //
  27. // control - in, handle to the control to be hooked.
  28. virtual
  29. HRESULT
  30. Init(HWND editControl);
  31. // Invoked upon receipt of any window message. The default implementation
  32. // calls the control's original window procedure. When you derive a new
  33. // class from this one, be sure to call this base class method from your
  34. // derived method for any messages your derived method doesn't handle.
  35. //
  36. // message - in, the message code passed to the dialog window.
  37. //
  38. // wparam - in, the WPARAM parameter accompanying the message.
  39. //
  40. // lparam - in, the LPARAM parameter accompanying the message.
  41. virtual
  42. LRESULT
  43. OnMessage(
  44. UINT message,
  45. WPARAM wparam,
  46. LPARAM lparam);
  47. // the handle to the subclassed control. Only valid after Init has
  48. // been called.
  49. HWND hwnd;
  50. private:
  51. // restore the original window proc to the window
  52. void
  53. UnhookWindowProc();
  54. // a static Windows Proc that acts as a dispatcher to the non-static
  55. // OnMessage method.
  56. static
  57. LRESULT CALLBACK
  58. WindowProc(
  59. HWND window,
  60. UINT message,
  61. WPARAM wParam,
  62. LPARAM lParam);
  63. // not implemented: no copying allowed
  64. ControlSubclasser(const ControlSubclasser&);
  65. const ControlSubclasser& operator=(const ControlSubclasser&);
  66. WNDPROC originalWindowProc;
  67. };
  68. #endif // CONTROLSUBCLASSER_HPP_INCLUDED