📄 rectview.cpp
字号:
// RectView.cpp : implementation file
//
#include "stdafx.h"
#include "RectView.h"
#include "RectButton.h"
#include "CheckState.h"
#include "MainFrm.h"
#include "DlgAllStaSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define HGLI RGB(95,175,191)
#define GRAY RGB(129,129,129)
#define GREEN RGB(86,222,100)
#define RED RGB(255,0,0)
/////////////////////////////////////////////////////////////////////////////
bool CRectView::bCrash=false;
bool CRectView::bFresh=false;
LONG CRectView::LCx=100;
LONG CRectView::LCy=100;
CPtrArray CRectView ::m_aRect;
bool bFlush=false;
IMPLEMENT_DYNCREATE(CRectView, CView)
CRectView::CRectView()
{
}
CRectView::~CRectView()
{
for(int i = 0;i<m_aRect.GetSize();i++)
{
CRectButton* pLeft = (CRectButton*)m_aRect.GetAt(i);
delete pLeft;
}
m_aRect.RemoveAll();
}
BEGIN_MESSAGE_MAP(CRectView, CView)
//{{AFX_MSG_MAP(CRectView)
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SIZE()
ON_WM_SHOWWINDOW()
ON_WM_PAINT()
ON_WM_SETFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRectView drawing
void CRectView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
GetClientRect(rect);
pDC->FillSolidRect(rect,HGLI);
if(nFirst<=1)
{
Mydraw();
}
DrawLine();
::SendMessage(::AfxGetApp()->m_pMainWnd->GetSafeHwnd(),WM_SYSCOMMAND,(WPARAM)SC_MAXIMIZE,NULL);
// m_aRect.RemoveAll();
}
/////////////////////////////////////////////////////////////////////////////
// CRectView diagnostics
#ifdef _DEBUG
void CRectView::AssertValid() const
{
CView::AssertValid();
}
void CRectView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRectView message handlers
UINT CRectView::uiPeriod=0;
int CRectView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
lpCreateStruct->style &=~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX);
lpCreateStruct->style &=~WS_THICKFRAME; //使窗口大小固定
lpCreateStruct->style &=~FWS_ADDTOTITLE; //去掉无标题
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// m_aRect.RemoveAll();
Mydraw();
ReadPeriod();
if(iStaCnt>0 && uiPeriod>0)
{
SetTimer(1,uiPeriod*1000,NULL);
}
return 0;
}
BOOL CRectView::PreTranslateMessage(MSG* pMsg)
{
return CView::PreTranslateMessage(pMsg);
}
int CRectView::ReadConfigStaCnt(int &iCntSta)
{
CDlgAllStaSet dlgalstaset;
CString strPath;
char Get[255];
dlgalstaset.GetModulePath(strPath,NULL);
strPath+="PCM120networksetup.ini";
GetPrivateProfileString("general","StationCnt","0",Get,255,strPath);
iCntSta =atoi(Get);
return iCntSta;
}
void CRectView::Mydraw()
{
/* CRect rectedge(0,0,1248,1024);
CBrush brush;
CClientDC dc(this);
brush.CreateSolidBrush(HGLI);
dc.FillRect(rectedge,&brush);
*/
for(int i = 0;i<m_aRect.GetSize();i++)
{
CRectButton* pLeft = (CRectButton*)m_aRect.GetAt(i);
delete pLeft;
}
m_aRect.RemoveAll();
CString strGetColor;
ReadConfigStaCnt(iStaCnt);
if(ReadConfigStaName(saStaNameAll))
{
CRect rcBut(0,0,80,80);
//CString strGetColor;
strGetColor=CCheckState::strColorbefore;
CStringArray staGetcolor;
int iGetColorLen=strGetColor.GetLength();
if(iGetColorLen==0)//如果strColor的长度为0,则说明设备都没有正常工作都置0
{
for(int im=0;im<iStaCnt;im++)
{
staGetcolor.Add("0");
}
}
for(int i =0;i<iGetColorLen;i++)//strColor中的每一位代表着一个设备的状态情况,2表示都工作,1代表部分工作,0表示都没工作;
{
CString str;
str=strGetColor.Mid(i,1);
staGetcolor.Add(strGetColor.Mid(i,1));
}
CDlgAllStaSet dlgalstaset;
CString strPath;
dlgalstaset.GetModulePath(strPath,NULL);
strPath+="PCM120networksetup.ini";
char Get[255];
int x,y,p,q;
for(int iIdxSta=0;iIdxSta<iStaCnt;iIdxSta++)
{
CString strSect;
strSect.Format("station%d",iIdxSta+1);
GetPrivateProfileString(strSect,"posionx","100",Get,255,strPath);
x =atoi(Get);
GetPrivateProfileString(strSect,"posiony","100",Get,255,strPath);
y =atoi(Get);
GetPrivateProfileString(strSect,"posionp","100",Get,255,strPath);
p =atoi(Get);
GetPrivateProfileString(strSect,"posionq","100",Get,255,strPath);
q =atoi(Get);
CRectButton* pRight = new CRectButton;
CRect rect2(x,y,p,q);
CString strTestchl;
// AfxMessageBox(saStaNameAll.GetAt(iIdxSta));
try
{
if(staGetcolor.GetAt(iIdxSta)=="2")
{
pRight->Create(saStaNameAll.GetAt(iIdxSta),rect2,GREEN,this,1001+iIdxSta+1);
m_aRect.Add(pRight);
}
else if(staGetcolor.GetAt(iIdxSta)=="0")
{
pRight->Create(saStaNameAll.GetAt(iIdxSta),rect2,GRAY,this,1001+iIdxSta+1);
m_aRect.Add(pRight);
}
else if(staGetcolor.GetAt(iIdxSta)=="1")
{
pRight->Create(saStaNameAll.GetAt(iIdxSta),rect2,RED,this,1001+iIdxSta+1);
m_aRect.Add(pRight);
}
}
catch (...)
{
}
}
if(nFirst<0)
{
nFirst=0;
}
else
{
nFirst+=1;
}
}
// CRectView::bFresh=false;
SetTimer(2,10,NULL);
}
bool CRectView::ReadConfigStaName(CStringArray &staName)
{
CDlgAllStaSet dlgalstaset;
CString strPath;
char Get[255];
dlgalstaset.GetModulePath(strPath,NULL);
strPath+="PCM120networksetup.ini";
GetPrivateProfileString("general","StationCnt","0",Get,255,strPath);
int iCntSta =atoi(LPCTSTR(Get));
for(int i=0;i<iCntSta;i++)
{
CString strSection;
strSection.Format("station%d",i+1);
GetPrivateProfileString(strSection,"stationname","NULL",Get,255,strPath);
staName.Add(Get);
}
return true;
}
void CRectView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent) {
case 1:
// m_aRect.RemoveAll();
Mydraw();
/* if(CCheckState::bAuto==0)
{
KillTimer(1);
}
*/
break;
case 2:
while(CRectView::bFresh==1)
{
Redraw();
CRectView::bFresh=false;
}
break;
}
CView::OnTimer(nIDEvent);
}
BOOL CRectView::ReadPeriod()
{
CDlgAllStaSet dlgalstaset;
CString strPath;
char Get[255];
dlgalstaset.GetModulePath(strPath,NULL);
strPath+="config.ini";
GetPrivateProfileString("General","查询周期(秒)","30",Get,255,strPath);
uiPeriod=(UINT)atoi(Get);
return true;
}
void CRectView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(CMainFrame::bSet==1)
{
StartPt.x=point.x;
StartPt.y=point.y;
}
CView::OnLButtonDown(nFlags, point);
}
void CRectView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(CMainFrame::bSet==1)
{
CStdioFile stfile;
CString strPath;
CDlgAllStaSet dlgalstaset;
dlgalstaset.GetModulePath(strPath,NULL);
strPath+="Line.txt";
CClientDC dc(this);
EndPt.x=point.x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -