共用方式為


IUIFramework::LoadUI 方法 (uiribbon.h)

載入 Windows 功能區架構 UI 資源,或編譯的標記、檔案。

語法

HRESULT LoadUI(
  [in] HINSTANCE instance,
  [in] LPCWSTR   resourceName
);

參數

[in] instance

類型: HINSTANCE

功能區應用程式實例的句柄。

[in] resourceName

類型: LPCWSTR

包含已編譯二進位標記的資源名稱。

注意 若要成功初始化功能區,編譯的功能區標記檔案必須可作為資源使用。 此標記檔案是功能區架構不可或缺的元件;它會指定要使用的控件及其配置。
 

傳回值

類型: HRESULT

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

備註

初始化時應該呼叫 IUIFramework::LoadUI。 例如,若要顯示或隱藏功能區,可以在應用程式生命週期期間多次呼叫此方法,前提是在兩者之間呼叫 IUIFramework::D estroy

IUIFramework::LoadUI 執行期間,會呼叫 OnCreateUICommandOnViewChanged

範例

下列範例示範基本的架構初始化函式。

//
//  FUNCTION:    InitializeFramework(HWND)
//
//  PURPOSE:    Initialize the Ribbon framework and bind a Ribbon to the application.
//
//  PARAMETERS:    
//                hWnd - Handle to the Ribbon host application window. 
//
//  COMMENTS:
//
//    In order to get a Ribbon to display, the Ribbon framework must be initialized. 
//    This involves three important steps:
//      1) Instantiate the Ribbon framework object (CLSID_UIRibbonFramework).
//      2) Pass the host HWND and IUIApplication object to the framework.
//      3) Load the binary markup compiled by the UI Command Compiler (UICC.exe).
//
//
bool InitializeFramework(HWND hWnd)
{
    // Instantiate the Ribbon framework object.
    HRESULT hr = CoCreateInstance(
        CLSID_UIRibbonFramework, 
        NULL, 
        CLSCTX_INPROC_SERVER, 
        IID_PPV_ARGS(&g_pFramework));
    if (!SUCCEEDED(hr))
    {
        return false;
    }    

    // Create the application object (IUIApplication) and call the 
    // framework Initialize method, passing the application object and the 
    // host HWND that the Ribbon will attach itself to.
    CComObject<CApplication> *pApplication = NULL;
    CComObject<CApplication>::CreateInstance(&pApplication);
    hr = pApplication->QueryInterface(&g_pApplication);
    if (!SUCCEEDED(hr))
    {
        return false;
    } 

    hr = g_pFramework->Initialize(hWnd, g_pApplication);
    if (!SUCCEEDED(hr))
    {
        return false;
    }

    // Load the binary markup.  
    // Initiate callbacks to the IUIApplication object that was 
    // provided to the framework earlier and bind command handler(s) 
    // to individual commands.
    hr = g_pFramework->LoadUI(GetModuleHandle(NULL), L"APPLICATION_RIBBON");
    if (!SUCCEEDED(hr))
    {
        return false;
    }
    return true;
}

規格需求

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

另請參閱

編譯功能區標記

IUIFramework

IUIFramework::Initialize

標記專案

Windows 功能區架構範例