예제 #1
0
void ExtFrame::SetSpinValue(CSpinButtonCtrl& spin, CEdit& edit, int val, bool two)
{
    int rangeMin;
    int rangeMax;
    spin.GetRange32(rangeMin, rangeMax);
    if(val < rangeMin)
    {
        val = rangeMin;
    }
    else if(val > rangeMax)
    {
        val = rangeMax;
    }
    char num[33];
    if(two && val < 10)
    {
        *num = '0';
        _itoa_s(val, num + 1, sizeof(num) - 1, 10);
    }
    else
    {
        _itoa_s(val, num, sizeof(num), 10);
    }
    spin.SetPos(val);

    edit.SetWindowText(num);
}
예제 #2
0
void ExtFrame::AdjustEdit(CSpinButtonCtrl& spin, CEdit& edit, bool two)
{
    int rangeMin;
    int rangeMax;
    spin.GetRange32(rangeMin, rangeMax);
    if(rangeMin <= rangeMax)
    {
        int length = edit.GetWindowTextLength();
        char* temp = new char[length + 1];
        edit.GetWindowText(temp, length + 1);
        int value;
        bool changed = false;
        if(length == 0)
        {
            value = rangeMin;
            changed = true;
        }
        else
        {
            value = atoi(temp);
            if(value < rangeMin)
            {
                value = rangeMin;
                changed = true;
            }
            else if(value > rangeMax)
            {
                value = rangeMax;
                changed = true;
            }
        }
        char numValue[33];
        _itoa_s(value, numValue, 10);
        length = (int)strlen(numValue);

        if(length == 0)
        {
            edit.SetWindowText(two ? "00" : "0");
        }
        else if(two)
        {
            if(length == 1)
            {
                char num[33];
                *num = '0';
                strcpy_s(num + 1, sizeof(num) - 1, numValue);
                edit.SetWindowText(num);
            }
            else if(changed)
            {
                edit.SetWindowText(numValue);
            }
        }
        else
        {
            if(length == 2)
            {
                if(*numValue == '0')
                {
                    edit.SetWindowText(numValue + 1);
                }
                else if(changed)
                {
                    edit.SetWindowText(numValue);
                }
            }
            else if(changed)
            {
                edit.SetWindowText(numValue);
            }
        }
        delete[] temp;
    }
}