📄 digitaldevice.cpp
字号:
//函数名:OnTimer(UINT nIDEvent)
//输入参数:定时器事件的ID
//返回值:无
//作用:重载函数,主要处理测试状态下的重画工作
void DigitalDevice::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static k = 1;
switch(DD_Status)
{
case DD_TEST:
switch(DD_WorkMode)
{
case DD_NUMBER:
DD_CurrentNumber ++;
if(DD_CurrentNumber > GetMaxNumber())
DD_CurrentNumber = 0;
DrawFace();
break;
case DD_STRING:
SYSTEMTIME tm;
GetLocalTime(&tm);
if(k == 1)
DD_CurrentString.Format("%02d:%02d:%02d", tm.wHour, tm.wMinute, tm.wSecond);
else
DD_CurrentString.Format("%02d %02d %02d", tm.wHour, tm.wMinute, tm.wSecond);
DrawFace();
k = - k;
break;
}
break;
default:
break;
}
CStatic::OnTimer(nIDEvent);
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetSize(UINT width, UINT height)
//输入参数:仪表的宽度和高度
//返回值:无
//作用:设置仪表的大小
void DigitalDevice::DD_SetSize(UINT width, UINT height)
{
DD_Width = width;
DD_Height = height;
RECT rect;
GetWindowRect(&rect);
MoveWindow(rect.left, rect.top, width, height);
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_Update()
//输入参数:无
//返回值:无
//作用:该函数立刻重画仪表的界面
void DigitalDevice::DD_Update()
{
DrawFace();
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetTextStyle(UINT charwidth, UINT charheight, UINT charthick, UINT charspace)
//输入参数:charwidth是字符的宽度,charheight是字符的高度,charthick是字符的笔划宽度,charspace是字符之间的空白距离,以上单位均是象素
//返回值:无
//作用:设置文字的显示样式
void DigitalDevice::DD_SetTextStyle(UINT charwidth, UINT charheight, UINT charthick, UINT charspace)
{
DD_CharWidth = charwidth;
DD_CharHeight = charheight;
DD_CharThick = charthick;
DD_CharSpace = charspace;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetTextPos(int x, int y)
//输入参数:开始绘制文字(文字的左上角)的坐标
//返回值:无
//作用:设置要显示的文字的位置
void DigitalDevice::DD_SetTextPos(int x, int y)
{
DD_TextPos.x = x;
DD_TextPos.y = y;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetWorkMode(UINT mode)
//输入参数:工作方式常量,可以是DD_NUMBER或者是DD_STRING,分别表示要测试的量是数值或者是字串
//返回值:无
//作用:设置仪表的工作方式
void DigitalDevice::DD_SetWorkMode(UINT mode)
{
DD_WorkMode = mode;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:SetCurrentNumber(double num)
//输入参数:期望的当前示数
//返回值:无
//作用:设置仪表当前的示数,该函数自动完成重画
void DigitalDevice::SetCurrentNumber(double num)
{
DD_CurrentNumber = num;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetCurrentString(CString string)
//输入参数:期望的当前显示字符串,只能包含数字,'.'和':'
//返回值:无
//作用:设置仪表当前的显示字符串,该函数自动完成重画
void DigitalDevice::DD_SetCurrentString(CString string)
{
if(DD_Status != DD_WORK)
return;
DD_CurrentString = string;
DrawFace();
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetStatus(UINT status)
//输入参数:仪表的状态常量,可以是DD_TEST(测试状态)或者DD_WORK(正常工作)
//返回值:无
//作用:设置仪表当前的状态
void DigitalDevice::DD_SetStatus(UINT status)
{
DD_Status = status;
DD_CurrentNumber = 0;
DD_CurrentString = "";
DrawFace();
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetCurrentNumber(double num)
//输入参数:当前要显示的数值
//返回值:无
//作用:设置仪表当前要显示的数值
void DigitalDevice::DD_SetCurrentNumber(double num)
{
if(DD_Status != DD_WORK)
return;
DD_CurrentNumber = num;
DrawFace();
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetTextLightColor(COLORREF color)
//输入参数:文字的颜色(点亮状态)
//返回值:无
//作用:设置仪表文字的颜色(点亮状态)
void DigitalDevice::DD_SetTextLightColor(COLORREF color)
{
DD_TextLightColor = color;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetTextDarkColor(COLORREF color)
//输入参数:文字的颜色(熄灭状态)
//返回值:无
//作用:设置仪表文字的颜色(非点亮状态)
void DigitalDevice::DD_SetTextDarkColor(COLORREF color)
{
DD_TextDarkColor = color;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetBits(UINT bits)
//输入参数:数码管位数,如果设置成0,将不显示数字,外观和普通的静态控件一样
//返回值:无
//作用:设置仪表数码管的位数
void DigitalDevice::DD_SetBits(UINT bits)
{
DD_Bits = bits;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetBorderStyle(UINT left, UINT top, UINT right, UINT bottom)
//输入参数:四条边框线的显示方式,0表示不显示,1表示显示
//返回值:无
//作用:设置仪表边框的显示样式
void DigitalDevice::DD_SetBorderStyle(UINT left, UINT top, UINT right, UINT bottom)
{
DD_BorderLeft = left;
DD_BorderTop = top;
DD_BorderRight = right;
DD_BorderBottom = bottom;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:GetMaxNumber()
//输入参数:无
//返回值:无
//作用:获取仪表能表示的最大数值
double DigitalDevice::GetMaxNumber()
{
UINT i;
CString text = "";
for(i = 0; i < DD_Bits; i ++)
text += "9";
return atof(text);
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetBorderWidth(UINT width)
//输入参数:边框的线条宽度,单位是象素
//返回值:无
//作用:设置仪表的边框的粗细
void DigitalDevice::DD_SetBorderWidth(UINT width)
{
DD_BorderWidth = width;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetBkColor(COLORREF color)
//输入参数:背景颜色
//返回值:无
//作用:设置仪表的背景颜色
void DigitalDevice::DD_SetBkColor(COLORREF color)
{
DD_BkColor = color;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:DD_SetBdColor(COLORREF lightcolor, COLORREF darkcolor)
//输入参数:边框的亮部颜色,边框的暗部颜色
//返回值:无
//作用:设置仪表的边框颜色
void DigitalDevice::DD_SetBdColor(COLORREF lightcolor, COLORREF darkcolor)
{
DD_BdLightColor = lightcolor;
DD_BdDarkColor = darkcolor;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:GetNextColor(COLORREF current_color, int delta)
//输入参数:current_color为源颜色,delta为变化量(可以取正负值)
//返回值:无
//作用:获得current_color的同样色调的下一颜色(如果delta大于0则为更亮的颜色,小于0则为更暗的颜色)
COLORREF DigitalDevice::GetNextColor(COLORREF current_color, int delta)
{
long red, green, blue;
red = GetRValue(current_color) + delta;
green = GetGValue(current_color) + delta;
blue = GetBValue(current_color) + delta;
if(red > 255)
red = 255;
if(green > 255)
green = 255;
if(blue > 255)
blue = 255;
if(red < 0)
red = 0;
if(green < 0)
green = 0;
if(blue < 0)
blue = 0;
return RGB(red, green, blue);
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:GetNextColor(COLORREF color, double ratio)
//输入参数:current_color为源颜色,ratio为变化比率
//返回值:无
//作用:获得current_color的同样色调的下一颜色(如果ratio大于1则为更亮的颜色,小于1则为更暗的颜色)
COLORREF DigitalDevice::GetNextColor(COLORREF current_color, double ratio)
{
long red, green, blue;
red = (long)(GetRValue(current_color) * ratio);
green = (long)(GetGValue(current_color) * ratio);
blue = (long)(GetBValue(current_color) * ratio);
if(red > 255)
red = 255;
if(green > 255)
green = 255;
if(blue > 255)
blue = 255;
if(red < 0)
red = 0;
if(green < 0)
green = 0;
if(blue < 0)
blue = 0;
return RGB(red, green, blue);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -