📄 tsqview.cpp
字号:
// TsqView.cpp : implementation of the CTsqView class
//
#include "stdafx.h"
#include "Tsq.h"
#include "TsqDoc.h"
#include "TsqView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTsqView
IMPLEMENT_DYNCREATE(CTsqView, CFormView)
BEGIN_MESSAGE_MAP(CTsqView, CFormView)
//{{AFX_MSG_MAP(CTsqView)
ON_WM_TIMER()
ON_WM_CREATE()
ON_BN_CLICKED(IDC_BT_CZ, OnBtCz)
ON_BN_CLICKED(IDC_BT_ZCD, OnBtZcd)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTsqView construction/destruction
CTsqView::CTsqView()
: CFormView(CTsqView::IDD)
{
//{{AFX_DATA_INIT(CTsqView)
m_dykd = 0.0f;
m_mt_dykd = 0.0f;
m_dyph = 0.0f;
m_mt_dyph = 0.0f;
m_jzpl = 0.0f;
m_jzyg = 0.0f;
m_dqst = 0.0f;
m_dysc = 0.0f;
m_glgd = 0.0f;
m_plgd = 0.0f;
m_dqkx = 0;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CTsqView::~CTsqView()
{
// if(pFont)
// delete pFont;
}
void CTsqView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTsqView)
DDX_Text(pDX, IDC_ET_DYKD, m_dykd);
DDX_OCFloat(pDX, IDC_METERCTRL1, DISPID(5), m_mt_dykd);
DDX_Text(pDX, IDC_ET_DYPH, m_dyph);
DDX_OCFloat(pDX, IDC_METERCTRL2, DISPID(5), m_mt_dyph);
DDX_Text(pDX, IDC_ET_JZPL, m_jzpl);
DDX_Text(pDX, IDC_ET_JZYG, m_jzyg);
DDX_Text(pDX, IDC_ET_DQST, m_dqst);
DDX_Text(pDX, IDC_ET_DYSC, m_dysc);
DDX_Text(pDX, IDC_ET_GLGD, m_glgd);
DDX_Text(pDX, IDC_ET_PLGD, m_plgd);
DDX_Text(pDX, IDC_ET_DQKX, m_dqkx);
//}}AFX_DATA_MAP
}
BOOL CTsqView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style=WS_CHILD;
return CFormView::PreCreateWindow(cs);
}
void CTsqView::OnInitialUpdate()
{
m_CzBt.SubclassDlgItem( IDC_BT_CZ, this );
m_ZcdBt.SubclassDlgItem( IDC_BT_ZCD, this );
m_CzBt.SetTxetBk(RGB(0,0,0));
m_ZcdBt.SetTxetBk(RGB(0,0,0));
/////
m_et_dykd.SubclassDlgItem( IDC_ET_DYKD, this );
COLORREF bk = RGB(255, 255, 255);
COLORREF tx = RGB( 255, 0, 0);
m_et_dykd.bkColor( bk );
m_et_dykd.textColor( RGB(255,0,0) );
m_et_dykd.setFont( -26 );
m_et_dyph.SubclassDlgItem( IDC_ET_DYPH, this );
m_et_dyph.bkColor( bk );
m_et_dyph.textColor( RGB(255,0,0) );
m_et_dyph.setFont( -26);
bk = RGB(128, 128, 128);
m_et_jzpl.SubclassDlgItem(IDC_ET_JZPL,this);
m_et_jzpl.bkColor( bk );
m_et_jzpl.textColor( tx );
m_et_jzpl.setFont( -26 );
m_et_plgd.SubclassDlgItem(IDC_ET_PLGD,this);
m_et_plgd.bkColor( bk );
m_et_plgd.textColor( tx );
m_et_plgd.setFont( -26 );
/////////
m_et_jzyg.SubclassDlgItem(IDC_ET_JZYG,this);
m_et_jzyg.bkColor( bk );
m_et_jzyg.textColor( tx );
m_et_jzyg.setFont( -26 );
//////////////
m_et_glgd.SubclassDlgItem(IDC_ET_GLGD,this);
m_et_glgd.bkColor( bk );
m_et_glgd.textColor( tx );
m_et_glgd.setFont( -26 );
///////////
m_et_dqst.SubclassDlgItem(IDC_ET_DQST,this);
m_et_dqst.bkColor( bk );
m_et_dqst.textColor( tx );
m_et_dqst.setFont( -26 );
///////////////
m_et_dysc.SubclassDlgItem(IDC_ET_DYSC,this);
m_et_dysc.bkColor( bk );
m_et_dysc.textColor( tx );
m_et_dysc.setFont( -26 );
//////////////
m_et_dqkx.SubclassDlgItem(IDC_ET_DQKX,this);
m_et_dqkx.bkColor( bk );
m_et_dqkx.textColor( tx );
m_et_dqkx.setFont( -26 );
//CDC *pDC=GetDC();
// pFont=new CFont();
/* if(!(pFont->CreateFont(0,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,
ANSI_CHARSET,OUT_TT_PRECIS,CLIP_TT_ALWAYS,
DEFAULT_QUALITY,DEFAULT_PITCH,"Courier New")))
{
pFont->CreateStockObject(SYSTEM_FONT);
}*/
// CFont* oldFont=pDC->SelectObject(pFont);
// pFont->CreatePointFont (200, "宋体");
// TEXTMETRIC tm;
// pDC->GetTextMetrics(&tm);
// lHeight=tm.tmHeight+tm.tmExternalLeading;
// cWidth=tm.tmAveCharWidth;
// pDC->SelectObject(oldFont);
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CTsqView printing
BOOL CTsqView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTsqView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTsqView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CTsqView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CTsqView diagnostics
#ifdef _DEBUG
void CTsqView::AssertValid() const
{
CFormView::AssertValid();
}
void CTsqView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CTsqDoc* CTsqView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTsqDoc)));
return (CTsqDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTsqView message handlers
void CTsqView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
m_dykd=m_mt_dykd=float(rand()%1000)/10;
m_mt_dyph=m_dyph=float(rand()%1000)/10;
m_jzpl=float(rand()%10000)/100;
m_plgd=float(rand()%10000)/100;
m_jzyg=float(rand()%1000)/10;
m_glgd=float(rand()%1000)/10;
m_dqst=float(rand()%1000)/10;
m_dysc=float(rand()%1000)/10;
m_dqkx=(int)rand()%100;
UpdateData(FALSE);
CWnd * pWnd=GetDlgItem(IDC_STATIC_R);
CRect Rect;
pWnd->GetClientRect(Rect);
CDC * pControlDC=pWnd->GetDC();
CFont font;
VERIFY(font.CreateFont(
24, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
DEFAULT_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
PROOF_QUALITY ,// DEFAULT_QUALITY, // nQuality
VARIABLE_PITCH|FF_ROMAN,//DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"楷体_GB2312")); // lpszFacename
// Do something with the font just created...
CFont* def_font = pControlDC->SelectObject(&font);
if(m_dqkx<50) pControlDC->SetTextColor(RGB(255,0,0));
else pControlDC->SetTextColor(RGB(0,255,0));
CPoint pos[12];
int Dis=(Rect.Width()-20)/4;
int k;
for(k=0;k<4;k++)
{
pos[k].x=Rect.left+10+Dis*k;
pos[k].y=Rect.top+10;
}
Dis=Rect.Height()/5;
for(k=4;k<8;k++)
{
pos[k].x=pos[0].x;
pos[k+4].x=pos[2].x;
pos[k+4].y=pos[k].y=Rect.top+10+(k-3)*Dis;
}
CString str[12];
str[0]="开机";
str[1]="停机";
str[2]="并网";
str[3]="调相";
str[10]="停机备用";
COLORREF tx[12];
COLORREF bx[12];
for(k=0;k<12;k++)
{
if(rand()%100<50)state[k]=TRUE;
else state[k]=FALSE;
}
if(state[0]){
bx[0]=RGB(255,255,0);
tx[0]=RGB(0,0,0);
}else{
bx[0]=RGB(128,128,128);
tx[0]=RGB(198,198,198);
}
if(state[1]){
bx[1]=RGB(0,255,0);
tx[1]=RGB(0,0,0);
}else{
bx[1]=RGB(128,128,128);
tx[1]=RGB(198,198,198);
}
if(state[2]){
bx[2]=RGB(255,0,0);
tx[2]=RGB(0,0,0);
}else{
bx[2]=RGB(128,128,128);
tx[2]=RGB(198,198,198);
}
if(state[3]){
bx[3]=RGB(0,255,0);
tx[3]=RGB(0,0,0);
}else{
bx[3]=RGB(128,128,128);
tx[3]=RGB(198,198,198);
}
if(state[4]){
bx[4]=RGB(255,255,0);
tx[4]=RGB(0,0,0);
str[4]="导叶手动";
}else{
bx[4]=RGB(0,255,0);
tx[4]=RGB(0,0,0);
str[4]="导叶自动";
}
if(state[6]){
bx[5]=RGB(0,255,0);
tx[5]=RGB(0,0,0);
str[5]="功率调节";
}else{
bx[5]=RGB(255,255,0);
tx[5]=RGB(0,0,0);
str[5]="开度调节";
}
if(state[7]){
bx[6]=RGB(255,255,0);
tx[6]=RGB(0,0,0);
str[6]="功率手动";
}else{
bx[6]=RGB(0,255,0);
tx[6]=RGB(0,0,0);
str[6]="功率自动";
}
if(state[8]){
bx[7]=RGB(255,255,0);
tx[7]=RGB(0,0,0);
str[7]="水头手动";
}else{
bx[7]=RGB(0,255,0);
tx[7]=RGB(0,0,0);
str[7]="水头自动";
}
if(state[13]){
bx[10]=RGB(0,255,0);
tx[10]=RGB(0,0,0);
}else{
bx[10]=RGB(128,128,128);
tx[10]=RGB(198,198,198);
}
if(state[10]){
bx[8]=RGB(255,255,0);
tx[8]=RGB(0,0,0);
str[8]= "跟踪频给";
}else{
bx[8]=RGB(0,255,0);
tx[8]=RGB(0,0,0);
str[8]= "跟踪网频";
}
if(txyc){
bx[9]=RGB(255,0,0);
tx[9]=RGB(0,0,0);
str[9]="通讯异常";
}else{
bx[9]=RGB(0,255,0);
tx[9]=RGB(0,0,0);
str[9]="通讯正常";
}
if(state[9]){
bx[11]=RGB(255,255,0);
tx[11]=RGB(0,0,0);
str[11]="调速器故障";
}else{
bx[11]=RGB(0,255,0);
tx[11]=RGB(0,0,0);
str[11]="调速器正常";
}
for(k=0;k<12;k++)
{
pControlDC->SetBkColor(bx[k]);
pControlDC->SetTextColor(tx[k]);
pControlDC->TextOut(pos[k].x,pos[k].y,str[k]);
}
font.DeleteObject();
pControlDC->SelectObject(def_font);
// Done with the font. Delete the font object.
// pWnd->Invalidate();
// pWnd->UpdateWindow();
CFormView::OnTimer(nIDEvent);
}
BOOL CTsqView::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
KillTimer(1);
return CFormView::DestroyWindow();
}
int CTsqView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1000,NULL);
return 0;
}
void CTsqView::OnBtCz()
{
// TODO: Add your control notification handler code here
if( MessageBox(" 非运行人员不得进入此画面\n若要进入,请按“YES”键,否则请按“NO”键!", "注意",
MB_ICONWARNING|MB_YESNO)==IDYES)
{
CWnd*p=GetParent();
p->PostMessage(WM_COMMAND,MAKEWPARAM(ID_CZ,0),0L);
}
}
void CTsqView::OnBtZcd()
{ if( MessageBox(" 非运行人员不得进入此画面\n若要进入,请按“YES”键,否则请按“NO”键!", "注意",
MB_ICONWARNING|MB_YESNO)==IDYES)
{
CWnd*p=GetParent();
p->PostMessage(WM_COMMAND,MAKEWPARAM(ID_ZCD,0),0L);
}
}
void CTsqView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
}
HBRUSH CTsqView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_EDIT){
HBRUSH B = CreateSolidBrush(RGB(200,0,0));
return (HBRUSH) B;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -