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.7 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 000
  5. *
  6. * File: mmcaxwin.inl
  7. *
  8. * Contents: Inline functions for CMMCAxWindow
  9. *
  10. * History: 10-Jan-2000 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #pragma once
  14. #ifndef MMCAXWIN_INL_INCLUDED
  15. #define MMCAXWIN_INL_INCLUDED
  16. #ifdef HACK_CAN_WINDOWLESS_ACTIVATE
  17. /*+-------------------------------------------------------------------------*
  18. * MMCAxCreateControlEx
  19. *
  20. * Lifted straight from AtlAxCreateControlEx in atl30.h. The only
  21. * difference is that it creates a CMMCAxHostWindow rather than a
  22. * CAxHostWindow.
  23. *--------------------------------------------------------------------------*/
  24. inline HRESULT MMCAxCreateControlEx(LPCOLESTR lpszName, HWND hWnd, IStream* pStream,
  25. IUnknown** ppUnkContainer, IUnknown** ppUnkControl, REFIID iidSink, IUnknown* punkSink)
  26. {
  27. AtlAxWinInit();
  28. HRESULT hr;
  29. CComPtr<IUnknown> spUnkContainer;
  30. CComPtr<IUnknown> spUnkControl;
  31. // hr = CAxHostWindow::_CreatorClass::CreateInstance(NULL, IID_IUnknown, (void**)&spUnkContainer);
  32. hr = CMMCAxHostWindow::_CreatorClass::CreateInstance(NULL, IID_IUnknown, (void**)&spUnkContainer);
  33. if (SUCCEEDED(hr))
  34. {
  35. CComPtr<IAxWinHostWindow> pAxWindow;
  36. spUnkContainer->QueryInterface(IID_IAxWinHostWindow, (void**)&pAxWindow);
  37. CComBSTR bstrName(lpszName);
  38. hr = pAxWindow->CreateControlEx(bstrName, hWnd, pStream, &spUnkControl, iidSink, punkSink);
  39. }
  40. if (ppUnkContainer != NULL)
  41. {
  42. if (SUCCEEDED(hr))
  43. {
  44. *ppUnkContainer = spUnkContainer.p;
  45. spUnkContainer.p = NULL;
  46. }
  47. else
  48. *ppUnkContainer = NULL;
  49. }
  50. if (ppUnkControl != NULL)
  51. {
  52. if (SUCCEEDED(hr))
  53. {
  54. *ppUnkControl = SUCCEEDED(hr) ? spUnkControl.p : NULL;
  55. spUnkControl.p = NULL;
  56. }
  57. else
  58. *ppUnkControl = NULL;
  59. }
  60. return hr;
  61. }
  62. /*+-------------------------------------------------------------------------*
  63. * CMMCAxWindow::AxCreateControl2
  64. *
  65. * Simple override of CAxWindowImplT::AxCreateControl2 that calls
  66. * MMCAxCreateControlEx rather than AtlAxCreateControlEx
  67. *--------------------------------------------------------------------------*/
  68. inline HRESULT CMMCAxWindow::AxCreateControl2(LPCOLESTR lpszName, HWND hWnd, IStream* pStream, IUnknown** ppUnkContainer, IUnknown** ppUnkControl, REFIID iidSink, IUnknown* punkSink)
  69. {
  70. return MMCAxCreateControlEx(lpszName, hWnd, pStream,ppUnkContainer,ppUnkControl,iidSink,punkSink);
  71. }
  72. #endif /* HACK_CAN_WINDOWLESS_ACTIVATE */
  73. /*+-------------------------------------------------------------------------*
  74. * CMMCAxWindow::SetFocus
  75. *
  76. * Simple override of CAxWindow::SetFocus that handles more special cases
  77. * NOTE: this is not a virtual method. Invoking on base class pointer will
  78. * endup in executing other method.
  79. *--------------------------------------------------------------------------*/
  80. inline HWND CMMCAxWindow::SetFocus()
  81. {
  82. DECLARE_SC(sc, TEXT("CMMCAxWindow::SetFocus"));
  83. // A misbehaving OCX may keep a hidden window in our view instead
  84. // of destroying it when it's not in-place active, so make sure
  85. // the window's visible and enabled before trying to give it focus.
  86. // (MFC doesn't check before doing a UIActivate call.)
  87. HWND hwndControl = ::GetWindow(m_hWnd, GW_CHILD);
  88. if (!hwndControl || !::IsWindowVisible(hwndControl) || !::IsWindowEnabled(hwndControl))
  89. return (HWND)NULL; // do not change anything
  90. // simply set focus on itselt - msg handlers will do the rest
  91. return ::SetFocus(m_hWnd);
  92. }
  93. #endif /* MMCAXWIN_INL_INCLUDED */