📄 hcontrol.cpp
字号:
FD_LowLevelColor = color;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetMiddleLevelColor(COLORREF color)
//输入参数:液体颜色
//返回值:无
//作用:设置流量达到中等水平时流量管液体的颜色
void CHControl::FD_SetMiddleLevelColor(COLORREF color)
{
FD_MiddleLevelColor = color;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetHighLevelColor(COLORREF color)
//输入参数:液体颜色
//返回值:无
//作用:设置流量达到高水平时流量管液体的颜色
void CHControl::FD_SetHighLevelColor(COLORREF color)
{
FD_HighLevelColor = color;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetFrameBackColor(COLORREF color)
//输入参数:框架的内表面的颜色
//返回值:无
//作用:设置框架内表面(当流量管未满时能看到)的颜色
void CHControl::FD_SetFrameBackColor(COLORREF color)
{
FD_FrameBackColor = color;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetFrameFrontColor(COLORREF color)
//输入参数:框架外表面的颜色
//返回值:无
//作用:设置框架外表面(只在流量管两头看得见)的颜色
void CHControl::FD_SetFrameFrontColor(COLORREF color)
{
FD_FrameFrontColor = color;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetFrameSize(UINT radius, UINT length)
//输入参数:框架的半径radius(通常应该比流量管半径要大一些)
// 框架长度length,这个长度是只能被看见的部分的长度(不包含被流量管遮住的部分)
// length表示流量管上下两头的框架高度都是length个象素
//返回值:无
//作用:设置流量表的框架(固定流量管的金属架子)字尺寸
void CHControl::FD_SetFrameSize(unsigned int radius,unsigned int length)
{
FD_FrameRadius = radius;
FD_FrameLength = length;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetFontSize(UINT size)
//输入参数:字体的大小
//返回值:无
//作用:设置流量表的刻度文字尺寸
void CHControl::FD_SetFontSize(unsigned int size)
{
FD_FontSize = size;
// FD_Font.DeleteObject();
// FD_Font.CreateFont(FD_FontSize, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, OUT_STROKE_PRECIS, CLIP_STROKE_PRECIS, DRAFT_QUALITY, VARIABLE_PITCH | FF_SWISS, _T("Arial")); //创建一个默认的字体
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetPipeSize(UINT radius, UINT length)
//输入参数:流量管的半径radius,流量管的长度length
//返回值:无
//作用:设置仪表的流量管的尺寸
void CHControl::FD_SetPipeSize(unsigned int radius, unsigned int length)
{
FD_PipeRadius = radius;
FD_PipeLength = length;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetOrigin(int x, int y)
//输入参数:坐标系原点相对于仪表在窗口左上角的位置坐标
//返回值:无
//作用:设置仪表的内部坐标系原点(也就是流量管的底部的中心)
void CHControl::FD_SetOrigin(int x, int y)
{
FD_Origin.x = x;
FD_Origin.y = y;
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetSize(UINT width, UINT height)
//输入参数:仪表的宽度和高度,单位是象素
//返回值:无
//作用:设置仪表的尺寸。
void CHControl::FD_SetSize(unsigned int width, unsigned int height)
{
FD_Width = width;
FD_Height = height;
RECT rect;
GetWindowRect(&rect);
// MoveWindow(rect.left, rect.top, width, height);
SetWindowPos(NULL, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE);
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetMaxFlux(double flux)
//输入参数:被检测流量的最大值
//返回值:无
//作用:设置被检测流量的最大值。
void CHControl::FD_SetMaxFluxV(double flux)
{
// FD_MaxFlux = flux;
// if(FD_CurrentFlux > FD_MaxFlux)
// FD_CurrentFlux = FD_MaxFlux;
//
m_max_v = (int)flux;
if(m_s_v2 > m_max_v)
m_s_v2 = m_max_v;
FireViewChange();
}
void CHControl::FD_SetMaxFluxA(double flux)
{
// FD_MaxFlux = flux;
// if(FD_CurrentFlux > FD_MaxFlux)
// FD_CurrentFlux = FD_MaxFlux;
//
m_max_a = (int)flux;
if(m_s_a2 > m_max_a)
m_s_a2 = m_max_a;
FireViewChange();
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetCurrentFlux(double flux)
//输入参数:被检测流量的当前值
//返回值:无
//作用:设置被显示流量的当前值。
void CHControl::FD_SetCurrentFluxV(double flux)
{
if(FD_Status != FD_WORK)
return;
// FD_CurrentFlux = flux;
// if(FD_CurrentFlux > FD_MaxFlux)
// FD_CurrentFlux = FD_MaxFlux;
// if(FD_CurrentFlux < 0)
// FD_CurrentFlux = 0;
m_s_v2 = (int)flux;
if(m_s_v2 > m_max_v)
m_s_v2 = m_max_v;
if(m_s_v2 < 0)
m_s_v2 = 0;
FireViewChange();
//DrawFace();
}
void CHControl::FD_SetCurrentFluxA(double flux)
{
if(FD_Status != FD_WORK)
return;
// FD_CurrentFlux = flux;
// if(FD_CurrentFlux > FD_MaxFlux)
// FD_CurrentFlux = FD_MaxFlux;
// if(FD_CurrentFlux < 0)
// FD_CurrentFlux = 0;
m_s_a2 =(int) flux;
if(m_s_a2 > m_max_a)
m_s_a2 = m_max_a;
if(m_s_a2 < 0)
m_s_a2 = 0;
FireViewChange();
//DrawFace();
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_SetStatus(UINT status)
//输入参数:仪表的状态常量status,可以是FD_TEST(自检状态)或者FD_WORK(工作状态)
//返回值:无
//作用:该函数设置仪表的当前状态。
void CHControl::FD_SetStatus(unsigned int status)
{
FD_Status = status;
FD_CurrentFlux = 0;
//DrawFace();
}
/////////////////////////////////////////////////////////////////////////////////////////
//函数名:FD_MoveWindow(int x, int y)
//输入参数:仪表窗口的新位置坐标
//返回值:无
//作用:该函数移动仪表的窗口
void CHControl::FD_MoveWindow(int x, int y)
{
CRect rect;
GetWindowRect(&rect);
MoveWindow(x, y, rect.Width(), rect.Height(), true);
}
COLORREF CHControl::GetNextColor(COLORREF current_color, int delta)
{
long red = 0, green = 0, blue = 0,temp = 0;
if(GetRValue(current_color))
red = GetRValue(current_color) + delta;
if(GetGValue(current_color))
green = GetGValue(current_color) + delta;
if(GetBValue(current_color))
blue = GetBValue(current_color) + delta;
if(red > 255)
{
red = 255;
return current_color;
}
if(green > 255)
{
green = 255;
return current_color;
}
if(blue > 255)
{
blue = 255;
return current_color;
}
if(red < 0)
{
red = 0;
return current_color;
}
if(green < 0)
{
green = 0;
return current_color;
}
if(blue < 0)
{
blue = 0;
return current_color;
}
return COLORREF(RGB(red, green, blue));
}
COLORREF CHControl::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);
long temp = current_color;
red = (long) ( (temp&0xff)*ratio );
green = (long)(((temp>>8)&0xff)*ratio);
blue = (long)(((temp>>16)&0xff)*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 COLORREF(RGB(red, green, blue));
}
LRESULT CHControl::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
m_bool_mouse_down = TRUE;
m_bool_mouse_up = FALSE;
point_pos.y = (long)(lParam>>16)&0xffff;
point_pos.x = (long)lParam&0xffff;
FireViewChange();
return 0;
}
//LRESULT CHControl::OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
//{
// m_bool_mouse_up = TRUE;
// m_bool_mouse_down = FALSE;
// point_pos.y =(long) (lParam>>16)&0xffff;
// point_pos.x = (long)lParam&0xffff;
// FireViewChange();
//
// return 0;
//}
//LRESULT CHControl::OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//{
// // 每秒钟和数据库核对一次
//
// return 0;
//}
STDMETHODIMP CHControl::get_DrawBkColor(OLE_COLOR* pVal)
{
*pVal = FD_BkColor;
return S_OK;
}
STDMETHODIMP CHControl::put_DrawBkColor(OLE_COLOR newVal)
{
FD_BkColor = newVal;
return S_OK;
}
STDMETHODIMP CHControl::get_PressColor(OLE_COLOR* pVal)
{
*pVal = FD_PressColor;
return S_OK;
}
STDMETHODIMP CHControl::put_PressColor(OLE_COLOR newVal)
{
FD_PressColor = newVal;
return S_OK;
}
void CHControl::DrawLogic(HDC device, RECT bounds)
{
COLORREF temp_color;
HPEN hOldPen,hPen;
RECT r1,r2,r3,r4,r5;
int i,j,k;
i = (bounds.bottom - bounds.top)/10;
r4 = CRect(bounds.left,bounds.top,bounds.right,bounds.top + i); //上面的窄条
r5 = CRect(bounds.left,bounds.bottom - i,bounds.right,bounds.bottom); //下面的窄条
r2 = CRect(bounds.right-80,r4.bottom,bounds.right-40,r5.top);
r3 = CRect(bounds.right-40,r4.bottom,bounds.right,r5.top);
r1 = CRect(bounds.left,r4.bottom,bounds.right-80,r5.top);
RECT r01,r02,r03,r04,r05,r06,r07,r08;
i = (bounds.bottom - bounds.top)/10;
j = (bounds.right - bounds.left)/3;
k = (bounds.right - bounds.left)/4;
r01 = CRect(bounds.left, bounds.top, bounds.left+j/2, bounds.top + i);
r08 = CRect(bounds.left+j/2, bounds.top, bounds.left+j, bounds.top + i);
r02 = CRect(bounds.left+j, bounds.top, bounds.left+2*j, bounds.top + i);
r03 = CRect(bounds.left+2*j, bounds.top, bounds.right, bounds.top+i);
r04 = CRect(bounds.left, bounds.bottom-i, bounds.left+k, bounds.bottom);
r05 = CRect(bounds.left+k, bounds.bottom-i, bounds.left+2*k, bounds.bottom);
r06 = CRect(bounds.left+k*2, bounds.bottom-i, bounds.left+3*k, bounds.bottom);
r07 = CRect(bounds.left+k*3, bounds.bottom-i, bounds.right, bounds.bottom);
OleTranslateColor(FD_BkColor,NULL,&temp_color);
HBRUSH hBrush = CreateSolidBrush(temp_color);//m_clrBackColor
HBRUSH hOldBrush = (HBRUSH)SelectObject(device, hBrush);
Rectangle(device, bounds.left, bounds.top, bounds.right, bounds.bottom);
Rectangle(device, r1.left, r1.top, r1.right, r1.bottom);
Rectangle(device, r2.left, r2.top, r2.right, r2.bottom);
Rectangle(device, r3.left, r3.top, r3.right, r3.bottom);
//-----------------------------------------------------------------------------------------------------------------------------------
int r;
CPoint point(0,0);
HFONT hFont,hOldFont;
hFont = CreateFont(FD_FontSize, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, OUT_STROKE_PRECIS, CLIP_STROKE_PRECIS, DRAFT_QUALITY, VARIABLE_PITCH | FF_SWISS, _T("Arial"));
//--------------------------------------------------------------- 字体处理的范例
//绘制仪表的背景色
OleTranslateColor(FD_BkColor,NULL,&temp_color);
hBrush = CreateSolidBrush(temp_color);
hOldBrush = (HBRUSH )SelectObject(device,hBrush);
Rectangle(device,r2.left,r2.top,r2.right,r2.bottom); //背景色,灰色
SelectObject(device,hOldBrush);
DeleteObject(hBrush);
FD_Width = r2.right-r2.left; //仪表的默认尺寸,高度和宽度和
FD_Height = r2.bottom-r2.top; //做到和矩形框完全一致
FD_FrameLength = FD_Height/20; //油管两头框架的长度
FD_FrameRadius = FD_Width/6; //默认的框架半径
FD_PipeLength = FD_Height - 2*FD_FrameLength; //等与总高度-油管两头框架的长度
FD_PipeRadius = FD_Width/7; //默认的油管半径
FD_Origin.x = r2.left +FD_Width/6; //仪表的内部坐标系原点
FD_Origin.y = r2.bottom - FD_FrameLength;
FD_BigGridLength = FD_FrameRadius/2;
FD_SmallGridLength = FD_BigGridLength/2;
// COLORREF temp_color = 0; //绘制框架内表面
OleTranslateColor(FD_FrameBackColor,NULL,&temp_color);
r = (int)(0.8 * FD_FrameRadius);
for(i = 0; i < r; i ++)
{
temp_color = GetNextColor(temp_color, 0.8);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -