⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tempe_computerdlg.cpp

📁 一个根据热敏电阻的电阻值计算出AD转换值的程序(源码) 采用列表控件,可同时计算出0到159度的电阻值所对应的AD值,AD转换精度8到12位 计算结果可保存可打开(文档操作)
💻 CPP
字号:
// Tempe_ComputerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Tempe_Computer.h"
#include "Tempe_ComputerDlg.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
	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)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTempe_ComputerDlg dialog

CTempe_ComputerDlg::CTempe_ComputerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTempe_ComputerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTempe_ComputerDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTempe_ComputerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTempe_ComputerDlg)
	DDX_Control(pDX, IDC_BUTTON1, m_VCC);
	DDX_Control(pDX, IDC_EDIT4, m_vol_re);
	DDX_Control(pDX, IDC_EDIT2, m_adbit);
	DDX_Control(pDX, IDC_BUTTON2, m_GND);
	DDX_Control(pDX, IDC_STATIC1, m_tempvol);
	DDX_Control(pDX, IDC_EDIT1, m_edit);
	DDX_Control(pDX, IDC_LIST1, m_list);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTempe_ComputerDlg, CDialog)
	//{{AFX_MSG_MAP(CTempe_ComputerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_BN_CLICKED(IDC_BUTTON2, On_updata)
	ON_BN_CLICKED(IDC_BUTTON3, On_computer)
	ON_BN_CLICKED(IDC_BUTTON1, On_input)
	ON_BN_CLICKED(IDC_BUTTON4, On_save)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTempe_ComputerDlg message handlers

BOOL CTempe_ComputerDlg::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
	
	// TODO: Add extra initialization here
	indexcolum=0;indexitem=0;

	m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
m_list.InsertColumn(0,"温度",LVCFMT_CENTER,45);
m_list.InsertColumn(1,"阻值(KΩ)",LVCFMT_CENTER,90);
m_list.InsertColumn(2,"AD转换值",LVCFMT_CENTER,60);
m_list.InsertColumn(3,"温度",LVCFMT_CENTER,45);	
m_list.InsertColumn(4,"阻值(KΩ)",LVCFMT_CENTER,90);	
m_list.InsertColumn(5,"AD转换值",LVCFMT_CENTER,60);
m_list.InsertColumn(6,"温度",LVCFMT_CENTER,45);	
m_list.InsertColumn(7,"阻值(KΩ)",LVCFMT_CENTER,90);	
m_list.InsertColumn(8,"AD转换值",LVCFMT_CENTER,60);
m_list.InsertColumn(9,"温度",LVCFMT_CENTER,45);	
m_list.InsertColumn(10,"阻值(KΩ)",LVCFMT_CENTER,90);	
m_list.InsertColumn(11,"AD转换值",LVCFMT_CENTER,60);

BYTE BB;CString str;
for(BB=0;BB<40;BB++)
{  str.Format("%02d",BB);
	m_list.InsertItem(BB,str);
    str.Format("%02d",(40+BB));
	m_list.SetItemText(BB,3,str);
	str.Format("%02d",(80+BB));
	m_list.SetItemText(BB,6,str);
	str.Format("%02d",(120+BB));
	m_list.SetItemText(BB,9,str);

}
//::PostMessage(m_hWnd,WM_COMMAND,MAKEWPARAM(IDC_RADIO1,BN_CLICKED),0);   
  ::SendMessage(::GetDlgItem(GetSafeHwnd(),   IDC_RADIO1),   WM_LBUTTONDOWN,NULL,NULL);   
  ::SendMessage(::GetDlgItem(GetSafeHwnd(),   IDC_RADIO1),   WM_LBUTTONUP,NULL,NULL);   
	diseditorcombox();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTempe_ComputerDlg::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 CTempe_ComputerDlg::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 CTempe_ComputerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTempe_ComputerDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
int item,colum;
	LVHITTESTINFO* pNMListView = (LVHITTESTINFO*)pNMHDR;
   item=pNMListView->iItem;
   colum=pNMListView->iSubItem;

    indexitem=item;
	if((colum>=0)&&(colum<3))
	indexcolum=0;
	if((colum>=3)&&(colum<6))
	indexcolum=3;
	if((colum>=6)&&(colum<9))
	indexcolum=6;
	if((colum>=9)&&(colum<12))
	indexcolum=9;


   diseditorcombox();
	*pResult = 0;	
}
BOOL  CTempe_ComputerDlg::PreTranslateMessage(MSG*   pMsg)     
  {   
    
          //if   ((pMsg->message   ==WM_KEYDOWN   &&   pMsg->wParam   ==VK_RETURN )   ) 
	 
	if   (pMsg->wParam  ==VK_RETURN )   
	{ 
		On_updata();
		return   TRUE; 
	}
	if   (pMsg->message==WM_KEYUP)return   TRUE;  
   if   (pMsg->wParam  ==VK_LEFT )   
   {   
	   
	   indexcolum-=3;
	   if(indexcolum<0)indexcolum=9;
      if((indexitem<0)||(indexitem>39)){indexitem=0;}
       diseditorcombox();
	   return   TRUE; 
   }
   if   (pMsg->wParam  ==VK_RIGHT )   
   {
	   
	    indexcolum+=3;
        if(indexcolum>9)indexcolum=0;
      if((indexitem<0)||(indexitem>39)){indexitem=0;}
       diseditorcombox();
	   return   TRUE; 
   }
   if   (pMsg->wParam  ==VK_UP )   
   {
	 
	   indexitem-=1;if(indexitem<0)indexitem=39;
      if((indexcolum<0)||(indexcolum>9)){indexcolum=0;}
       diseditorcombox();
	   return   TRUE; 
   }
   if   (pMsg->wParam  ==VK_DOWN )   
   {
	   
	   
		indexitem+=1;if(indexitem>39)indexitem=0;
      if((indexcolum<0)||(indexcolum>9)){indexcolum=0;}
       diseditorcombox();
	   return   TRUE;  
   }


return   CDialog::PreTranslateMessage(pMsg);   
  }   
void CTempe_ComputerDlg::diseditorcombox()
{	editstr=m_list.GetItemText(indexitem,indexcolum);
dd:if(editstr!="0")
if(editstr.GetAt(0)=='0')
  {editstr.Delete(0,1);
   goto dd;
  }
    editstr="所选温度值:"+editstr+"度";
    m_tempvol.SetWindowText(editstr);
	editstr=m_list.GetItemText(indexitem,indexcolum+1);
    m_edit.SetWindowText(editstr);
    m_edit.SetFocus();
	m_edit.SetSel( 20,20, FALSE );


}

void CTempe_ComputerDlg::On_updata() 
{
	CString str;
	 str="";
	m_edit.GetWindowText(str);
	m_list.SetItemText(indexitem,indexcolum+1,str);
	
}

void CTempe_ComputerDlg::On_computer() 
{  BYTE BB;bool flag;
	unsigned short ADVAL,addat;CString temp;double rd,rt,rval,dbtemp;
	flag=0;
	if(m_GND.GetCheck()!=1)flag=1;

   m_adbit.GetWindowText(temp);
   ADVAL=atoi(temp);
   if(ADVAL<8)ADVAL=8;
   if(ADVAL>12)ADVAL=10;
   switch(ADVAL)
   {case 8:ADVAL=256;break;
    case 9:ADVAL=512;break;
	case 10:ADVAL=1024;break;
	case 11:ADVAL=2048;break;
	case 12:ADVAL=4096;break; 
   }
   
  
  
   m_vol_re.GetWindowText(temp);
   rd=atof(temp);
   if(rd<1)rd=47;

   for(BB=0;BB<40;BB++)
   {
	  temp=m_list.GetItemText(BB,1);
     rt=atof(temp);
	 if(rt>0)
	 {
	   if(flag)addat=(ADVAL*rd)/(rd+rt);
	   else addat=(ADVAL*rt)/(rd+rt);
	   temp.Format("%04d",addat);
       m_list.SetItemText(BB,2,temp);
	 }

	 temp=m_list.GetItemText(BB,4);
     rt=atof(temp);
	 if(rt>0)
	 {
	   if(flag)addat=(ADVAL*rd)/(rd+rt);
	   else addat=(ADVAL*rt)/(rd+rt);
	   temp.Format("%04d",addat);
       m_list.SetItemText(BB,5,temp);
	 }

	 temp=m_list.GetItemText(BB,7);
     rt=atof(temp);
	 if(rt>0)
	 {
	   if(flag)addat=(ADVAL*rd)/(rd+rt);
	   else addat=(ADVAL*rt)/(rd+rt);
	   temp.Format("%04d",addat);
       m_list.SetItemText(BB,8,temp);
	 }

	 temp=m_list.GetItemText(BB,10);
     rt=atof(temp);
	 if(rt>0)
	 {
	   if(flag)addat=(ADVAL*rd)/(rd+rt);
	   else addat=(ADVAL*rt)/(rd+rt);
	   temp.Format("%04d",addat);
       m_list.SetItemText(BB,11,temp);
	 }



	
   }


	
}

void CTempe_ComputerDlg::On_input() 
{  BYTE BB;
	if(computer_save.open())
	{
		if(computer_save.GNDORVCC==0)
		{::SendMessage(::GetDlgItem(GetSafeHwnd(),   IDC_RADIO1),   WM_LBUTTONDOWN,NULL,NULL);   
         ::SendMessage(::GetDlgItem(GetSafeHwnd(),   IDC_RADIO1),   WM_LBUTTONUP,NULL,NULL);   
		}
	  else 
	  {::SendMessage(::GetDlgItem(GetSafeHwnd(),   IDC_RADIO2),   WM_LBUTTONDOWN,NULL,NULL);   
       ::SendMessage(::GetDlgItem(GetSafeHwnd(),   IDC_RADIO2),   WM_LBUTTONUP,NULL,NULL);   
	  }
       m_adbit.SetWindowText(computer_save.conver_bit);
	   m_vol_re.SetWindowText(computer_save.resister_vol);

	   for(BB=0;BB<40;BB++)
	   { 
		   m_list.SetItemText(BB,1,computer_save.TEMP_VOL[BB*4]);
	       m_list.SetItemText(BB,4,computer_save.TEMP_VOL[BB*4+1]);
	       m_list.SetItemText(BB,7,computer_save.TEMP_VOL[BB*4+2]);
	       m_list.SetItemText(BB,10,computer_save.TEMP_VOL[BB*4+3]);

	  m_list.SetItemText(BB,2,computer_save.ADC_VOL[BB*4]);
	  m_list.SetItemText(BB,5,computer_save.ADC_VOL[BB*4+1]);
	  m_list.SetItemText(BB,8,computer_save.ADC_VOL[BB*4+2]);
	  m_list.SetItemText(BB,11,computer_save.ADC_VOL[BB*4+3]);
	}
  
	}
  	
	
}

void CTempe_ComputerDlg::On_save() 
{   BYTE BB;
	int checkint=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2);
	if(checkint==IDC_RADIO1)computer_save.GNDORVCC=0;
	else 
		computer_save.GNDORVCC=1;
	m_adbit.GetWindowText(computer_save.conver_bit);
    m_vol_re.GetWindowText(computer_save.resister_vol);
	for(BB=0;BB<40;BB++)
	{ computer_save.TEMP_VOL[BB*4]=m_list.GetItemText(BB,1);
	  computer_save.TEMP_VOL[BB*4+1]=m_list.GetItemText(BB,4);
	  computer_save.TEMP_VOL[BB*4+2]=m_list.GetItemText(BB,7);
	  computer_save.TEMP_VOL[BB*4+3]=m_list.GetItemText(BB,10);

	  computer_save.ADC_VOL[BB*4]=m_list.GetItemText(BB,2);
	  computer_save.ADC_VOL[BB*4+1]=m_list.GetItemText(BB,5);
	  computer_save.ADC_VOL[BB*4+2]=m_list.GetItemText(BB,8);
	  computer_save.ADC_VOL[BB*4+3]=m_list.GetItemText(BB,11);
	}
   	computer_save.save();
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -