共用方式為


IUIApplication::OnViewChanged 方法 (uiribbon.h)

檢視 的狀態變更時呼叫。

語法

HRESULT OnViewChanged(
  [in] UINT32      viewId,
  [in] UI_VIEWTYPE typeID,
  [in] IUnknown    *view,
  [in] UI_VIEWVERB verb,
  [in] INT32       uReasonCode
);

參數

[in] viewId

類型: UINT32

檢視的識別碼。 只有 0 的值有效。

[in] typeID

類型: UI_VIEWTYPE

應用程式所裝載 UI_VIEWTYPE

[in] view

類型: IUnknown*

檢視介面的指標。

[in] verb

類型: UI_VIEWVERB

檢視所執行 UI_VIEWVERB (或動作) 。

[in] uReasonCode

類型: INT32

未定義。

傳回值

類型: HRESULT

如果此方法成功,則會傳回 S_OK。 否則,它會傳回 HRESULT 錯誤碼。

備註

架構會將此回呼通知傳送至每個檢視狀態變更上的主應用程式。

重要只有viewId為 0的功能區檢視才會發生此回呼。
 
IUIApplication::OnViewChanged 適用于在主應用程式啟動時初始化功能區屬性、根據使用者動作修改功能區屬性,例如調整應用程式視窗大小,以及在應用程式關閉時查詢功能區屬性。

範例

下列範例示範 IUIApplication::OnViewChanged 方法的基本實作。

//
//  FUNCTION: OnViewChanged(UINT, UI_VIEWTYPE, IUnknown*, UI_VIEWVERB, INT)
//
//  PURPOSE: Called when the state of a View (Ribbon is a view) changes - like created/destroyed/resized.
//
//  PARAMETERS:    
//                viewId - The View identifier. 
//                typeID - The View type. 
//                pView - Pointer to the View interface. 
//                verb - The action performed by the View. 
//                uReasonCode - Not defined. 
//
//  COMMENTS:
//
//    For this sample, return the same command handler for all commands
//    specified in the .xml file.
//    
//
STDMETHODIMP CApplication::OnViewChanged(
    UINT viewId,
    UI_VIEWTYPE typeId,
    IUnknown* pView,
    UI_VIEWVERB verb,
    INT uReasonCode)
{
    HRESULT hr = E_NOTIMPL;
    
    // Checks to see if the view that was changed was a Ribbon view.
    if (UI_VIEWTYPE_RIBBON == typeId)
    {
        switch (verb)
        {            
            // The view was newly created.
            case UI_VIEWVERB_CREATE:
                _cwprintf(L"IUIApplication::OnViewChanged called with verb=CREATE\r\n");

                if (NULL == g_pRibbon)
                {
                    // Retrieve and store the IUIRibbon
                    hr = pView->QueryInterface(&g_pRibbon);
                }
                break;

            // The view was resized.  
            // In the case of the Ribbon view, the application should call 
            // GetHeight() to determine the height of the Ribbon.
            case UI_VIEWVERB_SIZE:
                _cwprintf(L"IUIApplication::OnViewChanged called with verb=SIZE\r\n");
                // Call to the framework to determine the height of the Ribbon.
                if (NULL != g_pRibbon)
                {
                    UINT uRibbonHeight;
                    hr = g_pRibbon->GetHeight(&uRibbonHeight);
                }
                if (!SUCCEEDED(hr))
                {
                    //_cwprintf(L"IUIRibbon::GetHeight() failed with hr=0x%X\r\n", hr);
                }
                break;
                
            // The view was destroyed.
            case UI_VIEWVERB_DESTROY:
                //_cwprintf(L"IUIApplication::OnViewChanged called with verb=DESTROY\r\n");
                g_pRibbon = NULL;
                hr = S_OK;
                break;
        }
    }
    return hr;
}

需求

   
最低支援的用戶端 Windows 7 [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2008 R2 [僅限桌面應用程式]
目標平台 Windows
標頭 uiribbon.h
Dll Mshtml.dll

另請參閱

IUIApplication

Windows 功能區架構範例