YCData.cpp
上传用户:asikq0571
上传日期:2014-07-12
资源大小:528k
文件大小:6k
- // YCData.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Peugeot.h"
- #include "YCData.h"
- #include "MainFrm.h"
- #include "PeugeotDoc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CYCData dialog
- IMPLEMENT_DYNCREATE(CYCData, CDialog)
- CYCData::CYCData(CWnd* pParent /*=NULL*/)
- : CDialog(CYCData::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CYCData)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pYCGridCtrl = NULL;
- }
- void CYCData::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CYCData)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CYCData, CDialog)
- //{{AFX_MSG_MAP(CYCData)
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_GRIDEDITCELL,OnNotifyGrid)
- ON_MESSAGE(WM_GRIDDBLCLICK,OnNotifyDblClkGrid)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CYCData message handlers
- BOOL CYCData::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- if (m_pYCGridCtrl == NULL)
- {
- //创建m_pDoc->m_pYXGridCtrl对象
- m_pYCGridCtrl = new CGridCtrl;
- // m_pYXGridCtrl->m_hGridOwner=m_hGridOwner;
- if (!m_pYCGridCtrl)
- {
- AfxMessageBox("创建遥测表格失败");
- return false;
- }
- // 创建m_pDoc->m_pYXGridCtrl对象窗体
- CRect rect;
- rect.left = 0;
- rect.top = 0;
- rect.bottom = 0;
- rect.right = 273;
- m_pYCGridCtrl->Create(rect, this, 100);
-
- m_pYCGridCtrl->SetEditable(TRUE);
- m_pYCGridCtrl->EnableDragAndDrop(TRUE);
- // TODO: Add extra initialization here
-
- }
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- //绘制遥测电子表格
- void CYCData::DrawYCGrid()
- {
- CMainFrame* pMainFrame;
- pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针
- CPeugeotDoc* pDoc;
- pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ReDrawCtr();
- try
- {
- m_pYCGridCtrl->SetRowCount(pDoc->m_YCNum+1);
- m_pYCGridCtrl->SetColumnCount(3);
- m_pYCGridCtrl->SetFixedRowCount(1);
- m_pYCGridCtrl->SetFixedColumnCount(1);
- }
- catch (CMemoryException* e)
- {
- e->ReportError();
- e->Delete();
- AfxMessageBox("遥测表格初始化失败");
- }
- GV_ITEM Item;
- Item.mask = GVIF_TEXT|GVIF_FORMAT;
- Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
- Item.row = 0;
- Item.col = 0;
- Item.szText = "点地址 D";
- m_pYCGridCtrl->SetItem(&Item);
- Item.col = 1;
- Item.szText = "点名称";
- m_pYCGridCtrl->SetItem(&Item);
- Item.col = 2;
- Item.szText = "码值 H";
- m_pYCGridCtrl->SetItem(&Item);
-
- for(int i=1;i<pDoc->m_YCNum+1;i++)
- {
- Item.row = i;
- Item.col = 0; //点地址
- Item.szText.Format("%d",(pDoc->m_YCAddr+i-1));
- m_pYCGridCtrl->SetItem(&Item);
- Item.col = 1; //点名称
- Item.szText.Format("遥测%d",i);
- m_pYCGridCtrl->SetItem(&Item);
- Item.col = 2; //点码值
- Item.szText = "0000";
- m_pYCGridCtrl->SetItem(&Item);
- }
- }
- void CYCData::UpdateYCGrid()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- CString s1;
- BYTE hib, lob; //临时变量
- for (int i=0; i<pDoc->m_YCNum; i++)
- {
- hib = HIBYTE((WORD) pDoc->m_pYCData[i]);
- lob = LOBYTE((WORD) pDoc->m_pYCData[i]);
- s1 = ByteToString(hib) + ByteToString(lob);
- m_pYCGridCtrl->SetItemText(i+1,2,s1);
- m_pYCGridCtrl->Invalidate(TRUE);
- }
- }
- void CYCData::OnDestroy()
- {
- if (m_pYCGridCtrl != NULL)
- delete m_pYCGridCtrl;
- CDialog::OnDestroy();
- }
- LRESULT CYCData::OnNotifyGrid(WPARAM wParam,LPARAM lParam)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
-
- CString strData;
- int strLen;
- char c[4];
- strData = m_pYCGridCtrl->GetItemText(wParam,2);
- strLen = strData.GetLength();
-
- for (int i=0; i<4; i++)
- {
- if (i < strLen)
- {
- c[i] = strData[strLen-1-i]; //从字符右起取值
- ChartToInt(c[i]); //转换成 0-F 整数
- }
- else
- c[i] = 0x00; //字符不足的按0值补
- }
-
- BYTE hib, lob; //临时变量
- hib = (c[3]<<4) | c[2];
- lob = (c[1]<<4) | c[0];
- pDoc->m_pYCData[wParam - 1] = (hib <<8) | lob;
- strData = ByteToString(hib) + ByteToString(lob);
- m_pYCGridCtrl->SetItemText(wParam,2, strData);
- m_pYCGridCtrl->Invalidate(TRUE);
- // if (pDoc->m_PrtType == pDoc->IEC101_S)
- // pDoc->m_PrtIEC101.SlaveSend_ChangeYC(wParam-1,1); //发送变化遥测报文
- return 0L;
- }
- LRESULT CYCData::OnNotifyDblClkGrid(WPARAM wParam,LPARAM lParam)
- {
- return 0L;
- }
- void CYCData::ReDrawCtr()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
-
- CRect BarRect,GridRect;
- pMainFrame->m_wndMyBar1.GetClientRect(&BarRect);
-
- int iGridHeight;
-
- iGridHeight = BarRect.bottom-30;
- m_pYCGridCtrl->MoveWindow(0,0,271 ,iGridHeight);
- }