Spinner

Spinner es un control compuesto que consta de un botón de incremento, un botón decremento y un control de edición, todos los cuales se usan para proporcionar valores decimales a la aplicación.

Detalles

En la captura de pantalla siguiente se muestra el número de cinta de opciones.

captura de pantalla de un control spinner en la cinta de opciones del creador de películas en vivo de Windows.

Propiedades de número

El marco de la cinta define una colección de claves de propiedad para el control Spinner.

Normalmente, una propiedad Spinner se actualiza en la interfaz de usuario de la cinta invalidando el comando asociado al control a través de una llamada al método IUIFramework::InvalidateUICommand . El evento de invalidación se controla y la propiedad se actualiza definida por el método de devolución de llamada IUICommandHandler::UpdateProperty .

El método de devolución de llamada IUICommandHandler::UpdateProperty no se ejecuta y la aplicación consulta para obtener un valor de propiedad actualizado, hasta que el marco requiera la propiedad. Por ejemplo, cuando se activa una pestaña y se muestra un control en la interfaz de usuario de la cinta de opciones, o cuando se muestra una información sobre herramientas.

Nota:

En algunos casos, se puede recuperar una propiedad a través del método IUIFramework::GetUICommandProperty y establecer con el método IUIFramework::SetUICommandProperty .

En la tabla siguiente se enumeran las claves de propiedad asociadas al control Spinner.

Clave de propiedad Notas
UI_PKEY_DecimalPlaces Solo se puede actualizar a través de la invalidación.
UI_PKEY_DecimalValue Admite IUIFramework::GetUICommandProperty e IUIFramework::SetUICommandProperty. Nota: Si el comando asociado al control se invalida mediante una llamada a IUIFramework::InvalidateUICommand, el marco consulta esta propiedad cuando UI_INVALIDATIONS_VALUE se pasa como valor de marcas.
UI_PKEY_Enabled Admite IUIFramework::GetUICommandProperty e IUIFramework::SetUICommandProperty.
UI_PKEY_FormatString Solo se puede actualizar a través de la invalidación.
UI_PKEY_Increment Solo se puede actualizar a través de la invalidación.
UI_PKEY_Keytip Solo se puede actualizar a través de la invalidación.
UI_PKEY_Label Solo se puede actualizar a través de la invalidación.
UI_PKEY_LargeHighContrastImage Solo se puede actualizar a través de la invalidación.
UI_PKEY_LargeImage Solo se puede actualizar a través de la invalidación.
UI_PKEY_MaxValue Solo se puede actualizar a través de la invalidación.
UI_PKEY_MinValue Solo se puede actualizar a través de la invalidación.
UI_PKEY_RepresentativeString Solo se puede actualizar a través de la invalidación.
UI_PKEY_SmallHighContrastImage Solo se puede actualizar a través de la invalidación.
UI_PKEY_SmallImage Solo se puede actualizar a través de la invalidación.
UI_PKEY_TooltipDescription Solo se puede actualizar a través de la invalidación.
UI_PKEY_TooltipTitle Solo se puede actualizar a través de la invalidación.

En la siguiente sección de código se muestra cómo se actualizan varias propiedades del control Spinner en el método 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;
}

Comentarios

Si el valor mínimo (UI_PKEY_MinValue) de un spinner se inicializa en 0,0, la aplicación debe asegurarse de que cualquier valor subsiguiente proporcionado por el control no sea igual a -0,0 (cero negativo). Si spinner proporciona un valor de -0.0, la aplicación debe restablecer este valor a 0,0 (cero positivo) mediante el método IUIFramework::SetUICommandProperty , como se muestra en el ejemplo siguiente de un método IUICommandHandler::Execute para un control Spinner.

Nota:

Si esta prueba no se realiza y el valor deja sin corregir, el campo de edición del control muestra la cadena "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;
}

Biblioteca de controles del marco de la cinta de opciones de Windows

Elemento de marcado spinner