📄 mychild1.cpp
字号:
HPEN hOldPen = (HPEN)SelectObject (hdc, hpen);
int Width = 300, Height = 24;
int x=CtrlX+240, y=CtrlY-45;
r.left = x-5; r.top = y-5;
r.right = x+Width+5; r.bottom = y+Height+5;
DrawBorder (hdc, r, 1, 0);
Rectangle (hdc, x, y, x+Width, y+Height);
SetTextColor(hdc, RGB(255,255,255));
SetBkColor(hdc, color1);
wsprintf(Text, "%s", "串 行 通 道 状 态 图");
TextOut( hdc, x+80, y+4, Text, lstrlen(Text));
// 为每个通道状态显示画背景
// int x, y;
for (int i=0; i<TotalChNum; i++)
{
x = (i%RowNum)*cwWidth+CtrlX;
y = (i/RowNum)*cwHeight+CtrlY;
SelectObject (hdc, hBackBrush1);
SelectObject (hdc, hpen);
Rectangle(hdc, x, y, x+cwWidth, y+19);
wsprintf(Text, "通道%d", i);
SetBkColor (hdc, color1);
SetTextColor(hdc,RGB(255,255,255));
TextOut(hdc, x+40, y+1, Text, lstrlen(Text));
SelectObject (hdc, (HBRUSH)GetStockObject(WHITE_BRUSH));
Rectangle(hdc, x+40, y+18, x+cwWidth, y+18+54+60);
SelectObject (hdc, hBackBrush2);
Rectangle(hdc, x, y+18, x+41, y+18+54+60);
Rectangle (hdc, x+40, y+52, x+cwWidth, y+18+54);
SetBkColor (hdc, color2);
SetTextColor(hdc,RGB(0,0,0));
for (int j=0; j<1; j++) //old=3
{
MoveTo(hdc, x, y+18+54+20*j);
LineTo(hdc, x+cwWidth, y+18+54+20*j);
TextOut(hdc, x+4, y+18+56+20*j, ITile[j], lstrlen(ITile[j]));
}
SelectObject (hdc, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
Rectangle(hdc, x+8, y+27, x+8+28, y+27+36);
SelectObject (hdc, hBackBrush1);
WORD sto=(lpChannelParam+i)->CHStatus & ChOpen;
if (sto)
{
Rectangle(hdc, x+8, y+27, x+8+27, y+27+18);
SelectObject (hdc, (HPEN)GetStockObject(WHITE_PEN));
MoveTo(hdc, x+9+25, y+28);
LineTo(hdc, x+9, y+28);
LineTo(hdc, x+9, y+27+18);
}
else
{
Rectangle(hdc, x+8, y+27+18, x+8+27, y+27+35);
SelectObject (hdc, (HPEN)GetStockObject(WHITE_PEN));
MoveTo(hdc, x+9+25, y+27+18);
LineTo(hdc, x+9, y+27+18);
LineTo(hdc, x+9, y+27+35);
}
SetBkColor (hdc, RGB(192,192,192));
//tzc
if (sto)SetTextColor(hdc,RGB(0,255,0));else SetTextColor(hdc,RGB(255,0,0));
TextOut(hdc, x+9+sto*2, y+28+18*sto, status[sto], lstrlen(status[sto]));
//tzc
//tzc
SelectObject(hdc,CreatePen(PS_SOLID, 1, RGB(192,192,192)));
Rectangle(hdc, x+42, y+73, x+128, y+100);
//
}
SelectObject (hdc, hOldBrush);
DeleteObject (hBackBrush1);
DeleteObject (hBackBrush2);
SelectObject (hdc, hOldPen);
DeleteObject (hpen);
FreshChStatus();
}
void TMyChildWnd1::FreshChStatus()
{
RECT r;
// char *Chst[]={"通道未用","通道关闭","通道正常","通道故障","误码率高"};
char *Chst[]=
{"通道未用","通道关闭","通讯中断","字符无效","失 步","误码率高","空 发","通道正常"};
COLORREF color[8]={RGB(255,128,0),RGB(0,0,255),RGB(255,0,0),RGB(255,0,255),
RGB(0,128,64),RGB(0,255,128),RGB(128,0,64),RGB(255,255,255)};
HBRUSH hbr[8];
char Text[16];
HDC hdc = GetDC(HWindow);
COLORREF color1=BackColor;
COLORREF color2=RGB(192,208,214);
HBRUSH hBackBrush1 = CreateSolidBrush (color1);
for (int i=0; i<8; i++)
hbr[i] = CreateSolidBrush (color[i]);
HBRUSH hOldBrush = (HBRUSH)SelectObject (hdc, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
HPEN hpen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
HPEN hOldPen = (HPEN)SelectObject (hdc, hpen);
int x, y, no, fcolor;
WORD chs;
for (i=0; i<TotalChNum; i++)
{
x = (i%RowNum)*cwWidth+CtrlX;
y = (i/RowNum)*cwHeight+CtrlY;
chs = (lpChannelParam+i)->CHStatus;
if (!(lpChannelParam+i)->CHValidFlag) no=0;
else if (!(chs&ChOpen)) no=1;
else if (chs&CommBreakFlag1) no=2;// bit11 // 通讯中断
else if (chs&CharInvFlag1) no=3;// bit12 // 字符无效
else if (chs&NoSyncFlag1) no=4;// bit13 // 失步
else if (chs&ErrDataFlag1) no=5;// bit15 // 误码率高
else if (chs&NoTxFlag1) no=6;// bit16 // 空发
else no=7;
// else if (1) no=2;
if (no==0) fcolor=7;
else if (no==1) fcolor=1;
else if (no==7) fcolor=StartNo;
else fcolor=3;
if (StartNo==7) fcolor=7;
SelectObject (hdc, hbr[fcolor]);
if (StartNo==7)
{
if (no!=1)
{
Rectangle (hdc, x+42, y+24, x+54+6*12, y+24+8);
Rectangle (hdc, x+42, y+40, x+54+6*12, y+40+8);
}
}
else
{
Rectangle (hdc, x+42+StartNo*12, y+24, x+54+StartNo*12, y+24+8);
Rectangle (hdc, x+42+(6-StartNo)*12, y+40, x+54+(6-StartNo)*12, y+40+8);
}
// SetBkColor (hdc, color[no]);
// SetTextColor (hdc, RGB(255,255,255));
SetBkColor (hdc, color2);
SetTextColor (hdc, color[no]);
TextOut (hdc, x+52, y+54, Chst[no], lstrlen(Chst[no]));
// SetBkColor (hdc, RGB(255,255,255));
SetBkColor (hdc, RGB(192,192,192));
SetTextColor (hdc, RGB(0,0,0));
//tzc
sprintf(Text, "%8d", (lpChannelParam+i)->ErrDataNum);
TextOut (hdc, x+60, y+54+20, Text, lstrlen(Text));
/*
sprintf(Text, "%3.1f\%", (lpChannelParam+i)->ErrRate*100.0);
TextOut (hdc, x+60, y+54+20, Text, lstrlen(Text));
sprintf(Text, "%d小时%d分", (lpChannelParam+i)->CHWorkTime/3600,
((lpChannelParam+i)->CHWorkTime%3600)/60);
TextOut (hdc, x+42, y+54+40, Text, lstrlen(Text));
sprintf(Text, "%d小时%d分", (lpChannelParam+i)->CHStopTime/3600,
((lpChannelParam+i)->CHStopTime%3600)/60);
TextOut (hdc, x+42, y+54+60, Text, lstrlen(Text));
*/
}
StartNo = (++StartNo) & 7;
SelectObject (hdc, hOldBrush);
DeleteObject (hBackBrush1);
for (i=0; i<8; i++) DeleteObject (hbr[i]);
SelectObject (hdc, hOldPen);
DeleteObject (hpen);
ReleaseDC(HWindow,hdc);
}
void TMyChildWnd1::DrawRealData(HDC hdc)
{
RECT Rect;
char *Nam[]={"遥信","遥测","电量"};
HBRUSH hOldBrush = (HBRUSH)SelectObject (hdc, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
HBRUSH hBackBrush = CreateSolidBrush (BackColor);
HPEN hpen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
HPEN hOldPen = (HPEN)SelectObject (hdc, hpen);
// 为静态控制画背景,如站名显示
Rectangle (hdc, CtrlX+80, CtrlY, CtrlX+100+4*132, CtrlY+25);
for (int i=0; i<4; i++)
{
MoveTo(hdc, CtrlX+106+i*132, CtrlY);
LineTo(hdc, CtrlX+100+i*132, CtrlY+6);
LineTo(hdc, CtrlX+100+i*132, CtrlY+25);
}
SelectObject (hdc, hBackBrush);
SetBkMode (hdc, TRANSPARENT);
SetBkColor (hdc, BackColor);
int Width = 475, Height = 24;
int x=CtrlX+72, y=CtrlY-45;
Rect.left = x-5; Rect.top = y-5;
Rect.right = x+Width+5; Rect.bottom = y+Height+5;
DrawBorder (hdc, Rect, 1, 0); //PrinterFlag);
Rectangle (hdc, x, y, x+Width, y+Height);
cwWidth = 48+144+128; cwHeight = 21;
x=CtrlX+5; y=CtrlY+30;
Rect.left = x-5; Rect.top = y-5;
Rect.right = x+cwWidth*2+5; Rect.bottom = y+cwHeight*17+5;
DrawBorder (hdc, Rect, 1, 0); //PrinterFlag);
Rectangle (hdc, x, y+cwHeight, x+cwWidth*2, y+cwHeight*17);
char Str[32];
SelectObject (hdc, (HPEN)GetStockObject(WHITE_PEN));
for (i=0; i<2; i++)
{
MoveTo (hdc, x+i*cwWidth, y+cwHeight);
LineTo (hdc, x+i*cwWidth, y);
LineTo (hdc, x+i*cwWidth+47, y);
MoveTo (hdc, x+i*cwWidth+48, y+cwHeight);
LineTo (hdc, x+i*cwWidth+48, y);
LineTo (hdc, x+i*cwWidth+48+143, y);
MoveTo (hdc, x+i*cwWidth+48+144, y+cwHeight);
LineTo (hdc, x+i*cwWidth+48+144, y);
LineTo (hdc, x+i*cwWidth+48+144+127, y);
sprintf(Str, "%s", "序号");
TextOut(hdc, x+i*cwWidth+8, y+2, Str, lstrlen(Str));
sprintf(Str, "%s名称", Nam[WinFlag-REALYXWINDOW]);
TextOut(hdc, x+i*cwWidth+84, y+2, Str, lstrlen(Str));
sprintf(Str, "%s值", Nam[WinFlag-REALYXWINDOW]);
TextOut(hdc, x+i*cwWidth+224, y+2, Str, lstrlen(Str));
}
SelectObject (hdc, hpen);
for (i=0; i<2; i++)
{
MoveTo (hdc, x+i*cwWidth, y+cwHeight);
LineTo (hdc, x+i*cwWidth+47, y+cwHeight);
LineTo (hdc, x+i*cwWidth+47, y);
LineTo (hdc, x+i*cwWidth+47, y+17*cwHeight);
MoveTo (hdc, x+i*cwWidth+48, y+cwHeight);
LineTo (hdc, x+i*cwWidth+48+143, y+cwHeight);
LineTo (hdc, x+i*cwWidth+48+143, y);
LineTo (hdc, x+i*cwWidth+48+143, y+17*cwHeight);
MoveTo (hdc, x+i*cwWidth+48+144, y+cwHeight);
LineTo (hdc, x+i*cwWidth+48+144+127, y+cwHeight);
LineTo (hdc, x+i*cwWidth+48+144+127, y);
LineTo (hdc, x+i*cwWidth+48+144+127, y+17*cwHeight);
}
for (i=1; i<17; i++)
{
MoveTo (hdc, x, y+i*cwHeight);
LineTo (hdc, x+2*cwWidth, y+i*cwHeight);
}
if (CurrentNo >= TotalStaNum) CurrentNo = 0;
GetName(RTUDB, CurrentNo, 0, Str);
WORD num;
if (WinFlag==REALYXWINDOW)
{
num = GetRcdNum(YXDB, CurrentNo);
DispPage = min(DispPage, max(0,(num-1)/32));
}
else if (WinFlag==REALYCWINDOW)
{
num = GetRcdNum(YCDB, CurrentNo);
DispPage = min(DispPage, max(0,(num-1)/32));
}
else if (WinFlag==REALKWHWINDOW)
{
num = GetRcdNum(KWHDB, CurrentNo);
DispPage = min(DispPage, max(0,(num-1)/32));
}
COLORREF color = GetColor (BackColor);
SetTextColor (hdc, color);
for (i=0; i<32; i++)
{
wsprintf(Str, "%03d", DispPage*32+i);
if (Str[0]=='0')
{
Str[0]=' ';
if (Str[1]=='0') Str[1]=' ';
}
TextOut(hdc, x+(i/16)*cwWidth+10, y+(i%16+1)*cwHeight+3, Str, lstrlen(Str));
}
SetTextColor(hdc,RGB(0,128,128));//RGB(255,255,255));tzc 遥测遥信电度名称
char Name[32];
switch (WinFlag)
{
case REALYXWINDOW:
for (i=DispPage*32; i<min((DispPage+1)*32, num); i++)
{
GetName(YXDB, CurrentNo, i, Name);
TextOut(hdc, x+((i%32)/16)*cwWidth+56, y+((i%32)%16+1)*cwHeight+2, Name, lstrlen(Name));
}
break;
case REALYCWINDOW:
for (i=DispPage*32; i<min((DispPage+1)*32, num); i++)
{
GetName(YCDB, CurrentNo, i, Name);
TextOut(hdc, x+((i%32)/16)*cwWidth+56, y+((i%32)%16+1)*cwHeight+2, Name, lstrlen(Name));
}
break;
case REALKWHWINDOW:
for (i=DispPage*32; i<min((DispPage+1)*32, num); i++)
{
GetName( KWHDB, CurrentNo, i, Name);
TextOut(hdc, x+((i%32)/16)*cwWidth+56, y+((i%32)%16+1)*cwHeight+2, Name, lstrlen(Name));
}
break;
}
DeleteObject ((HBRUSH)SelectObject (hdc, hOldBrush));
SelectObject (hdc, hOldPen);
DeleteObject (hpen);
FreshRealData();
}
void TMyChildWnd1::FreshRealData()
{
char Str[100];
HDC hdc = GetDC(HWindow);
SetBkColor (hdc, BackColor);
int x=CtrlX+5, y=CtrlY+30;
int totalnum;
char rtuname[32];
/*
//tzc
StartNo = min(StartNo+4, max(0,TotalChNum-4));
if (CurrentNo<=StartNo+4&&CurrentNo>=StartNo)
{
int temp1=CurrentNo/4*4;
COLORREF color1;
for (int i=0;i<4;i++,temp1++)
{
if (temp1>TotalStaNum) wsprintf (Str," ");
else GetName(RTUDB, temp1, 0, Str);
if (temp1==CurrentNo) color1 = GetColor (RGB(255,0,0));
else color1 = GetColor (RGB(0,0,0));
SetTextColor (hdc, color1);
TextOut(hdc, 131+i*132,65, Str, lstrlen(Str));
}
}
//tzc
*/
GetName(RTUDB, CurrentNo, 0, rtuname);
switch(WinFlag)
{
case REALYXWINDOW:
wsprintf(Str, "实时遥信数据区___(%d)%s 当前通道号:%d ", CurrentNo,rtuname, (lpStaParam+CurrentNo)->CurrUsedCh);
totalnum = GetRcdNum(YXDB, CurrentNo);
break;
case REALYCWINDOW:
totalnum = GetRcdNum(YCDB, CurrentNo);
wsprintf(Str, "实时遥测数据区___ (%d)%s 当前通道号:%d ", CurrentNo,rtuname, (lpStaParam+CurrentNo)->CurrUsedCh);
totalnum = GetRcdNum(YCDB, CurrentNo);
break;
case REALKWHWINDOW:
wsprintf(Str, "实时电度数据区___(%d)%s 当前通道号:%d ", CurrentNo,rtuname, (lpStaParam+CurrentNo)->CurrUsedCh);
totalnum = GetRcdNum(KWHDB, CurrentNo);
break;
}
SetTextColor(hdc,RGB(0,0,0));//RGB(255,255,255));
TextOut(hdc, CtrlX+100, CtrlY-42, Str, lstrlen(Str));
switch (WinFlag)
{
case REALYXWINDOW:
{
for (int i=DispPage*32; i<min((DispPage+1)*32,totalnum); i++)
{
if ((BYTE)GetValue(YXDB, CurrentNo, i)&1)
{
SetTextColor(hdc,RGB(255, 0, 0));
wsprintf(Str, "%s ", "合");
}
else
{
SetTextColor(hdc,RGB(0, 255, 0));
wsprintf(Str, "%s ", "分");
}
TextOut(hdc, x+((i%32)/16)*cwWidth+240, y+((i%32)%16+1)*cwHeight+2, Str, lstrlen(Str));
}
}
break;
case REALYCWINDOW:
{
int ycv,j;
BYTE ycp;
float coe;
char Str1[10];
for (int i=DispPage*32; i<min((DispPage+1)*32,totalnum); i++)
{
WORD wycv = (WORD)GetValue(YCDB, CurrentNo, i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -