Share via


Spinner

Le Spinner est un contrôle composite qui se compose d’un bouton incrément, d’un bouton décrémentation et d’un contrôle d’édition, qui sont tous utilisés pour fournir des valeurs décimales à l’application.

Détails

La capture d’écran suivante illustre le spinner du ruban.

capture d’écran d’un contrôle spinner dans le ruban windows live moviemaker.

Propriétés du spinner

L’infrastructure ribbon définit une collection de clés de propriété pour le contrôle Spinner.

En règle générale, une propriété Spinner est mise à jour dans l’interface utilisateur du ruban en invalidant la commande associée au contrôle via un appel à la méthode IUIFramework::InvalidateUICommand . L’événement d’invalidation est géré et la propriété est mise à jour définie par la méthode de rappel IUICommandHandler::UpdateProperty .

La méthode de rappel IUICommandHandler::UpdateProperty n’est pas exécutée et l’application a demandé une valeur de propriété mise à jour, jusqu’à ce que la propriété soit requise par l’infrastructure. Par exemple, lorsqu’un onglet est activé et qu’un contrôle est révélé dans l’interface utilisateur du ruban, ou lorsqu’une info-bulle est affichée.

Notes

Dans certains cas, une propriété peut être récupérée via la méthode IUIFramework::GetUICommandProperty et définie avec la méthode IUIFramework::SetUICommandProperty .

Le tableau suivant répertorie les clés de propriété associées au contrôle Spinner.

Clé de propriété Notes
UI_PKEY_DecimalPlaces Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_DecimalValue Prend en charge IUIFramework::GetUICommandProperty et IUIFramework::SetUICommandProperty. Note: Si la commande associée au contrôle est invalidée par un appel à IUIFramework::InvalidateUICommand, l’infrastructure interroge cette propriété quand UI_INVALIDATIONS_VALUE est passée comme valeur d’indicateurs.
UI_PKEY_Enabled Prend en charge IUIFramework::GetUICommandProperty et IUIFramework::SetUICommandProperty.
UI_PKEY_FormatString Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_Increment Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_Keytip Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_Label Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_LargeHighContrastImage Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_LargeImage Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_MaxValue Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_MinValue Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_RepresentativeString Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_SmallHighContrastImage Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_SmallImage Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_TooltipDescription Peut uniquement être mis à jour via l’invalidation.
UI_PKEY_TooltipTitle Peut uniquement être mis à jour via l’invalidation.

La section suivante du code montre comment les différentes propriétés du contrôle Spinner sont mises à jour dans la méthode IUICommandHandler::UpdateProperty .

//
//  FUNCTION:    UpdateProperty()
//
//  PURPOSE:    Called by the Ribbon framework when a command property needs 
//                to be updated.
//
//  COMMENTS:    This function is used to provide new command property values for 
//                the spinner when requested by the Ribbon framework.  
//    
STDMETHODIMP CCommandHandler::UpdateProperty(
    UINT nCmdID,
    REFPROPERTYKEY key,
    const PROPVARIANT* ppropvarCurrentValue,
    PROPVARIANT* ppropvarNewValue)
{
    UNREFERENCED_PARAMETER(ppropvarCurrentValue);

    HRESULT hr = E_NOTIMPL;

    if (nCmdID == IDR_CMD_SPINNER_RESIZE)
    {
        // Set the minimum value
        if (IsEqualPropertyKey(key, UI_PKEY_MinValue))
        {
            ZeroMemory(ppropvarNewValue, sizeof(*ppropvarNewValue));
            ppropvarNewValue->vt = VT_DECIMAL;
            VarDecFromR8(-10.0, &ppropvarNewValue->decVal);
            hr = S_OK;
        }

        // Set the maximum value
        else if (IsEqualPropertyKey(key, UI_PKEY_MaxValue))
        {
            ZeroMemory(ppropvarNewValue, sizeof(*ppropvarNewValue));
            ppropvarNewValue->vt = VT_DECIMAL;
            VarDecFromR8(10.0, &ppropvarNewValue->decVal);
            hr = S_OK;
        }

        // Set the increment
        else if (IsEqualPropertyKey(key, UI_PKEY_Increment))
        {
            ZeroMemory(ppropvarNewValue, sizeof(*ppropvarNewValue));
            ppropvarNewValue->vt = VT_DECIMAL;
            VarDecFromR8(2.0, &ppropvarNewValue->decVal);
            hr = S_OK;
        }

        // Set the number of decimal places
        else if (IsEqualPropertyKey(key, UI_PKEY_DecimalPlaces))
        {
            hr = InitPropVariantFromUInt32(1, ppropvarNewValue);
            hr = S_OK;
        }

        // Set the format string
        else if (IsEqualPropertyKey(key, UI_PKEY_FormatString))
        {
            hr = InitPropVariantFromString(L"px", ppropvarNewValue);
            hr = S_OK;
        }

        // Set the representative string
        else if (IsEqualPropertyKey(key, UI_PKEY_RepresentativeString))
        {
            hr = InitPropVariantFromString(L"AAAAAAA", ppropvarNewValue);
            hr = S_OK;
        }
    }
    return hr;
}

Notes

Si la valeur minimale (UI_PKEY_MinValue) d’un spinner est initialisée à 0,0, l’application doit s’assurer que toute valeur ultérieure fournie par le contrôle n’est pas égale à -0,0 (zéro négatif). Si spinner fournit une valeur de -0,0, l’application doit réinitialiser cette valeur à 0,0 (zéro positif) à l’aide de la méthode IUIFramework::SetUICommandProperty , comme illustré dans l’exemple suivant de méthode IUICommandHandler::Execute pour un contrôle Spinner.

Notes

Si ce test n’est pas effectué et que la valeur n’est pas corrigée, le champ d’édition du contrôle affiche la chaîne « Auto ».

//
//  FUNCTION:    Execute()
//
//  PURPOSE:    Called by the Ribbon framework when a command is executed by the user.  
//                For this sample, when an increment or decrement button is pressed or
//                a new value is entered in the Spinner edit field.
//
STDMETHODIMP CCommandHandler::Execute(
      UINT nCmdID,
      UI_EXECUTIONVERB verb,
      const PROPERTYKEY* key,
      const PROPVARIANT* ppropvarValue,
      IUISimplePropertySet* pCommandExecutionProperties)
{
    UNREFERENCED_PARAMETER(pCommandExecutionProperties);

    HRESULT hr = E_NOTIMPL;

    if (verb == UI_EXECUTIONVERB_EXECUTE)
    {
        RenderParam param;
        g_renderer.GetRenderParam(&param);

        if (nCmdID == IDR_CMD_SPINNER_RESIZE)
        {
            // Spinner value is negative.
            if (!(ppropvarValue->decVal.sign == 0))
            {
                // Check if the value supplied by the Spinner is -0
                // and correct the value if necessary.
                // If this value is left uncorrected, the edit field 
                // of the control will display the string "Auto" when 
                // UI_PKEY_MinValue is set to 0.
                if (ppropvarValue->decVal.Lo64 == 0)
                {
                    // Initialize a new PROPVARIANT structure.
                    PROPVARIANT m_varNewVal;
                    PropVariantInit(&m_varNewVal);

                    // The replacement DECIMAL value.
                    DECIMAL m_dVal;
                    hr = VarDecFromI4(0, &m_dVal);
                    if (FAILED(hr))
                    {
                        return hr;
                    }
                    
                    // Initialize the new DECIMAL value.
                    UIInitPropertyFromDecimal(UI_PKEY_DecimalValue, m_dVal, &m_varNewVal);

                    // Set the UI_PKEY_DecimalValue to the new DECIMAL value.
                    hr = g_pFramework->SetUICommandProperty(nCmdID, UI_PKEY_DecimalValue, m_varNewVal);
                    if (FAILED(hr))
                    {
                        return hr;
                    }
                }
                // Decrease size of shape in document space.
                param.iShapeSizeIncrement = -ppropvarValue->intVal;
            }
            // Spinner value is positive.
            else
            {
                // Increase size of shape in document space.
                param.iShapeSizeIncrement = ppropvarValue->intVal;
            }
        }
        g_renderer.UpdateRenderParam(param);
    }

    return hr;
}

Bibliothèque de contrôle de l’infrastructure du ruban Windows

Élément de balisage Spinner