YMData.cpp
上传用户:asikq0571
上传日期:2014-07-12
资源大小:528k
文件大小:6k
- // YMData.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Peugeot.h"
- #include "YMData.h"
- #include "MainFrm.h"
- #include "PeugeotDoc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CYMData dialog
- IMPLEMENT_DYNCREATE(CYMData, CDialog)
- CYMData::CYMData(CWnd* pParent /*=NULL*/)
- : CDialog(CYMData::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CYMData)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pYMGridCtrl = NULL;
- }
- void CYMData::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CYMData)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CYMData, CDialog)
- //{{AFX_MSG_MAP(CYMData)
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_GRIDEDITCELL,OnNotifyGrid)
- ON_MESSAGE(WM_GRIDDBLCLICK,OnNotifyDblClkGrid)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CYMData message handlers
- BOOL CYMData::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- if (m_pYMGridCtrl == NULL)
- {
- //创建m_pDoc->m_pYXGridCtrl对象
- m_pYMGridCtrl = new CGridCtrl;
- // m_pYXGridCtrl->m_hGridOwner=m_hGridOwner;
- if (!m_pYMGridCtrl)
- {
- AfxMessageBox("创建电度表格失败");
- return false;
- }
- // 创建m_pDoc->m_pYXGridCtrl对象窗体
- CRect rect;
- rect.left = 0;
- rect.top = 0;
- rect.bottom = 0;
- rect.right = 273;
- m_pYMGridCtrl->Create(rect, this, 100);
-
- m_pYMGridCtrl->SetEditable(TRUE);
- m_pYMGridCtrl->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 CYMData::DrawYMGrid()
- {
- CMainFrame* pMainFrame;
- pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针
- CPeugeotDoc* pDoc;
- pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ReDrawCtr();
- try
- {
- m_pYMGridCtrl->SetRowCount(pDoc->m_YMNum+1);
- m_pYMGridCtrl->SetColumnCount(3);
- m_pYMGridCtrl->SetFixedRowCount(1);
- m_pYMGridCtrl->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_pYMGridCtrl->SetItem(&Item);
- Item.col = 1;
- Item.szText = "点名称";
- m_pYMGridCtrl->SetItem(&Item);
- Item.col = 2;
- Item.szText = "码值 H";
- m_pYMGridCtrl->SetItem(&Item);
-
- for(int i=1;i<pDoc->m_YMNum+1;i++)
- {
- Item.row = i;
- Item.col = 0; //点地址
- Item.szText.Format("%d",(pDoc->m_YMAddr+i-1));
- m_pYMGridCtrl->SetItem(&Item);
- Item.col = 1; //点名称
- Item.szText.Format("电度%d",i);
- m_pYMGridCtrl->SetItem(&Item);
- Item.col = 2; //点码值
- Item.szText = "00000000";
- m_pYMGridCtrl->SetItem(&Item);
- }
- }
- void CYMData::OnDestroy()
- {
- if (m_pYMGridCtrl != NULL)
- delete m_pYMGridCtrl;
- CDialog::OnDestroy();
- }
- LRESULT CYMData::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[8];
- strData = m_pYMGridCtrl->GetItemText(wParam,2);
- strLen = strData.GetLength();
-
- for (int i=0; i<8; i++)
- {
- if (i < strLen)
- {
- c[i] = strData[strLen-1-i]; //从字符右起取值
- ChartToInt(c[i]); //转换成 0-F 整数
- }
- else
- c[i] = 0x00; //字符不足的按0值补
- }
-
- BYTE hihib,hib,lob,lolob; //临时变量,4个字节
- WORD hiword,loword;
- hihib = (c[7]<<4) | c[6];
- hib = (c[5]<<4) | c[4];
- lob = (c[3]<<4) | c[2];
- lolob = (c[1]<<4) | c[0];
- hiword = (hihib<<8) | hib;
- loword = (lob<<8) | lolob;
- pDoc->m_pYMData[wParam - 1] = (hiword << 16) | loword;
- strData = ByteToString(hihib) + ByteToString(hib) + ByteToString(lob) + ByteToString(lolob);
- m_pYMGridCtrl->SetItemText(wParam,2,strData);
- m_pYMGridCtrl->Invalidate(TRUE);
-
- return 0L;
- }
- LRESULT CYMData::OnNotifyDblClkGrid(WPARAM wParam,LPARAM lParam)
- {
- return 0L;
- }
- void CYMData::UpdateYMGrid()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- CString s1;
- WORD hiw, low;
- BYTE hihib,hib,lob,lolob; //临时变量,4个字节
- for (int i=0; i<pDoc->m_YCNum; i++)
- {
- hiw = HIWORD(pDoc->m_pYMData[i]);
- low = LOWORD(pDoc->m_pYMData[i]);
- hihib = HIBYTE(hiw);
- hib = LOBYTE(hiw);
- lob = HIBYTE(low);
- lolob = LOBYTE(low);
- s1 = ByteToString(hihib) + ByteToString(hib) + ByteToString(lob) + ByteToString(lolob);
- m_pYMGridCtrl->SetItemText(i+1,2,s1);
- m_pYMGridCtrl->Invalidate(TRUE);
- }
- }
- void CYMData::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_pYMGridCtrl->MoveWindow(0,0,271 ,iGridHeight);
- }