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.

144 lines
3.9 KiB

  1. //
  2. // framewnd.cpp
  3. //
  4. // Implementation of CTscFrameWnd
  5. // Frame window class
  6. //
  7. // Copyright(C) Microsoft Corporation 2000
  8. // Author: Nadim Abdo (nadima)
  9. //
  10. //
  11. #include "stdafx.h"
  12. #define TRC_GROUP TRC_GROUP_UI
  13. #define TRC_FILE "framewnd"
  14. #include <atrcapi.h>
  15. #include "framewnd.h"
  16. CTscFrameWnd::CTscFrameWnd()
  17. {
  18. _hWnd = NULL;
  19. }
  20. CTscFrameWnd::~CTscFrameWnd()
  21. {
  22. }
  23. //
  24. // Create the window
  25. // params:
  26. // hInstance - app instance
  27. // hWndParent - parent window
  28. // szClassName - window class name (will create)
  29. // dwStyle - window style
  30. // returns:
  31. // window handle
  32. //
  33. HWND CTscFrameWnd::CreateWnd(HINSTANCE hInstance,HWND hwndParent,
  34. LPTSTR szClassName, LPTSTR szTitle,
  35. DWORD dwStyle, LPRECT lpInitialRect,
  36. HICON hIcon)
  37. {
  38. BOOL rc = FALSE;
  39. DC_BEGIN_FN("CreateWnd");
  40. TRC_ASSERT(hInstance, (TB, _T("hInstance is null")));
  41. TRC_ASSERT(szClassName, (TB, _T("szClassName is null")));
  42. TRC_ASSERT(lpInitialRect, (TB, _T("lpInitialRect is null")));
  43. if(!hInstance || !szClassName || !lpInitialRect)
  44. {
  45. return NULL;
  46. }
  47. TRC_ASSERT(!_hWnd, (TB,_T("Double create window. Could be leaking!!!")));
  48. _hInstance = hInstance;
  49. #ifndef OS_WINCE
  50. WNDCLASSEX wndclass;
  51. wndclass.cbSize = sizeof (wndclass);
  52. #else //OS_WINCE
  53. WNDCLASS wndclass;
  54. #endif
  55. wndclass.style = 0;
  56. wndclass.lpfnWndProc = CTscFrameWnd::StaticTscFrameWndProc;
  57. wndclass.cbClsExtra = 0;
  58. wndclass.cbWndExtra = 0;
  59. wndclass.hInstance = hInstance;
  60. wndclass.hIcon = hIcon;
  61. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  62. wndclass.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH);
  63. wndclass.lpszMenuName = NULL;
  64. wndclass.lpszClassName = szClassName;
  65. #ifndef OS_WINCE
  66. wndclass.hIconSm = NULL;
  67. #endif
  68. #ifndef OS_WINCE
  69. if ((0 == RegisterClassEx(&wndclass)) &&
  70. #else
  71. if ((0 == RegisterClass(&wndclass)) &&
  72. #endif
  73. (ERROR_CLASS_ALREADY_EXISTS != GetLastError()))
  74. {
  75. TRC_ERR((TB,_T("RegisterClassEx failed: %d"),GetLastError()));
  76. return NULL;
  77. }
  78. _hWnd = CreateWindow(szClassName,
  79. szTitle,
  80. dwStyle,
  81. 0,
  82. 0,
  83. lpInitialRect->right - lpInitialRect->left,
  84. lpInitialRect->bottom - lpInitialRect->top,
  85. hwndParent,
  86. NULL,
  87. hInstance,
  88. this);
  89. if(_hWnd)
  90. {
  91. // put a reference to the current object into the hwnd
  92. // so we can access the object from the WndProc
  93. SetLastError(0);
  94. if(!SetWindowLongPtr(_hWnd, GWLP_USERDATA, (LONG_PTR)this))
  95. {
  96. if(GetLastError())
  97. {
  98. TRC_ERR((TB,_T("SetWindowLongPtr failed 0x%x"),
  99. GetLastError()));
  100. return NULL;
  101. }
  102. }
  103. }
  104. else
  105. {
  106. TRC_ERR((TB,_T("CreateWindow failed 0x%x"), GetLastError()));
  107. return NULL;
  108. }
  109. DC_END_FN();
  110. return _hWnd;
  111. }
  112. LRESULT CALLBACK CTscFrameWnd::StaticTscFrameWndProc(HWND hwnd,
  113. UINT uMsg,
  114. WPARAM wParam,
  115. LPARAM lParam)
  116. {
  117. DC_BEGIN_FN("StaticTscFrameWndProc");
  118. // pull out the pointer to the container object associated with this hwnd
  119. CTscFrameWnd *pwnd = (CTscFrameWnd *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  120. if(pwnd)
  121. {
  122. return pwnd->WndProc( hwnd, uMsg, wParam, lParam);
  123. }
  124. else
  125. {
  126. return DefWindowProc (hwnd, uMsg, wParam, lParam);
  127. }
  128. DC_END_FN();
  129. }