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.

107 lines
3.4 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. TCHAR szModule[_MAX_PATH];
  34. GetModuleFileName(_Module.GetModuleInstance(), szModule, _MAX_PATH);
  35. CComBSTR bstrURL(OLESTR("res://"));
  36. bstrURL.Append(szModule);
  37. bstrURL.Append(OLESTR("/"));
  38. TCHAR szResID[11];
  39. wsprintf(szResID, _T("%0d"), dwResID);
  40. bstrURL.Append(szResID);
  41. return CreateControlEx(bstrURL, pStream, ppUnkContainer, ppUnkControl, iidSink, punkSink);
  42. }
  43. HRESULT CreateControlEx(LPCOLESTR lpszName, IStream* pStream = NULL,
  44. IUnknown** ppUnkContainer = NULL, IUnknown** ppUnkControl = NULL,
  45. REFIID iidSink = IID_NULL, IUnknown* punkSink = NULL)
  46. {
  47. ATLASSERT(::IsWindow(m_hWnd));
  48. HRESULT hr = E_FAIL;
  49. CComPtr<IAxWinHostWindow> spAxWindow;
  50. // Reuse existing CAxHostWindow
  51. hr = QueryHost(&spAxWindow);
  52. if( SUCCEEDED(hr) )
  53. {
  54. CComPtr<IUnknown> spunkControl;
  55. hr = spAxWindow->CreateControlEx(lpszName, m_hWnd, pStream, &spunkControl, iidSink, punkSink);
  56. if( FAILED(hr) ) return hr;
  57. if( ppUnkControl ) (*ppUnkControl = spunkControl)->AddRef();
  58. if( ppUnkContainer ) (*ppUnkContainer = spAxWindow)->AddRef();
  59. }
  60. // Create a new CAxHostWindow
  61. else
  62. {
  63. return AtlAxCreateControlEx(lpszName, m_hWnd, pStream, ppUnkContainer, ppUnkControl, iidSink, punkSink);
  64. }
  65. return S_OK;
  66. }
  67. HRESULT AttachControl(IUnknown* pControl, IUnknown** ppUnkContainer = 0)
  68. {
  69. ATLASSERT(::IsWindow(m_hWnd));
  70. HRESULT hr = E_FAIL;
  71. CComPtr<IAxWinHostWindow> spAxWindow;
  72. // Reuse existing CAxHostWindow
  73. hr = QueryHost(&spAxWindow);
  74. if( SUCCEEDED(hr) )
  75. {
  76. hr = spAxWindow->AttachControl(pControl, m_hWnd);
  77. if( FAILED(hr) ) return hr;
  78. if( ppUnkContainer ) (*ppUnkContainer = spAxWindow)->AddRef();
  79. }
  80. // Create a new CAxHostWindow
  81. else
  82. {
  83. return AtlAxAttachControl(pControl, m_hWnd, ppUnkContainer);
  84. }
  85. return S_OK;
  86. }
  87. };
  88. typedef CAxWindowT2<CWindow> CAxWindow2;
  89. #endif // __AXWIN2_H__