Source code of Windows XP (NT5)
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.

144 lines
4.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: cwindow.cxx
  7. //
  8. // Contents: implementation for a window class
  9. //
  10. // Classes: CHlprWindow
  11. //
  12. // Functions: WindowProc
  13. //
  14. // History: 4-12-94 stevebl Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "cwindow.h"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Member: CHlprWindow::Create
  21. //
  22. // Synopsis: Special version of CreateWindow.
  23. //
  24. // Arguments: [lpszClassName] - address of registered class name
  25. // [lpszWindowName] - address of window name
  26. // [dwStyle] - window style
  27. // [x] - horizontal position of window
  28. // [y] - vertical position of window
  29. // [nWidth] - window width
  30. // [nHeight] - window height
  31. // [hwndParent] - handle of parent or owner window
  32. // [hmenu] - handle of menu, or child window identifier
  33. // [hinst] - handle of application instance
  34. //
  35. // Returns: HWND of the created window
  36. //
  37. // Modifies: _hwnd, _hInstance
  38. //
  39. // History: 4-12-94 stevebl Created
  40. //
  41. // Notes: The window class must have been previously registered (as
  42. // is normal Windows procedure) and the callback function
  43. // must have been registered as ::WindowProc. ::WindowProc will
  44. // then forward all messages on to the CHlprWindow::WindowProc
  45. // method, allowing the window to directly access class members
  46. // (i.e. giving the WindowProc access to the "this" pointer).
  47. //
  48. //----------------------------------------------------------------------------
  49. HWND CHlprWindow::Create(
  50. LPCTSTR lpszClassName,
  51. LPCTSTR lpszWindowName,
  52. DWORD dwStyle,
  53. int x,
  54. int y,
  55. int nWidth,
  56. int nHeight,
  57. HWND hwndParent,
  58. HMENU hmenu,
  59. HINSTANCE hinst)
  60. {
  61. _hInstance = hinst;
  62. return(_hwnd =
  63. CreateWindow(
  64. lpszClassName,
  65. lpszWindowName,
  66. dwStyle,
  67. x,
  68. y,
  69. nWidth,
  70. nHeight,
  71. hwndParent,
  72. hmenu,
  73. hinst,
  74. this));
  75. }
  76. //+---------------------------------------------------------------------------
  77. //
  78. // Function: WindowProc
  79. //
  80. // Synopsis: Standard WindowProc that forwards Windows messages on to the
  81. // CHlprWindow::WindowProc method.
  82. //
  83. // Arguments: [hwnd] - window handle
  84. // [uMsg] - message
  85. // [wParam] - first message parameter
  86. // [lParam] - second message parameter
  87. //
  88. // History: 4-12-94 stevebl Created
  89. //
  90. // Notes: This Window procedure expects that it will receive a "this"
  91. // pointer as the lpCreateParams member passed as part of the
  92. // WM_CREATE message. It saves the "this" pointer in the
  93. // GWL_USERDATA field of the window structure.
  94. //
  95. //----------------------------------------------------------------------------
  96. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  97. {
  98. CHlprWindow * pw;
  99. switch (uMsg)
  100. {
  101. case WM_CREATE:
  102. // Since this is the first time that we can get ahold of
  103. // a pointer to the window class object, all messages that might
  104. // have been sent before this are never seen by the Windows object
  105. // and only get passed on to te DefWindowProc
  106. // get a pointer to the window class object
  107. pw = (CHlprWindow *) ((CREATESTRUCT *)lParam)->lpCreateParams;
  108. // set its USERDATA DWORD to point to the class object
  109. SetWindowLong(hwnd, GWL_USERDATA, (long) pw);
  110. // Set it's protected _hwnd member variable to ensure that
  111. // member functions have access to the correct window handle.
  112. pw->_hwnd = hwnd;
  113. break;
  114. case WM_DESTROY:
  115. // This is our signal to destroy the window class object.
  116. pw = (CHlprWindow *) GetWindowLong(hwnd, GWL_USERDATA);
  117. SetWindowLong(hwnd, GWL_USERDATA, 0);
  118. delete pw;
  119. pw = (CHlprWindow *) 0;
  120. break;
  121. default:
  122. // get a pointer to the window class object
  123. pw = (CHlprWindow *) GetWindowLong(hwnd, GWL_USERDATA);
  124. break;
  125. }
  126. // and call its message proc method
  127. if (pw != (CHlprWindow *) 0)
  128. {
  129. return(pw->WindowProc(uMsg, wParam, lParam));
  130. }
  131. else
  132. {
  133. return(DefWindowProc(hwnd, uMsg, wParam, lParam));
  134. }
  135. }