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.

115 lines
3.8 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1999
  5. *
  6. * File: AxHostWindow2.h
  7. *
  8. * Contents: Header file for CAxWindowT2. Refer to MSJ, December 1999.
  9. *
  10. * History: 30-Nov-99 VivekJ Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #pragma once
  14. #ifndef __AXWIN2_H__
  15. #define __AXWIN2_H__
  16. template <typename TBase = CWindow>
  17. class CAxWindowT2 : public CAxWindowT<TBase>
  18. {
  19. public:
  20. CAxWindowT2(HWND hwnd = 0) : CAxWindowT<TBase>(hwnd) {}
  21. HRESULT CreateControl(LPCOLESTR lpszName, IStream* pStream = NULL, IUnknown** ppUnkContainer = NULL)
  22. {
  23. return CreateControlEx(lpszName, pStream, ppUnkContainer);
  24. }
  25. HRESULT CreateControl(DWORD dwResID, IStream* pStream = NULL, IUnknown** ppUnkContainer = NULL)
  26. {
  27. return CreateControlEx(dwResID, pStream, ppUnkContainer);
  28. }
  29. HRESULT CreateControlEx(DWORD dwResID, IStream* pStream = NULL,
  30. IUnknown** ppUnkContainer = NULL, IUnknown** ppUnkControl = NULL,
  31. REFIID iidSink = IID_NULL, IUnknown* punkSink = NULL)
  32. {
  33. DECLARE_SC(sc, TEXT("CreateControlEx"));
  34. TCHAR szModule[_MAX_PATH];
  35. if(0 == GetModuleFileName(_Module.GetModuleInstance(), szModule, _MAX_PATH))
  36. {
  37. ASSERT(FALSE);
  38. return ((sc = E_FAIL).ToHr());
  39. }
  40. CComBSTR bstrURL(OLESTR("res://"));
  41. bstrURL.Append(szModule);
  42. bstrURL.Append(OLESTR("/"));
  43. TCHAR szResID[11];
  44. sc = StringCchPrintf(szResID, countof(szResID), _T("%0d"), dwResID);
  45. if(sc)
  46. return ((sc = E_FAIL).ToHr());
  47. bstrURL.Append(szResID);
  48. return CreateControlEx(bstrURL, pStream, ppUnkContainer, ppUnkControl, iidSink, punkSink);
  49. }
  50. HRESULT CreateControlEx(LPCOLESTR lpszName, IStream* pStream = NULL,
  51. IUnknown** ppUnkContainer = NULL, IUnknown** ppUnkControl = NULL,
  52. REFIID iidSink = IID_NULL, IUnknown* punkSink = NULL)
  53. {
  54. ATLASSERT(::IsWindow(m_hWnd));
  55. HRESULT hr = E_FAIL;
  56. CComPtr<IAxWinHostWindow> spAxWindow;
  57. // Reuse existing CAxHostWindow
  58. hr = QueryHost(&spAxWindow);
  59. if( SUCCEEDED(hr) )
  60. {
  61. CComPtr<IUnknown> spunkControl;
  62. hr = spAxWindow->CreateControlEx(lpszName, m_hWnd, pStream, &spunkControl, iidSink, punkSink);
  63. if( FAILED(hr) ) return hr;
  64. if( ppUnkControl ) (*ppUnkControl = spunkControl)->AddRef();
  65. if( ppUnkContainer ) (*ppUnkContainer = spAxWindow)->AddRef();
  66. }
  67. // Create a new CAxHostWindow
  68. else
  69. {
  70. return AtlAxCreateControlEx(lpszName, m_hWnd, pStream, ppUnkContainer, ppUnkControl, iidSink, punkSink);
  71. }
  72. return S_OK;
  73. }
  74. HRESULT AttachControl(IUnknown* pControl, IUnknown** ppUnkContainer = 0)
  75. {
  76. ATLASSERT(::IsWindow(m_hWnd));
  77. HRESULT hr = E_FAIL;
  78. CComPtr<IAxWinHostWindow> spAxWindow;
  79. // Reuse existing CAxHostWindow
  80. hr = QueryHost(&spAxWindow);
  81. if( SUCCEEDED(hr) )
  82. {
  83. hr = spAxWindow->AttachControl(pControl, m_hWnd);
  84. if( FAILED(hr) ) return hr;
  85. if( ppUnkContainer ) (*ppUnkContainer = spAxWindow)->AddRef();
  86. }
  87. // Create a new CAxHostWindow
  88. else
  89. {
  90. return AtlAxAttachControl(pControl, m_hWnd, ppUnkContainer);
  91. }
  92. return S_OK;
  93. }
  94. };
  95. typedef CAxWindowT2<CWindow> CAxWindow2;
  96. #endif // __AXWIN2_H__