//#include "stdafx.h" #include "display.h" #include "commport.h" extern SIO_PARAM_DEF SioParam[]; extern int iCurDevIdx; extern DEV_DEF DevParam[]; HWND hMainWnd; int RealDataDispFlag; int CurPort; int DispType = 0; int ListIndex = 0; // 显示序号索引起始 int ItemNumOfPage; // 页显示项目数 COLORREF dwColorVal[16] = // 显示颜色定义 { RGB(255,255,255), RGB(128,128,128), RGB(255, 0, 0), RGB(255,255, 0), RGB( 0,255, 0), RGB( 0,255,255), RGB( 0, 0,255), RGB(255, 0,255), RGB(192,192,192), RGB( 0, 0, 0), RGB(128, 0, 0), RGB(128,128, 0), RGB( 0,128, 0), RGB( 0,128,128), RGB( 0, 0,128), RGB(128, 0,128) }; void RealAiDataDisp( HDC hdc ) { UINT xWd, yHg, lineh, tmp; int i, j, total, idx, itemofline; char szbuf[256]; RECT rc; AI_DEF *aiptr; float sp; int pos[6]; GetClientRect( hMainWnd, &rc ); itemofline = 2; CaculateWH( hdc, &xWd, &yHg, (char*)"行距" ); lineh = yHg + 5; rc.top = 10; SetTextColor( hdc, dwColorVal[BLUE] ); // 显示标题 sprintf( szbuf,"端口%02d 实时遥测数据信息", CurPort + 1 ); DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); rc.top += (lineh + 5); SetTextColor( hdc, dwColorVal[BLACK] ); // 计算显示位置 pos[0] = 0; pos[3] = rc.right / 2; tmp = 0; CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); tmp += xWd; pos[1] = pos[0] + xWd; pos[4] = pos[3] + xWd; CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); tmp += xWd; pos[2] = pos[1] + xWd; pos[5] = pos[4] + xWd; CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" ); tmp += xWd; sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4); pos[0] += (int)sp; pos[1] += (int)(sp*2); pos[2] += (int)(sp*3); pos[3] += (int)(sp); pos[4] += (int)(sp*2); pos[5] += (int)(sp*3); // 显示项目名称 for ( i = 0; i < itemofline; i++ ) { sprintf( szbuf, (char*)"序号" ); rc.left = pos[i*3]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); sprintf( szbuf, (char*)"测点名称" ); rc.left = pos[i*3+1]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); sprintf( szbuf, (char*)"测点原值" ); rc.left = pos[i*3+2]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); } rc.top += lineh; ItemNumOfPage = (rc.bottom - rc.top) / lineh; if( !IsBaoHuPtr(CurPort) ) return; // 计算总行数 total = (SioParam[CurPort].m_psBaoHu->AiNum + itemofline - 1) / itemofline; // 调整显示的起始位置 if ( total < ItemNumOfPage ) ListIndex = 0; if ( (ListIndex + ItemNumOfPage) > total ) ListIndex = total - ItemNumOfPage; if ( ListIndex < 0 ) ListIndex = 0; // 显示输出 idx = ListIndex * itemofline; aiptr = (AI_DEF*)SioParam[CurPort].m_psBaoHu->AiPtr; if( !aiptr ) return; for ( i = 0; (i < ItemNumOfPage) && (idx < SioParam[CurPort].m_psBaoHu->AiNum); i++ ) { for ( j = 0; j < itemofline; j++ ) { if((idx + j) >= SioParam[CurPort].m_psBaoHu->AiNum) break; sprintf( szbuf, "%03d", idx + j + 1 ); rc.left = pos[j*3+0]; CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); rc.right = rc.left + xWd; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); sprintf( szbuf, "遥测%03d", idx + j + 1 ); rc.left = pos[j*3+1]; CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); rc.right = rc.left + xWd; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); sprintf( szbuf, "0x%04x", aiptr[idx+j].RawValue & 0xffff ); rc.left = pos[j*3+2]; CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" ); rc.right = rc.left + xWd; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); } idx += itemofline; rc.top += lineh; } } void RealDiDataDisp( HDC hdc ) { UINT xWd, yHg, lineh, tmp; int i, j, total, idx, itemofline; char szbuf[256], stchar = 1; RECT rc; DI_DEF *diptr; float sp; int pos[6]; GetClientRect( hMainWnd, &rc ); CaculateWH( hdc, &xWd, &yHg, (char*)"行距" ); lineh = yHg + 5; itemofline = 2; rc.top = 10; SetTextColor( hdc, dwColorVal[BLUE] ); // 显示标题 sprintf( szbuf,"端口%02d 实时遥信数据信息", CurPort + 1 ); DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); rc.top += (lineh + 5); SetTextColor( hdc, dwColorVal[BLACK] ); // 计算显示位置 pos[0] = 0; pos[3] = rc.right / 2; tmp = 0; CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); tmp += xWd; pos[1] = pos[0] + xWd; pos[4] = pos[3] + xWd; CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); tmp += xWd; pos[2] = pos[1] + xWd; pos[5] = pos[4] + xWd; CaculateWH( hdc, &xWd, &yHg, (char*)"状态" ); tmp += xWd; sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4); pos[0] += (int)sp; pos[1] += (int)(sp*2); pos[2] += (int)(sp*3); pos[3] += (int)(sp); pos[4] += (int)(sp*2); pos[5] += (int)(sp*3); // 显示项目名称 for ( i = 0; i < itemofline; i++ ) { sprintf( szbuf, (char*)"序号" ); rc.left = pos[i*3+0]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); sprintf( szbuf, (char*)"测点名称" ); rc.left = pos[i*3+1]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); sprintf( szbuf, (char*)"状态" ); rc.left = pos[i*3+2]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); } rc.top += lineh; ItemNumOfPage = (rc.bottom - rc.top) / lineh; if( !IsBaoHuPtr(CurPort) ) return; // 计算总行数 total = (SioParam[CurPort].m_psBaoHu->DiNum + itemofline - 1) / itemofline; // 调整显示的起始位置 if ( total < ItemNumOfPage ) ListIndex = 0; if ( (ListIndex + ItemNumOfPage) > total ) ListIndex = total - ItemNumOfPage; if ( ListIndex < 0 ) ListIndex = 0; // 显示输出 idx = ListIndex * itemofline; diptr = (DI_DEF*)SioParam[CurPort].m_psBaoHu->DiPtr; if( !diptr ) return; for ( i = 0; (i < ItemNumOfPage) && (idx < SioParam[CurPort].m_psBaoHu->DiNum); i++ ) { for ( j = 0; j < itemofline; j++ ) { if((idx + j) >= SioParam[CurPort].m_psBaoHu->DiNum) break; sprintf( szbuf, "%03d", idx + j + 1 ); rc.left = pos[j*3+0]; CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); rc.right = rc.left + xWd; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); sprintf( szbuf, "遥信%03d", idx + j + 1 ); rc.left = pos[j*3+1]; CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); rc.right = rc.left + xWd; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); sprintf( szbuf, "%s", diptr[idx+j].Status ? (char*)"合" : (char*)"分" ); rc.left = pos[j*3+2]; CaculateWH( hdc, &xWd, &yHg, (char*)"状态" ); rc.right = rc.left + xWd; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); } idx += itemofline; rc.top += lineh; } } void RealPiDataDisp( HDC hdc ) { UINT xWd, yHg, lineh, tmp; int i, j, total, idx, itemofline; char szbuf[256]; RECT rc; PI_DEF *piptr; float sp; int pos[6]; GetClientRect( hMainWnd, &rc ); itemofline = 2; CaculateWH( hdc, &xWd, &yHg, (char*)"行距" ); lineh = yHg + 5; rc.top = 10; SetTextColor( hdc, dwColorVal[BLUE] ); // 显示标题 sprintf( szbuf,"端口%02d 实时电度数据信息", CurPort + 1 ); DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); rc.top += (lineh + 5); SetTextColor( hdc, dwColorVal[BLACK] ); // 计算显示位置 pos[0] = 0; pos[3] = rc.right / 2; tmp = 0; CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); tmp += xWd; pos[1] = pos[0] + xWd; pos[4] = pos[3] + xWd; CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); tmp += xWd; pos[2] = pos[1] + xWd; pos[5] = pos[4] + xWd; CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" ); tmp += xWd; sp = ((float)rc.right - (float)tmp*itemofline) / (itemofline*4); pos[0] += (int)sp; pos[1] += (int)(sp*2); pos[2] += (int)(sp*3); pos[3] += (int)(sp); pos[4] += (int)(sp*2); pos[5] += (int)(sp*3); // 显示项目名称 for ( i = 0; i < itemofline; i++ ) { sprintf( szbuf, (char*)"序号" ); rc.left = pos[i*3+0]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); sprintf( szbuf, (char*)"测点名称" ); rc.left = pos[i*3+1]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); sprintf( szbuf, (char*)"测点原值" ); rc.left = pos[i*3+2]; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); } rc.top += lineh; ItemNumOfPage = (rc.bottom - rc.top) / lineh; if( !IsBaoHuPtr(CurPort) ) return; // 计算总行数 total = (SioParam[CurPort].m_psBaoHu->PiNum + itemofline - 1) / itemofline; // 调整显示的起始位置 if ( total < ItemNumOfPage ) ListIndex = 0; if ( (ListIndex + ItemNumOfPage) > total ) ListIndex = total - ItemNumOfPage; if ( ListIndex < 0 ) ListIndex = 0; // 显示输出 idx = ListIndex * itemofline; piptr = (PI_DEF*)SioParam[CurPort].m_psBaoHu->PiPtr; if( !piptr ) return; for ( i = 0; (i < ItemNumOfPage) && (idx < SioParam[CurPort].m_psBaoHu->PiNum); i++ ) { for ( j = 0; j < itemofline; j++ ) { if((idx + j) >= SioParam[CurPort].m_psBaoHu->PiNum) break; sprintf( szbuf, "%03d", idx + j + 1 ); rc.left = pos[j*3+0]; CaculateWH( hdc, &xWd, &yHg, (char*)"序号" ); rc.right = rc.left + xWd; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); sprintf( szbuf, "电度%03d", idx + j + 1); rc.left = pos[j*3+1]; CaculateWH( hdc, &xWd, &yHg, (char*)"测点名称" ); rc.right = rc.left + xWd; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_CENTER ); sprintf( szbuf, "0x%08x", piptr[idx+j].RawValue ); rc.left = pos[j*3+2]; CaculateWH( hdc, &xWd, &yHg, (char*)"测点原值" ); // wen 2004.11.19 显示的长度是名称的1.5倍 //rc.right = rc.left + xWd; //DrawText( hdc, szbuf, strlen(szbuf), &rc, DT_CENTER ); rc.right = rc.left + xWd/4*6; DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); } idx += itemofline; rc.top += lineh; } } void WatchDataDisp( HDC hdc ) { UINT xWd, yHg, lineh; int i, j, total, idx, type; char szbuf[256]; RECT rc; GetClientRect( hMainWnd, &rc ); CaculateWH( hdc, &xWd, &yHg, (char*)"行距" ); lineh = yHg + 5; rc.top = 10; if ( DevParam[iCurDevIdx].WatchDispLine.LineCnt == 0 ) { sprintf( szbuf, "当前没有数据....." ); DrawText(hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); return; } ItemNumOfPage = (rc.bottom - rc.top) / lineh; total = DevParam[iCurDevIdx].WatchDispLine.LineCnt; if ( RealDataDispFlag ) ListIndex = 100000; // 调整显示的起始位置 if ( total < ItemNumOfPage ) ListIndex = 0; if ( (ListIndex + ItemNumOfPage) > total ) ListIndex = total - ItemNumOfPage; if ( ListIndex < 0 ) ListIndex = 0; // 寻找数据起始位置 idx = DevParam[iCurDevIdx].WatchDispLine.Rear - total; if ( idx < 0 ) idx += MAX_DISP_LINE; // 显示起始位置 idx += ListIndex; for ( i = 0; i < min(ItemNumOfPage, total); i++ ) { j = (idx + i) % MAX_DISP_LINE; type = DevParam[iCurDevIdx].WatchDispLine.Line[j][0]; if ( type == 'R' ) // 接收数据 SetTextColor( hdc, dwColorVal[BLUE] ); else SetTextColor( hdc, dwColorVal[MAGENTA] ); strcpy( szbuf, (char*)&DevParam[iCurDevIdx].WatchDispLine.Line[j][1] ); DrawText( hdc, (CONST WCHAR*)szbuf, strlen(szbuf), &rc, DT_LEFT ); rc.top += lineh; } } //*************************************************************** //* 新字体函数? * //*************************************************************** HFONT NewFont( int nFSize ) { /* WCHAR typeface[32] = (WCHAR *)"宋体"; LOGFONT LogFont = { 0, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, //OUT_STROKE_PRECIS, OUT_STRING_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH, typeface //"新宋体" //"黑体" //"隶书" //"幼圆" //"仿宋_GB2312" }; LogFont.lfWidth = (LONG)((float)nFSize*.618); LogFont.lfHeight = (LONG)nFSize; strcpy( LogFont.lfFaceName, "Lee宋体" ); return( CreateFontIndirect( &LogFont ));*/ return NULL; } void DataDisp( HWND hWnd ) { HDC hdc; HFONT hFont; int nFSize; hdc = GetDC( hWnd ); if( WATCH_DATA_DISP != DispType) nFSize = 16; else nFSize = 12; hFont = (HFONT)SelectObject( hdc, NewFont( nFSize ) ); if( !IsBaoHuPtr(CurPort) ) return; switch( DispType ) { case AI_DATA_DISP: if(PROV_PROTOCOL != SioParam[CurPort].m_psBaoHu->PortType) RealAiDataDisp( hdc ); break; case DI_DATA_DISP: if(PROV_PROTOCOL != SioParam[CurPort].m_psBaoHu->PortType) RealDiDataDisp( hdc ); break; case PI_DATA_DISP: if(PROV_PROTOCOL != SioParam[CurPort].m_psBaoHu->PortType) RealPiDataDisp( hdc ); break; case WATCH_DATA_DISP: WatchDataDisp( hdc ); break; } DeleteObject( SelectObject(hdc, hFont) ); ReleaseDC( hWnd, hdc ); } //*************************************************************** //* 计算字串显示宽度和高度 * //*************************************************************** void CaculateWH( HDC hdc, UINT *xWidth, UINT *yHeight, char *szStr ) { RECT rc; DrawText( hdc, (CONST WCHAR*)szStr, strlen(szStr), &rc, DT_CALCRECT ); *xWidth = rc.right - rc.left; *yHeight = rc.bottom - rc.top; } //**************************************************************** //* 显示数据上页? * //**************************************************************** void PageUp( void ) { ListIndex -= ItemNumOfPage; if ( ListIndex < 0 ) ListIndex = 0; } //*************************************************************** //* 显示数据下页? * //*************************************************************** void PageDown( void ) { ListIndex += ItemNumOfPage; } //*************************************************************** //* 显示端口最后一页数据 * //*************************************************************** void PageEnd( void ) { ListIndex = 100000; } //*************************************************************** //* 显示端口最前一页数据? * //*************************************************************** void PageHome( void ) { ListIndex = 0; } void LineUp( void ) { ListIndex--; if ( ListIndex < 0 ) ListIndex = 0; } //*************************************************************** //* 显示下移一行? * //*************************************************************** void LineDown( void ) { ListIndex++; } int GetCurPort() { return CurPort; } int IsRealDataDisp() { return RealDataDispFlag; }