www.pudn.com > CTableDemo.rar > CTableDemoDlg.cpp
// CTableDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CTableDemo.h"
#include "CTableDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnMove(int x, int y);
afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnCancelMode();
afx_msg void OnCaptureChanged(CWnd *pWnd);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg int OnCharToItem(UINT nChar, CListBox* pListBox, UINT nIndex);
afx_msg void OnClose();
afx_msg int OnCompareItem(int nIDCtl, LPCOMPAREITEMSTRUCT lpCompareItemStruct);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_CTLCOLOR()
ON_WM_HELPINFO()
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_MOVE()
ON_WM_RBUTTONDBLCLK()
ON_WM_RBUTTONUP()
ON_WM_CANCELMODE()
ON_WM_CAPTURECHANGED()
ON_WM_CHAR()
ON_WM_CHARTOITEM()
ON_WM_CLOSE()
ON_WM_COMPAREITEM()
ON_WM_CONTEXTMENU()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCTableDemoDlg dialog
CCTableDemoDlg::CCTableDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCTableDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCTableDemoDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCTableDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCTableDemoDlg)
DDX_Control(pDX, IDC_SETSTATE, m_Set);
DDX_Control(pDX, IDC_EDIT8, m_Val8);
DDX_Control(pDX, IDC_EDIT7, m_Val7);
DDX_Control(pDX, IDC_EDIT6, m_Val6);
DDX_Control(pDX, IDC_EDIT5, m_Val5);
DDX_Control(pDX, IDC_EDIT4, m_Val4);
DDX_Control(pDX, IDC_EDIT3, m_Val3);
DDX_Control(pDX, IDC_EDIT2, m_Val2);
DDX_Control(pDX, IDC_EDIT1, m_Val1);
DDX_Control(pDX, IDC_METER6, m_Meter6);
DDX_Control(pDX, IDC_METER5, m_Meter5);
DDX_Control(pDX, IDC_METER4, m_Meter4);
DDX_Control(pDX, IDC_METER3, m_Meter3);
DDX_Control(pDX, IDC_METER2, m_Meter2);
DDX_Control(pDX, IDC_METER1, m_Meter1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCTableDemoDlg, CDialog)
//{{AFX_MSG_MAP(CCTableDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_HAND, OnHand)
ON_BN_CLICKED(IDC_ONTIME, OnOntime)
ON_BN_CLICKED(IDC_SETSTATE, OnSetstate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCTableDemoDlg message handlers
BOOL CCTableDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
for(int i=0;i<10;i++)
iVal[i]=0.00f;
COLORREF m_colorNeedle = RGB(255, 128, 64);//etSysColor(COLOR_ACTIVEBORDER);
m_Meter1.SetNeedleColor(m_colorNeedle);
m_Meter1.SetColorTick(TRUE);
m_Meter1.SetRange(0,500);
m_Meter1.SetScaleDecimals(0);
m_Meter1.SetValueDecimals(3);
m_Meter1.SetTicks(4);
m_Meter1.SetSubTicks(5);
CString str="";
m_Meter1.SetUnits(str);
m_Meter1.UpdateNeedle(0.00f);
m_colorNeedle = RGB(255, 128, 64);//etSysColor(COLOR_ACTIVEBORDER);
m_Meter2.SetNeedleColor(m_colorNeedle);
m_Meter2.SetColorTick(TRUE);
m_Meter2.SetRange(0,50);
m_Meter2.SetScaleDecimals(0);
m_Meter2.SetValueDecimals(2);
m_Meter2.SetTicks(10);
m_Meter2.SetSubTicks(8);
str="数值2";
m_Meter2.SetUnits(str);
m_Meter2.UpdateNeedle(0.00f);
m_Meter3.SetRange(0,500);
str="数值3";
m_Meter3.SetUnits(str);
m_colorNeedle = RGB(255, 128, 64);//etSysColor(COLOR_ACTIVEBORDER);
m_Meter3.SetNeedleColor(m_colorNeedle);
m_Meter3.UpdateNeedle(0.00f);
m_Meter4.SetRange(0,50);
str="数值4";
m_Meter4.SetUnits(str);
m_colorNeedle = RGB(255, 128, 64);//etSysColor(COLOR_ACTIVEBORDER);
m_Meter4.SetNeedleColor(m_colorNeedle);
m_Meter4.UpdateNeedle(0.00f);
RECT rect;
rect.left = 45; rect.top = 232;
rect.right = rect.left + (5 * IMAGE_WIDTH);
rect.bottom = rect.top + IMAGE_HEIGHT;
m_Odometer1.SetNumDigits (10);
m_Odometer1.m_RotationStyle = STYLE_ROTATE_FROM_ZERO;
m_Odometer1.Create (NULL, SS_BLACKFRAME | WS_VISIBLE |
WS_CHILD, rect, this, 1001);
m_Odometer1.m_RotationStyle = STYLE_ROTATE_WRAPAROUND;
m_Odometer1.SendMessage (WM_SET_ROTATION_STYLE,
0, (int) (LPARAM) m_Odometer1.m_RotationStyle);
m_Odometer1.m_Digits [i].m_TimeInterval = 20;
m_Odometer1.ShowWindow (SW_SHOW);
rect.left = 195; rect.top = 232;
rect.right = rect.left + (5 * IMAGE_WIDTH);
rect.bottom = rect.top + IMAGE_HEIGHT;
m_Odometer2.SetNumDigits (10);
m_Odometer2.m_RotationStyle = STYLE_ROTATE_FROM_ZERO;
m_Odometer2.Create (NULL, SS_BLACKFRAME | WS_VISIBLE |
WS_CHILD, rect, this, 1001);
m_Odometer2.m_RotationStyle = STYLE_ROTATE_WRAPAROUND;
m_Odometer2.SendMessage (WM_SET_ROTATION_STYLE,
0, (int) (LPARAM) m_Odometer2.m_RotationStyle);
m_Odometer2.m_Digits [i].m_TimeInterval = 20;
m_Odometer2.ShowWindow (SW_SHOW);
m_Meter5.SetColourFaded(RGB(0,40,0));
CString strVal="00000000";
m_Meter5.Display(strVal);
m_Meter6.SetColourFaded(RGB(0,40,0));
strVal="00000000";
m_Meter6.Display(strVal);
AfxGetApp()->GetMainWnd()->SetWindowText(_T("模拟量节点模拟显示程序"));
// 创建阴影工具提示,并与相应提示控件联系起来
m_tooltip.Create(this);
m_tooltip.AddTool(GetDlgItem(IDOK), _T("退出
退出模拟量监控程序"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDCANCEL), _T("退出"));
m_tooltip.AddTool(GetDlgItem(IDC_COMBO1), _T("ID选择
选择发送命令的模拟点的ID"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT9), _T("命令发送
输入整型数字"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT1), _T("状态输入
模拟点1的输入状态"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT2), _T("状态输入
模拟点2的输入状态"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT3), _T("状态输入
模拟点3的输入状态"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT4), _T("状态输入
模拟点4的输入状态"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT5), _T("状态输入
模拟点5的输入状态"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT6), _T("状态输入
模拟点6的输入状态"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT7), _T("状态输入
模拟点7的输入状态"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_EDIT8), _T("状态输入
模拟点8的输入状态"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_SENDCOMMAND), _T("命令发送
进行选择ID的模拟点进行信号输出"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_HAND), _T("手工置位
手动置模拟点信号数值"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_SETSTATE), _T("设定状态
对模拟点进行数值手动更新"),IDI_PINFORMATION);
m_tooltip.AddTool(GetDlgItem(IDC_ONTIME), _T("实时刷新
模拟点信号位实时输入采集信号"),IDI_PINFORMATION);
// 显示图标或位图及字体属性
m_tooltip.SetNotify();
m_tooltip.SetDefaultFont();
// 设置背景效果及渐变色
m_tooltip.SetColor(CPPToolTip::PPTOOLTIP_COLOR_BK_BEGIN, RGB(255, 255, 255));
m_tooltip.SetColor(CPPToolTip::PPTOOLTIP_COLOR_BK_MID,RGB(240, 247, 250));
m_tooltip.SetColor(CPPToolTip::PPTOOLTIP_COLOR_BK_END, RGB(192, 192, 200));
m_tooltip.SetEffectBk(14, 10);
m_tooltip.SetColor(CPPToolTip::PPTOOLTIP_COLOR_BK_BEGIN, RGB(255, 255, 223));
m_tooltip.SetColor(CPPToolTip::PPTOOLTIP_COLOR_BK_MID,RGB(192, 192, 172));
m_tooltip.SetColor(CPPToolTip::PPTOOLTIP_COLOR_BK_END, RGB(128, 128, 112));
m_tooltip.SetEffectBk(13, 10);
// 多行显示提示信息
m_tooltip.SetBehaviour(PPTOOLTIP_MULTIPLE_SHOW);
// 程序初始启动时,窗体位于最前方
SetWindowPos(&wndTopMost,0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
SetEditValue();
UpdateLedState();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCTableDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCTableDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCTableDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CCTableDemoDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// 为阴影工具提示加入鼠标事件传递
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
HBRUSH CCTableDemoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_LISTBOX)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(233,233,220));
HBRUSH b=CreateSolidBrush(RGB(233,233,220));
return b;
}
else if(nCtlColor==CTLCOLOR_SCROLLBAR)
{
}
else if(nCtlColor==CTLCOLOR_EDIT)
{
}
else if(nCtlColor==CTLCOLOR_STATIC)
{
}
else if(nCtlColor==CTLCOLOR_DLG)
{
}
return hbr;
}
void CCTableDemoDlg::OnOK()
{
if(MessageBox("监控系统程序正在运行,确定要退出监控界面吗?","提示",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
CDialog::OnOK();
}
void CCTableDemoDlg::OnHand()
{
this->m_Val1.EnableWindow(TRUE);
this->m_Val2.EnableWindow(TRUE);
this->m_Val3.EnableWindow(TRUE);
this->m_Val4.EnableWindow(TRUE);
this->m_Val5.EnableWindow(TRUE);
this->m_Val6.EnableWindow(TRUE);
this->m_Val7.EnableWindow(TRUE);
this->m_Val8.EnableWindow(TRUE);
this->m_Set.EnableWindow(TRUE);
SetEditValue();
}
void CCTableDemoDlg::SetEditValue()
{
CString strVal1,strVal2,strVal3,strVal4,strVal5,strVal6,strVal7,strVal8;
strVal1.Format("%.2f",iVal[1]);
strVal2.Format("%.2f",iVal[2]);
strVal3.Format("%.2f",iVal[3]);
strVal4.Format("%.2f",iVal[4]);
strVal5.Format("%.2f",iVal[5]);
strVal6.Format("%.2f",iVal[6]);
strVal7.Format("%.2f",iVal[7]);
strVal8.Format("%.2f",iVal[8]);
this->m_Val1.SetWindowText(strVal1);
this->m_Val2.SetWindowText(strVal2);
this->m_Val3.SetWindowText(strVal3);
this->m_Val4.SetWindowText(strVal4);
this->m_Val5.SetWindowText(strVal5);
this->m_Val6.SetWindowText(strVal6);
this->m_Val7.SetWindowText(strVal7);
this->m_Val8.SetWindowText(strVal8);
}
void CCTableDemoDlg::OnOntime()
{
this->m_Val1.EnableWindow(FALSE);
this->m_Val2.EnableWindow(FALSE);
this->m_Val3.EnableWindow(FALSE);
this->m_Val4.EnableWindow(FALSE);
this->m_Val5.EnableWindow(FALSE);
this->m_Val6.EnableWindow(FALSE);
this->m_Val7.EnableWindow(FALSE);
this->m_Val8.EnableWindow(FALSE);
this->m_Set.EnableWindow(FALSE);
}
void CCTableDemoDlg::OnSetstate()
{
CString strVal1,strVal2,strVal3,strVal4,strVal5,strVal6,strVal7,strVal8;
this->m_Val1.GetWindowText(strVal1);
this->m_Val2.GetWindowText(strVal2);
this->m_Val3.GetWindowText(strVal3);
this->m_Val4.GetWindowText(strVal4);
this->m_Val5.GetWindowText(strVal5);
this->m_Val6.GetWindowText(strVal6);
this->m_Val7.GetWindowText(strVal7);
this->m_Val8.GetWindowText(strVal8);
iVal[1]=(float)atof(strVal1);
iVal[2]=(float)atof(strVal2);
iVal[3]=(float)atof(strVal3);
iVal[4]=(float)atof(strVal4);
iVal[5]=(float)atof(strVal5);
iVal[6]=(float)atof(strVal6);
iVal[7]=(float)atof(strVal7);
iVal[8]=(float)atof(strVal8);
UpdateLedState();
}
void CCTableDemoDlg::UpdateLedState()
{
CString strVal1,strVal2;
int nLen;
m_Meter1.UpdateNeedle(iVal[1]);
m_Meter2.UpdateNeedle(iVal[2]);
m_Meter3.UpdateNeedle(iVal[3]);
m_Meter4.UpdateNeedle(iVal[4]);
m_Odometer1.m_nNumber=(int)iVal[5];
m_Odometer1.SendMessage (WM_RESET_COUNTERS, 0, 0);
m_Odometer1.SendMessage (WM_ADVANCE_COUNTERS, 0, 0);
m_Odometer2.m_nNumber=(int)iVal[6];
m_Odometer2.SendMessage (WM_RESET_COUNTERS, 0, 0);
m_Odometer2.SendMessage (WM_ADVANCE_COUNTERS, 0, 0);
strVal1.Format("%.2f",iVal[7]);
nLen=strVal1.GetLength();
if(nLen<8)
{
for(int i=0;i<8-nLen;i++)
strVal1="0"+strVal1;
}
m_Meter5.Display(strVal1);
strVal2.Format("%.2f",iVal[8]);
nLen=strVal2.GetLength();
if(nLen<8)
{
for(int i=0;i<8-nLen;i++)
strVal2="0"+strVal2;
}
m_Meter6.Display(strVal2);
}
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return hbr;
}
BOOL CAboutDlg::OnHelpInfo(HELPINFO* pHelpInfo)
{
// TODO: Add your message handler code here and/or call default
return CDialog::OnHelpInfo(pHelpInfo);
}
void CAboutDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
}
void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnMouseMove(nFlags, point);
}
void CAboutDlg::OnMove(int x, int y)
{
CDialog::OnMove(x, y);
// TODO: Add your message handler code here
}
void CAboutDlg::OnRButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnRButtonDblClk(nFlags, point);
}
void CAboutDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnRButtonUp(nFlags, point);
}
void CAboutDlg::OnCancelMode()
{
CDialog::OnCancelMode();
// TODO: Add your message handler code here
}
void CAboutDlg::OnCaptureChanged(CWnd *pWnd)
{
// TODO: Add your message handler code here
CDialog::OnCaptureChanged(pWnd);
}
void CAboutDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnChar(nChar, nRepCnt, nFlags);
}
int CAboutDlg::OnCharToItem(UINT nChar, CListBox* pListBox, UINT nIndex)
{
// TODO: Add your message handler code here and/or call default
return CDialog::OnCharToItem(nChar, pListBox, nIndex);
}
void CAboutDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
CDialog::OnClose();
}
int CAboutDlg::OnCompareItem(int nIDCtl, LPCOMPAREITEMSTRUCT lpCompareItemStruct)
{
// TODO: Add your message handler code here and/or call default
return CDialog::OnCompareItem(nIDCtl, lpCompareItemStruct);
}
void CAboutDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
}