Exemplo n.º 1
0
        private void BtnBrightnessLevelApply_Click(object sender, EventArgs e)
        {
            ushort ret;

            if (RadioBrightnessLevelSet.Checked)
            {
                HotKey_API.IMC_BRIGHTNESS_LEVEL level = new HotKey_API.IMC_BRIGHTNESS_LEVEL();
                level.minimum = Convert.ToByte(EditBrightnessLevelMinValue.Text);
                level.maximum = Convert.ToByte(EditBrightnessLevelMaxValue.Text);
                level.current = Convert.ToByte(EditBrightnessLevelCurValue.Text);

/*
 *             string strTmp = String.Format("{0}, {1}, {2}", level.minimum, level.maximum, level.current);
 *              MessageBox.Show(strTmp, "Warning");
 */
                if (level.minimum < HotKey_API.IMC_BRIGHTNESS_LEVEL_MIN ||
                    level.minimum > HotKey_API.IMC_BRIGHTNESS_LEVEL_MAX ||
                    level.maximum < HotKey_API.IMC_BRIGHTNESS_LEVEL_MIN ||
                    level.maximum > HotKey_API.IMC_BRIGHTNESS_LEVEL_MAX
                    )
                {
                    string strWarning = String.Format("Out of Range !!\nLevel : {0} - {1}\n",
                                                      HotKey_API.IMC_BRIGHTNESS_LEVEL_MIN,
                                                      HotKey_API.IMC_BRIGHTNESS_LEVEL_MAX
                                                      );
                    MessageBox.Show(strWarning, "Warning");
                    return;
                }
                if (level.minimum > level.maximum)
                {
                    string strWarning = String.Format("The min threshold should be larger than the max one");
                    MessageBox.Show(strWarning, "Warning");
                    return;
                }
                if (level.current > level.maximum || level.current < level.minimum)
                {
                    string strWarning = String.Format("Current Value is out of range !!");
                    MessageBox.Show(strWarning, "Warning");
                    return;
                }
                ret = HotKey_API.Brightness_SetLevel(ref level);
                if (ret != IMCAPIErrCode.IMC_ERR_NO_ERROR)
                {
                    ShowWanringMessage("Fails to set the value of the level", ret);
                    return;
                }
            }
            else
            {
                HotKey_API.IMC_BRIGHTNESS_LEVEL level = new HotKey_API.IMC_BRIGHTNESS_LEVEL();
                unsafe
                {
                    ret = HotKey_API.Brightness_GetLevel(out level);
                }
                if (ret != IMCAPIErrCode.IMC_ERR_NO_ERROR)
                {
                    ShowWanringMessage("Fails to get the brightness level", ret);
                    return;
                }
                EditBrightnessLevelMinValue.Text = level.minimum.ToString();
                EditBrightnessLevelMaxValue.Text = level.maximum.ToString();
                EditBrightnessLevelCurValue.Text = level.current.ToString();
            }
        }