📄 anavalueview1.cpp
字号:
// AnaValueView1.cpp : implementation file
//
#include "stdafx.h"
#include "mbpc.h"
#include "AnaValueView1.h"
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAnaValueView1
IMPLEMENT_DYNCREATE(CAnaValueView1, CFormView)
CAnaValueView1::CAnaValueView1()
: CFormView(CAnaValueView1::IDD)
{
//{{AFX_DATA_INIT(CAnaValueView1)
m_szParaName = _T("");
m_fParaRatio = 0.0f;
m_szSecName = _T("");
m_fSecRatio = 0.0f;
m_nFstComb = 0;
m_nSecComb = 0;
m_fValue = 0.0f;
m_nTimerFlag = 0;
m_szStatus = _T("");
//}}AFX_DATA_INIT
}
CAnaValueView1::~CAnaValueView1()
{
}
void CAnaValueView1::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAnaValueView1)
DDX_Control(pDX, IDC_SECNAME, m_EditSecName);
DDX_Control(pDX, IDC_SECSET, m_btSetSec);
DDX_Control(pDX, IDC_GETSRATIO, m_btGetSratio);
DDX_Control(pDX, IDC_SECRATIO, m_EditSecRatio);
DDX_Control(pDX, IDC_VALUE, m_EditValueIn);
DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
DDX_Control(pDX, IDC_SECCOMB, m_CombSec);
DDX_Control(pDX, IDC_FSTCOMB, m_CombFst);
DDX_Control(pDX, IDC_ANALIST, m_ListAnalog);
DDX_Text(pDX, IDC_PARANAME, m_szParaName);
DDX_Text(pDX, IDC_PARARATIO, m_fParaRatio);
DDX_Text(pDX, IDC_SECNAME, m_szSecName);
DDX_Text(pDX, IDC_SECRATIO, m_fSecRatio);
DDX_CBIndex(pDX, IDC_FSTCOMB, m_nFstComb);
DDX_CBIndex(pDX, IDC_SECCOMB, m_nSecComb);
DDX_Text(pDX, IDC_VALUE, m_fValue);
DDX_Text(pDX, IDC_STATUS, m_szStatus);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAnaValueView1, CFormView)
//{{AFX_MSG_MAP(CAnaValueView1)
ON_WM_CREATE()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_PARASET, OnParaset)
ON_BN_CLICKED(IDC_SECSET, OnSecset)
ON_WM_DESTROY()
ON_CBN_SELCHANGE(IDC_FSTCOMB, OnSelchangeFstcomb)
ON_CBN_SELCHANGE(IDC_SECCOMB, OnSelchangeSeccomb)
ON_BN_CLICKED(IDC_GETSRATIO, OnGetsratio)
ON_MESSAGE(WM_MYMESSAGE,OnMyMessage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAnaValueView1 diagnostics
#ifdef _DEBUG
void CAnaValueView1::AssertValid() const
{
CFormView::AssertValid();
}
void CAnaValueView1::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CAnaValueView1 message handlers
CMbpcDoc* CAnaValueView1::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMbpcDoc)));
return (CMbpcDoc*)m_pDocument;
}
int CAnaValueView1::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,500,NULL);
return 0;
}
void CAnaValueView1::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
int j;
m_ListAnalog.DeleteAllItems();
for(j = 0; j < 6; j++)
{
m_ListAnalog.DeleteColumn(0);
}
for(j = 0; j < GetDocument()->m_device_info.analog_count; j++)
{
m_CombFst.DeleteString(0);
m_CombSec.DeleteString(0);
}
LONG lStyle;
lStyle = GetWindowLong(m_ListAnalog.m_hWnd, GWL_STYLE);//获取当前窗口style
lStyle &= ~LVS_TYPEMASK; //清除显示方式位
lStyle |= LVS_REPORT; //设置style
SetWindowLong(m_ListAnalog.m_hWnd, GWL_STYLE, lStyle);//设置style
DWORD dwStyle = m_ListAnalog.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)
dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl)
m_ListAnalog.SetExtendedStyle(dwStyle); //设置扩展风格
this->m_ListAnalog.InsertColumn(0,"模拟量ID",LVCFMT_LEFT,80);
this->m_ListAnalog.InsertColumn(1,"名称",LVCFMT_LEFT,70);
this->m_ListAnalog.InsertColumn(2,"一次测变比",LVCFMT_LEFT,90);
this->m_ListAnalog.InsertColumn(3,"一次测",LVCFMT_LEFT,90);
this->m_ListAnalog.InsertColumn(4,"二次测变比",LVCFMT_LEFT,90);
this->m_ListAnalog.InsertColumn(5,"二次测",LVCFMT_LEFT,90);
for(int i = 0; i < this->GetDocument()->m_device_info.analog_count; i++)
{
CString str;
str.Format("%d", i+1);
this->m_CombFst.AddString(str);
this->m_CombSec.AddString(str);
}
/* CString strText;
int nColumnCount = m_ListAnalog.GetHeaderCtrl()->GetItemCount();
for (int i=0;i < 10;i++)
{
strText.Format(TEXT("item %d"), i);
m_ListAnalog.InsertItem(
LVIF_TEXT|LVIF_STATE, i, strText,
(i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
0, 0);
for (int j=1;j < nColumnCount;j++)
{
strText.Format(TEXT("sub-item %d %d"), i, j);
m_ListAnalog.SetItemText(i, j, strText);
}
}*/
// m_ListAnalog.SetItemText(nRow, 1, "jacky");
if(GetDocument()->m_bSetuped)
{
CString strText;
this->m_nAnaCntr = GetDocument()->m_device_info.analog_count;
for(int i = 0; i < m_nAnaCntr; i++)
{
strText.Format("%d",i + 1);
int nRow = m_ListAnalog.InsertItem(i,strText);
m_ListAnalog.SetItemText(nRow, 1, (CString)GetDocument()->m_analog_info[i].analog_name);
strText.Format("%f",GetDocument()->m_analog_info[i].primary_ratio);
m_ListAnalog.SetItemText(nRow, 2, strText);
strText.Format("%f",GetDocument()->m_analog_info[i].secondary_ratio);
m_ListAnalog.SetItemText(nRow, 4, strText);
}
}
UpdateData(FALSE);
}
void CAnaValueView1::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString str,strText;
char szBuf[1024];
memset(szBuf,0,sizeof(szBuf));
if(1 == nIDEvent)
{
m_nTimerFlag++;
if(m_nTimerFlag > 1)
{
m_nTimerFlag --;
}
else
{
if(GetDocument()->m_bSetuped)
{
for(int i = 0; i < m_nAnaCntr; i++)
{
sprintf(szBuf,"%f %s",GetDocument()->m_fPrim_AnaVal[i],GetDocument()->m_analog_info[i].primary_unit);
m_ListAnalog.SetItemText(i, 3, szBuf);
memset(szBuf,0,sizeof(szBuf));
sprintf(szBuf,"%f %s",GetDocument()->m_fSec_AnaVal[i],GetDocument()->m_analog_info[i].secondary_unit);
m_ListAnalog.SetItemText(i,5,szBuf);
memset(szBuf,0,sizeof(szBuf));
strText.Format("%d",i);
m_ListAnalog.SetItemText(i, 1, (CString)GetDocument()->m_analog_info[i].analog_name);
strText.Format("%f",GetDocument()->m_analog_info[i].primary_ratio);
m_ListAnalog.SetItemText(i, 2, strText);
strText.Format("%f",GetDocument()->m_analog_info[i].secondary_ratio);
m_ListAnalog.SetItemText(i, 4, strText);
}
m_ListAnalog.UpdateData(FALSE);
//UpdateData(FALSE);
}
}
m_nTimerFlag--;
}
CFormView::OnTimer(nIDEvent);
}
void CAnaValueView1::OnParaset()
{
// TODO: Add your control notification handler code here
if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
{
UpdateData(TRUE);
if(GetDocument()->m_bSetuped)
{
GetDocument()->SetAnalogParaSet(this->m_nFstComb,this->m_szParaName,this->m_fParaRatio);
Sleep(1000);
GetDocument()->ReqAnaInfo(m_nFstComb);
}
}
}
void CAnaValueView1::OnSecset()
{
// TODO: Add your control notification handler code here
if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
{
UpdateData(TRUE);
if(GetDocument()->m_bSetuped)
{
GetDocument()->SetAnalogScndPara(this->m_nSecComb,this->m_szSecName,this->m_fSecRatio);
Sleep(1000);
GetDocument()->ReqAnaInfo(m_nSecComb);
}
}
}
void CAnaValueView1::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// TODO: Add your specialized code here and/or call the base class
UpdateData();
if(bActivate == FALSE)
{
KillTimer(1);
}
else
{
OnInitialUpdate();
SetTimer(1,500,NULL);
}
CFormView::Invalidate();
CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CAnaValueView1::OnDestroy()
{
CFormView::OnDestroy();
// TODO: Add your message handler code here
KillTimer(1);
}
void CAnaValueView1::OnSelchangeFstcomb()
{
// TODO: Add your control notification handler code here
UpdateData();
m_szParaName.Format("%s", GetDocument()->m_analog_info[m_nFstComb].analog_name);
this->m_fParaRatio = GetDocument()->m_analog_info[m_nFstComb].primary_ratio;
UpdateData(FALSE);
}
void CAnaValueView1::OnSelchangeSeccomb()
{
// TODO: Add your control notification handler code here
UpdateData();
m_szSecName.Format("%s", GetDocument()->m_analog_info[m_nSecComb].analog_name);
m_fSecRatio = GetDocument()->m_analog_info[m_nSecComb].secondary_ratio;
UpdateData(FALSE);
}
void __cdecl ThreadTime(void* point)
{
CAnaValueView1 *pAna = (CAnaValueView1*)point;
CMbpcDoc* pDoc = (CMbpcDoc*)pAna->GetDocument();
int cntr = 0;
int anacntr = 0;
while(pDoc->m_nAnaCntr < 10)
{
pAna->m_Progress.SetPos(pDoc->m_nAnaCntr*10);
cntr++;
if(anacntr != pDoc->m_nAnaCntr)
{
cntr = 0;
anacntr = pDoc->m_nAnaCntr;
}
Sleep(100);
if(cntr > 50)
{
break;
}
}
UINT avg = 0;
//UpdateData();
if(cntr > 50)
{
::PostMessage(pAna->m_hWnd, WM_MYMESSAGE, 1, 0);
}
else
{
for(int i = 0; i < 10; i++)
{
avg += pDoc->m_nAnaAvg[pAna->m_nSecComb][i];
}
avg = avg/10;
pAna->m_fSecRatio = pAna->m_fValue/avg;
::PostMessage(pAna->m_hWnd, WM_MYMESSAGE, 0, 0);
}
_endthread();
}
void CAnaValueView1::OnGetsratio()
{
// TODO: Add your control notification handler code here
// UINT avg = 0;
//UpdateData();
/*if(GetDocument()->m_nAnaCntr < 10)
{
for(int i = 0; i < GetDocument()->m_nAnaCntr; i++)
{
avg += GetDocument()->m_nAnaAvg[m_nSecComb][i];
}
}*/
//this->EnableWindow(FALSE);
GetDocument()->m_nAnaCntr = 0;
m_szStatus.Format("计算中");
UpdateData(FALSE);
UpdateData();
m_btGetSratio.EnableWindow(FALSE);
m_btSetSec.EnableWindow(FALSE);
m_EditSecRatio.EnableWindow(FALSE);
m_EditValueIn.EnableWindow(FALSE);
m_EditSecName.EnableWindow(FALSE);
m_CombSec.EnableWindow(FALSE);
_beginthread(ThreadTime,0,this);
/*for(int i = 0; i < 10; i++)
{
avg += GetDocument()->m_nAnaAvg[m_nSecComb][i];
}
avg = avg/10;
m_fSecRatio = m_fValue/avg;*/
UpdateData(FALSE);
}
LRESULT CAnaValueView1::OnMyMessage(WPARAM w,LPARAM l)
{
if(w == 0)
{
m_szStatus.Format("计算完成");
UpdateData(FALSE);
m_btGetSratio.EnableWindow();
m_btSetSec.EnableWindow();
m_EditSecRatio.EnableWindow();
m_EditValueIn.EnableWindow();
m_EditSecName.EnableWindow();
m_CombSec.EnableWindow();
}
else
{
AfxMessageBox("计算超时");
m_szStatus.Format("计算超时");
UpdateData(FALSE);
m_btGetSratio.EnableWindow();
m_btSetSec.EnableWindow();
m_EditSecRatio.EnableWindow();
m_EditValueIn.EnableWindow();
m_EditSecName.EnableWindow();
m_CombSec.EnableWindow();
}
//this->EnableWindow();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -