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.

89 lines
1.5 KiB

  1. //
  2. // CWnd.cpp
  3. //
  4. // A super-simple window wrapper implementation.
  5. //
  6. // History:
  7. //
  8. // 10/07/1999 KenSh Created
  9. //
  10. #include "stdafx.h"
  11. #include "CWnd.h"
  12. CWnd::CWnd()
  13. {
  14. m_hWnd = NULL;
  15. m_pfnPrevWindowProc = NULL;
  16. m_cRef = 1;
  17. }
  18. CWnd::~CWnd()
  19. {
  20. }
  21. BOOL CWnd::Attach(HWND hwnd)
  22. {
  23. m_hWnd = hwnd;
  24. SetPropA(hwnd, "CWnd*", (HANDLE)this);
  25. m_pfnPrevWindowProc = SubclassWindow(hwnd, StaticWindowProc);
  26. m_cRef++;
  27. return TRUE;
  28. }
  29. void CWnd::Release()
  30. {
  31. m_cRef--;
  32. if (0==m_cRef)
  33. delete this;
  34. }
  35. // Can NOT cache the return value from this function
  36. CWnd* CWnd::FromHandle(HWND hwnd)
  37. {
  38. return (CWnd*)GetPropA(hwnd, "CWnd*");
  39. }
  40. LRESULT CWnd::Default(UINT message, WPARAM wParam, LPARAM lParam)
  41. {
  42. return CallWindowProc(m_pfnPrevWindowProc, m_hWnd, message, wParam, lParam );
  43. }
  44. LRESULT CALLBACK CWnd::StaticWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  45. {
  46. LRESULT lResult;
  47. CWnd* pWnd = FromHandle(hwnd);
  48. if (pWnd)
  49. {
  50. lResult = pWnd->WindowProc(message, wParam, lParam);
  51. if (message == WM_NCDESTROY)
  52. {
  53. RemovePropA(hwnd, "CWnd*");
  54. pWnd->OnNCDESTROY();
  55. }
  56. }
  57. else
  58. {
  59. lResult = DefWindowProc(hwnd, message, wParam, lParam);
  60. }
  61. return lResult;
  62. }
  63. void CWnd::OnNCDESTROY()
  64. {
  65. SubclassWindow(m_hWnd, m_pfnPrevWindowProc);
  66. m_hWnd = NULL;
  67. m_pfnPrevWindowProc = NULL;
  68. Release();
  69. }