?? 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 + -