承接专栏《MFC工控项目实例二十二主界面计数背景颜色改变》
1、在SenSet.h文件中添加代码
#include "BtnST.h"
#include "ShadeButtonST.h"/
// SenSet dialogclass SenSet : public CDialog
{
// Construction
public:SenSet(CWnd* pParent = NULL); // standard constructorCFont m_font;CString m_Path;CString strFilePath;// Dialog Data//{{AFX_DATA(SenSet)enum { IDD = IDD_DIALOG_SEN_TEST };CListCtrl m_IDC_LIST2;CListBox m_IDC_LIST1;CShadeButtonST m_bAdd_2;CShadeButtonST m_bDel_2;CShadeButtonST m_bParameter_2;CShadeButtonST m_bReturn_2;
2、在SenSet.cpp文件中添加代码
#include "stdafx.h"
#include "seal_pressure.h"
#include "SenSet.h"
#include "Data_2.h"
#include "PC60002K.H"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// SenSet dialogSenSet::SenSet(CWnd* pParent /*=NULL*/): CDialog(SenSet::IDD, pParent)
{
m_font.CreateFont(-28,0,0,0,700,FALSE,FALSE,0,134,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS,"楷体_GB2312");TCHAR exeFullPath[MAX_PATH];GetModuleFileName(NULL,exeFullPath,MAX_PATH);m_Path = exeFullPath;for(int i = m_Path.GetLength() - 1; i > 0 ; i --){if(m_Path.GetAt(i) == '\\')break;}SetCurrentDirectory(m_Path);m_Path = m_Path.Left(i);strFilePath= m_Path + "\\Test.ini";nAddr_AD_2=0x110; COMB_Data_AD_Number_2=(sizeof(COMB_Data_AD_2) / sizeof(COMB_Data_AD_2[1]));
}void SenSet::DoDataExchange(CDataExchange* pDX)
{CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(SenSet)DDX_Control(pDX, IDC_LIST2, m_IDC_LIST2);DDX_Control(pDX, IDC_LIST1, m_IDC_LIST1);DDX_Control(pDX, IDC_BUTTON1, m_bAdd_2);DDX_Control(pDX, IDC_BUTTON2, m_bDel_2);DDX_Control(pDX, IDC_BUTTON6, m_bParameter_2);DDX_Control(pDX, IDC_BUTTON7, m_bReturn_2);//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(SenSet, CDialog)//{{AFX_MSG_MAP(SenSet)ON_BN_CLICKED(IDC_BUTTON7, OnButton7)//}}AFX_MSG_MAP
END_MESSAGE_MAP()/
// SenSet message handlersBOOL SenSet::OnInitDialog()
{CDialog::OnInitDialog();m_bAdd_2.SetShade(CShadeButtonST::SHS_HARDBUMP);m_bDel_2.SetShade(CShadeButtonST::SHS_HARDBUMP);m_bParameter_2.SetShade(CShadeButtonST::SHS_HARDBUMP);m_bReturn_2.SetShade(CShadeButtonST::SHS_HARDBUMP);DWORD dwExStyles = m_IDC_LIST2.GetExtendedStyle();m_IDC_LIST2.SetExtendedStyle(dwExStyles |LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT | LVS_EX_FLATSB |LVS_EX_ONECLICKACTIVATE);LVCOLUMN cloumn;int i;cloumn.mask = LVCF_TEXT|LVCF_WIDTH;cloumn.pszText = "序号";cloumn.cx =50;i = m_IDC_LIST2.InsertColumn(0,&cloumn);cloumn.mask = LVCF_TEXT|LVCF_WIDTH;cloumn.pszText = "电压";cloumn.cx =120;i =m_IDC_LIST2.InsertColumn(1,&cloumn);cloumn.pszText = "对应值";cloumn.cx =120;i = m_IDC_LIST2.InsertColumn(2,&cloumn);for( i=0;i<COMB_Data_AD_Number_2;i++){GetPrivateProfileString("AD输入",COMB_Data_AD_2[i],NULL,b_str_AD_2[i].GetBuffer(20),20,strFilePath);if (b_str_AD_2[i]!="-1" ){// AD_2[i]=_ttoi(b_str_AD_2[i]);m_IDC_LIST1.AddString(COMB_Data_AD_2[i]);}}if( OpenDevice6K() != TRUE )
AfxMessageBox("Open device failed!");return TRUE; // return TRUE unless you set the focus to a control// EXCEPTION: OCX Property Pages should return FALSE
}void SenSet::OnButton7()
{EndDialog(IDD_DIALOG_BOA_TEST);}
运行程序