IUIFramework::GetView method (uiribbon.h)

Retrieves the address of a pointer to an interface that represents a Windows Ribbon framework View, such as IUIRibbon or IUIContextualUI.

Syntax

HRESULT GetView(
  [in]  UINT32 viewId,
  [in]  REFIID riid,
  [out] void   **ppv
);

Parameters

[in] viewId

Type: UINT32

The ID for the View. A value of 0 for a Ribbon or the Command.Id of a ContextPopup.

[in] riid

Type: REFIID

The interface ID for IUIRibbon or IUIContextualUI.

[out] ppv

Type: void**

When this method returns, contains the address of a pointer to an IUIRibbon or an IUIContextualUI object.

Return value

Type: HRESULT

Returns S_OK if successful; otherwise, an error value from the following list.

Value Description
E_INVALIDARG riid is not a valid interface ID.
E_FAIL The operation failed.

Remarks

Ribbon framework UI functionality is differentiated by Views, which are essentially built-in core frameworks, such as the Ribbon and ContextPopup.

Rather than maintaining a pointer to an interface throughout the life of an application, IUIFramework::GetView enables a host application to create a temporary interface pointer and call methods as necessary.

Note  The host application must call IUnknown::Release on the temporary interface pointer to avoid a memory leak.
 
For example, each time there is a change to the size of the ribbon, a host application calls GetHeight to adjust the size of the host client area appropriately.

Examples

The following example demonstrates how to use the IUIFramework::GetView method to retrieve a Ribbon View object, call the GetHeight method to retrieve the height of the ribbon, and calculate a display location for a Context Popup control based on the height of the ribbon.

void GetDisplayLocation(POINT &pt, HWND hWnd)
{
  if (pt.x == -1 && pt.y == -1)
  {
    HRESULT hr = E_FAIL;

    // Display the menu in the upper-left corner of the client area, below the ribbon.
    IUIRibbon* pRibbon;
    hr = g_pFramework->GetView(0, IID_PPV_ARGS(&pRibbon));
    if (SUCCEEDED(hr))
    {
      UINT32 uRibbonHeight = 0;
      hr = pRibbon->GetHeight(&uRibbonHeight);
      if (SUCCEEDED(hr))
      {
        pt.x = 0;
        pt.y = uRibbonHeight;
        // Convert client coordinates of a specified point to screen coordinates.
        ClientToScreen(hWnd, &pt);
      }
      pRibbon->Release();
    }
    if (FAILED(hr))
    {
      // Default to just the upper-right corner of the entire screen.
      pt.x = 0;
      pt.y = 0;
    }
  }
}

Requirements

Requirement Value
Minimum supported client Windows 7 [desktop apps only]
Minimum supported server Windows Server 2008 R2 [desktop apps only]
Target Platform Windows
Header uiribbon.h
DLL Mshtml.dll

See also

IUIFramework

Windows Ribbon Framework Samples