共用方式為


IUIApplication::OnCreateUICommand 方法 (uiribbon.h)

針對 Windows 功能區架構標記中指定的每個命令呼叫,以將命令系結至 IUICommandHandler

語法

HRESULT OnCreateUICommand(
  [in]  UINT32            commandId,
  [in]  UI_COMMANDTYPE    typeID,
  [out] IUICommandHandler **commandHandler
);

參數

[in] commandId

類型: UINT32

命令的識別碼,這個識別碼是在標記資源檔中指定。

[in] typeID

類型: UI_COMMANDTYPE

與特定控制項相關聯的 命令類型

[out] commandHandler

類型: IUICommandHandler**

當這個方法傳回時,會包含 IUICommandHandler 物件的指標位址。 這個物件是系結至一或多個命令的主應用程式 Command 處理常式。

傳回值

類型: HRESULT

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

備註

功能區架構會針對處理標記資源檔時遇到的每個命令宣告,將此回呼通知傳送至主應用程式。

針對功能區標記中指定的每個命令,功能區架構需要主應用程式中的命令處理常式。 必須將新的或現有的處理常式指派給每個命令。

範例

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

//
//  FUNCTION: OnCreateUICommand(UINT, UI_COMMANDTYPE, IUICommandHandler)
//
//  PURPOSE: Called by the Ribbon framework for each command specified in markup to allow
//           the host application to bind a command handler to that command.
//
//  PARAMETERS:    
//                nCmdID - The Command identifier. 
//                typeID - The Command type. 
//                ppCommandHandler - Pointer to the address of the Command handler. 
//
//  COMMENTS:
//
//    For this sample, return the same command handler for all commands
//    specified in the .xml file.
//    
//
STDMETHODIMP CApplication::OnCreateUICommand(
    UINT nCmdID,
    UI_COMMANDTYPE typeID,
    IUICommandHandler** ppCommandHandler)
{
    HRESULT hr = E_NOTIMPL;

    switch(typeID)
    {
        case UI_COMMANDTYPE_DECIMAL:
            {
                _cwprintf(L"IUIApplication::OnCreateUICommand called for Spinner.\r\n");
                hr = _spSpinnerSite->QueryInterface(IID_PPV_ARGS(ppCommandHandler));
                break;
            }
        default:
            {
                _cwprintf(L"IUIApplication::OnCreateUICommand called with CmdID=%u, typeID=%u.\r\n", nCmdID, typeID);
                hr = _spCommandHandler->QueryInterface(IID_PPV_ARGS(ppCommandHandler));
            }
    }    
    return hr;
}

規格需求

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

另請參閱

IUIApplication

Windows 功能區架構範例