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.

123 lines
4.5 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1999
  5. *
  6. * File: SiteBase.h
  7. *
  8. * Contents: Header file for CAxWindowImplT. Refer to MSJ, December 1999.
  9. *
  10. * History: 30-Nov-99 VivekJ Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #pragma once
  14. #ifndef __SITEBASE_H_
  15. #define __SITEBASE_H_
  16. //------------------------------------------------------------------------------------------------------------------
  17. //
  18. //
  19. //
  20. #include "AxWin2.H"
  21. template <typename TDerived, typename TWindow = CAxWindow2>
  22. class CAxWindowImplT : public CWindowImplBaseT< TWindow >
  23. {
  24. public:
  25. typedef CAxWindowImplT<TWindow> thisClass;
  26. public:
  27. BEGIN_MSG_MAP(thisClass)
  28. MESSAGE_HANDLER(WM_CREATE,OnCreate)
  29. MESSAGE_HANDLER(WM_NCDESTROY,OnNCDestroy)
  30. END_MSG_MAP()
  31. //
  32. DECLARE_WND_SUPERCLASS(_T("AtlAxWinEx"),CAxWindow::GetWndClassName())
  33. HWND Create(HWND hWndParent, RECT& rcPos, LPCTSTR szWindowName = NULL,
  34. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  35. UINT nID = 0, LPVOID lpCreateParam = NULL)
  36. {
  37. if (GetWndClassInfo().m_lpszOrigName == NULL)
  38. GetWndClassInfo().m_lpszOrigName = GetWndClassName();
  39. ATOM atom = GetWndClassInfo().Register(&m_pfnSuperWindowProc);
  40. dwStyle = GetWndStyle(dwStyle);
  41. dwExStyle = GetWndExStyle(dwExStyle);
  42. return CWindowImplBaseT<TWindow>::Create(hWndParent, rcPos, szWindowName,dwStyle, dwExStyle, nID,atom, lpCreateParam);
  43. }
  44. HRESULT AxCreateControl2(LPCOLESTR lpszName, HWND hWnd, IStream* pStream, IUnknown** ppUnkContainer, IUnknown** ppUnkControl = 0, REFIID iidSink = IID_NULL, IUnknown* punkSink = 0)
  45. {
  46. return AtlAxCreateControlEx(lpszName, hWnd, pStream,ppUnkContainer,ppUnkControl,iidSink,punkSink);
  47. }
  48. public:
  49. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  50. {
  51. ::OleInitialize(NULL);
  52. CREATESTRUCT* lpCreate = (CREATESTRUCT*)lParam;
  53. int nLen = ::GetWindowTextLength(m_hWnd);
  54. LPTSTR lpstrName = (LPTSTR)_alloca((nLen + 1) * sizeof(TCHAR));
  55. ::GetWindowText(m_hWnd, lpstrName, nLen + 1);
  56. ::SetWindowText(m_hWnd, _T(""));
  57. IAxWinHostWindow* pAxWindow = NULL;
  58. int nCreateSize = 0;
  59. if (lpCreate && lpCreate->lpCreateParams)
  60. nCreateSize = *((WORD*)lpCreate->lpCreateParams);
  61. HGLOBAL h = GlobalAlloc(GHND, nCreateSize);
  62. CComPtr<IStream> spStream;
  63. if (h && nCreateSize)
  64. {
  65. BYTE* pBytes = (BYTE*) GlobalLock(h);
  66. BYTE* pSource = ((BYTE*)(lpCreate->lpCreateParams)) + sizeof(WORD);
  67. //Align to DWORD
  68. //pSource += (((~((DWORD)pSource)) + 1) & 3);
  69. memcpy(pBytes, pSource, nCreateSize);
  70. GlobalUnlock(h);
  71. CreateStreamOnHGlobal(h, TRUE, &spStream);
  72. }
  73. USES_CONVERSION;
  74. CComPtr<IUnknown> spUnk;
  75. TDerived* pT = static_cast<TDerived*>(this);
  76. HRESULT hRet = pT->AxCreateControl2(T2COLE(lpstrName), m_hWnd, spStream, &spUnk);
  77. if(FAILED(hRet))
  78. return -1; // abort window creation
  79. hRet = spUnk->QueryInterface(IID_IAxWinHostWindow, (void**)&pAxWindow);
  80. if(FAILED(hRet))
  81. return -1; // abort window creation
  82. ::SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (DWORD_PTR)pAxWindow);
  83. // check for control parent style if control has a window
  84. HWND hWndChild = ::GetWindow(m_hWnd, GW_CHILD);
  85. if(hWndChild != NULL)
  86. {
  87. if(::GetWindowLong(hWndChild, GWL_EXSTYLE) & WS_EX_CONTROLPARENT)
  88. {
  89. DWORD dwExStyle = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);
  90. dwExStyle |= WS_EX_CONTROLPARENT;
  91. ::SetWindowLong(m_hWnd, GWL_EXSTYLE, dwExStyle);
  92. }
  93. }
  94. bHandled = TRUE;
  95. return 0L;
  96. }
  97. LRESULT OnNCDestroy(UINT , WPARAM , LPARAM , BOOL& bHandled)
  98. {
  99. IAxWinHostWindow* pAxWindow = (IAxWinHostWindow*)::GetWindowLongPtr(m_hWnd, GWLP_USERDATA);
  100. if(pAxWindow != NULL)
  101. pAxWindow->Release();
  102. OleUninitialize();
  103. m_hWnd = 0;
  104. bHandled = TRUE;
  105. return 0L;
  106. }
  107. };
  108. //-----------------------------------------------------------------------------------------------------------------
  109. #endif