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

📄 entertext.cpp

📁 串口 操作 源码 打标机的控制程序
💻 CPP
字号:
// EnterText.cpp : implementation file
//

#include "stdafx.h"
#include "dabiao.h"
#include "EnterText.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEnterText dialog


CEnterText::CEnterText(CWnd* pParent /*=NULL*/)
	: CDialog(CEnterText::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEnterText)
	m_date = FALSE;
	m_far = 0;
	m_no = FALSE;
	m_string = _T("");
	m_text = FALSE;
	m_high = 0;
	m_time = FALSE;
	m_width = 0;
	m_posx = 0;
	m_posy = 0;
	//}}AFX_DATA_INIT
	
	m_bHaveFont=false;
}


void CEnterText::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEnterText)
	DDX_Control(pDX, IDC_string, m_Com_String);
	DDX_Check(pDX, IDC_date, m_date);
	DDX_Text(pDX, IDC_f, m_far);
	DDX_Check(pDX, IDC_no, m_no);
	DDX_Text(pDX, IDC_string, m_string);
	DDX_Check(pDX, IDC_text, m_text);
	DDX_Text(pDX, IDC_h, m_high);
	DDX_Check(pDX, IDC_time, m_time);
	DDX_Text(pDX, IDC_w, m_width);
	DDX_Text(pDX, IDC_x, m_posx);
	DDX_Text(pDX, IDC_y, m_posy);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CEnterText, CDialog)
	//{{AFX_MSG_MAP(CEnterText)
	ON_BN_CLICKED(IDC_date, Ondate)
	ON_BN_CLICKED(IDC_no, Onno)
	ON_BN_CLICKED(IDC_text, Ontext)
	ON_BN_CLICKED(IDC_time, Ontime)
	ON_BN_CLICKED(IDC_BUTTON_Font, OnBUTTONFont)
	ON_CBN_SELCHANGE(IDC_string, OnSelchangestring)
	ON_WM_CLOSE()
	ON_WM_DESTROY()
	ON_WM_SHOWWINDOW()
	ON_WM_CREATE()
	ON_COMMAND(ID_TTEXTOUT, OnTtextout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEnterText message handlers

void CEnterText::Ondate() 
{	
	UpdateData(TRUE);
	m_no = FALSE;
    m_text = FALSE;
	m_time =FALSE;
    CString	buffer;
	while(m_Com_String.DeleteString(0)&&m_Com_String.DeleteString(0)!=CB_ERR);
	if(m_date == TRUE)
		{
		   
	       buffer.Format("%04d_%02d_%02d",
				CTime::GetCurrentTime().GetYear(),
				CTime::GetCurrentTime().GetMonth(),
				CTime::GetCurrentTime().GetDay());
               m_Com_String.AddString(buffer);
                  
	      buffer.Format("%04d.%02d.%02d",
				CTime::GetCurrentTime().GetYear(),
				CTime::GetCurrentTime().GetMonth(),
				CTime::GetCurrentTime().GetDay());
                m_Com_String.AddString(buffer);
			
		buffer.Format("%04d/%02d/%02d",
				CTime::GetCurrentTime().GetYear(),
				CTime::GetCurrentTime().GetMonth(),
				CTime::GetCurrentTime().GetDay());
                m_Com_String.AddString(buffer); 
			}
     m_string=buffer;
	 UpdateData(FALSE);	
	 m_Com_String.SetCurSel(0);
}

void CEnterText::Onno() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CFile file;
	CFileStatus Status;
	char startno[6];
    while(m_Com_String.DeleteString(0)&&m_Com_String.DeleteString(0)!=CB_ERR);
	if(!file.GetStatus(_T("backup.txt"),Status))
	{
	file.Open(_T("backup.txt"),CFile::modeCreate|CFile::modeReadWrite);
	file.Close();
	return;
	}
	file.Open(_T("backup.txt"),CFile::modeReadWrite);
		
	UINT nbyte=file.Read(startno,6);
		if(nbyte!=6)
		  {
	  //       AfxMessageBox("读取初试流水号出错!");
	//		 return;
		  }
	      file.Close();
	m_string=startno;
    m_date=FALSE;
	m_text=FALSE;
	m_time=FALSE;
	m_no=TRUE;
	UpdateData(FALSE);
}

void CEnterText::Ontext() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
    while(m_Com_String.DeleteString(0)&&m_Com_String.DeleteString(0)!=CB_ERR);
	m_text=TRUE;
	m_no=FALSE;
	m_date=FALSE;
	m_time=FALSE;
	m_string="";
    UpdateData(FALSE);
}

void CEnterText::Ontime() 
{
	// TODO: Add your control notification handler code here
		// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_no = FALSE;
    m_text = FALSE;
	m_date = FALSE;
    CString	buffer;
 while(m_Com_String.DeleteString(0)&&m_Com_String.DeleteString(0)!=CB_ERR);
	if(m_time == TRUE)
	{
	            buffer.Format("%02d:%02d",
				CTime::GetCurrentTime().GetHour(),
				CTime::GetCurrentTime().GetMinute());
		//		CTime::GetCurrentTime().GetSecond());
				m_Com_String.AddString(buffer);
//
	//		buffer.Format("%02d:%02d",
	//			CTime::GetCurrentTime().GetHour(),
	//			CTime::GetCurrentTime().GetMinute());
	//		m_Com_String.AddString(buffer);

	}
     m_string=buffer;
	 UpdateData(FALSE);
	 m_Com_String.SetCurSel(0);
	//}
}

void CEnterText::OnBUTTONFont() 
{
	// TODO: Add your control notification handler code here
	CFontDialog dlg;
	if(dlg.DoModal()==IDOK)
	{
	    m_bHaveFont=true;
		memcpy(&m_lf, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
	}
	

}

BOOL CEnterText::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	
    CFont l_Font;
	CClientDC dc(this);
	l_Font.CreatePointFont(700,"Arial",&dc);
	l_Font.GetLogFont(&m_lf);

  

	
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


extern datetype;
void CEnterText::OnSelchangestring() 
{
	// TODO: Add your control notification handler code here
 datetype=m_Com_String.GetCurSel();
}

void CEnterText::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	
	m_DateType=m_Com_String.GetCurSel();
	m_TimeType=m_Com_String.GetCurSel();
	CDialog::OnClose();
}

void CEnterText::OnDestroy() 
{
	CDialog::OnDestroy();

	m_DateType=m_Com_String.GetCurSel();
		m_TimeType=m_Com_String.GetCurSel();
	    CDialog::OnClose(); 
	// TODO: Add your message handler code here
	
}

void CEnterText::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
if(m_no==FALSE&&m_date==TRUE&&m_text==FALSE&&m_time==FALSE)
{	   
		this->Ondate();

}	
	
	
	// TODO: Add your message handler code here

}

int CEnterText::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO: Add your specialized creation code here
	
	return 0;
}

int CEnterText::DoModal() 
{
	// TODO: Add your specialized code here and/or call the base class
                	
	

	return CDialog::DoModal();
}

void CEnterText::OnTtextout() 
{
	// TODO: Add your command handler code here
	
}

⌨️ 快捷键说明

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