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

📄 config.cpp

📁 wince无线点菜软件,具备常规点菜的所有功能,可直接使用
💻 CPP
字号:
// config.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "config.h"

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

/////////////////////////////////////////////////////////////////////////////
// Cconfig dialog


Cconfig::Cconfig(CWnd* pParent /*=NULL*/)
	: CDialog(Cconfig::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cconfig)
	m_ip1 = _T("");
	m_ip2 = _T("");
	m_ip3 = _T("");
	m_ip4 = _T("");
	m_port = _T("");
	m_taiweilen = _T("");
	m_caipulen = _T("");
	//}}AFX_DATA_INIT
}


void Cconfig::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cconfig)
	DDX_Control(pDX, IDOK, m_ok);
	DDX_Control(pDX, IDC_EDIT_TAIWEI, m_ctaiweilen);
	DDX_Control(pDX, IDC_EDIT_PORT, m_cport);
	DDX_Control(pDX, IDC_EDIT_IP4, m_cip4);
	DDX_Control(pDX, IDC_EDIT_IP3, m_cip3);
	DDX_Control(pDX, IDC_EDIT_IP2, m_cip2);
	DDX_Control(pDX, IDC_EDIT_IP1, m_cip1);
	DDX_Control(pDX, IDC_EDIT_CAIPU, m_ccaipulen);
	DDX_Text(pDX, IDC_EDIT_IP1, m_ip1);
	DDV_MaxChars(pDX, m_ip1, 3);
	DDX_Text(pDX, IDC_EDIT_IP2, m_ip2);
	DDV_MaxChars(pDX, m_ip2, 3);
	DDX_Text(pDX, IDC_EDIT_IP3, m_ip3);
	DDV_MaxChars(pDX, m_ip3, 3);
	DDX_Text(pDX, IDC_EDIT_IP4, m_ip4);
	DDV_MaxChars(pDX, m_ip4, 3);
	DDX_Text(pDX, IDC_EDIT_PORT, m_port);
	DDV_MaxChars(pDX, m_port, 4);
	DDX_Text(pDX, IDC_EDIT_TAIWEI, m_taiweilen);
	DDV_MaxChars(pDX, m_taiweilen, 2);
	DDX_Text(pDX, IDC_EDIT_CAIPU, m_caipulen);
	DDV_MaxChars(pDX, m_caipulen, 2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cconfig, CDialog)
	//{{AFX_MSG_MAP(Cconfig)
	ON_EN_MAXTEXT(IDC_EDIT_IP1, OnMaxtextEditIp1)
	ON_EN_MAXTEXT(IDC_EDIT_IP2, OnMaxtextEditIp2)
	ON_EN_MAXTEXT(IDC_EDIT_IP3, OnMaxtextEditIp3)
	ON_EN_MAXTEXT(IDC_EDIT_IP4, OnMaxtextEditIp4)
	ON_EN_MAXTEXT(IDC_EDIT_PORT, OnMaxtextEditPort)
	ON_EN_MAXTEXT(IDC_EDIT_TAIWEI, OnMaxtextEditTaiwei)
	ON_EN_MAXTEXT(IDC_EDIT_CAIPU, OnMaxtextEditCaipu)
	ON_EN_CHANGE(IDC_EDIT_IP1, OnChangeEditIp1)
	ON_EN_SETFOCUS(IDC_EDIT_IP1, OnSetfocusEditIp1)
	ON_EN_CHANGE(IDC_EDIT_IP2, OnChangeEditIp2)
	ON_EN_SETFOCUS(IDC_EDIT_IP2, OnSetfocusEditIp2)
	ON_EN_CHANGE(IDC_EDIT_IP3, OnChangeEditIp3)
	ON_EN_SETFOCUS(IDC_EDIT_IP3, OnSetfocusEditIp3)
	ON_EN_CHANGE(IDC_EDIT_IP4, OnChangeEditIp4)
	ON_EN_SETFOCUS(IDC_EDIT_IP4, OnSetfocusEditIp4)
	ON_EN_CHANGE(IDC_EDIT_PORT, OnChangeEditPort)
	ON_EN_SETFOCUS(IDC_EDIT_PORT, OnSetfocusEditPort)
	ON_EN_CHANGE(IDC_EDIT_TAIWEI, OnChangeEditTaiwei)
	ON_EN_SETFOCUS(IDC_EDIT_TAIWEI, OnSetfocusEditTaiwei)
	ON_EN_CHANGE(IDC_EDIT_CAIPU, OnChangeEditCaipu)
	ON_EN_SETFOCUS(IDC_EDIT_CAIPU, OnSetfocusEditCaipu)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cconfig message handlers

void Cconfig::OnOK() 
{
	u_short portid;
	u_long SAddr;
	int taiweilen,caipulen;
	char s[21];
	HANDLE hFile;
	unsigned long len;
	
	UpdateData(TRUE);
	WideCharToMultiByte(CP_ACP,0,m_ip1,-1,s,20,NULL,NULL);
	SAddr=atoi(s)*256*256*256;
	WideCharToMultiByte(CP_ACP,0,m_ip2,-1,s,20,NULL,NULL);
	SAddr=SAddr+atoi(s)*256*256;
	WideCharToMultiByte(CP_ACP,0,m_ip3,-1,s,20,NULL,NULL);
	SAddr=SAddr+atoi(s)*256;
	WideCharToMultiByte(CP_ACP,0,m_ip4,-1,s,20,NULL,NULL);
	SAddr=SAddr+atoi(s);
	WideCharToMultiByte(CP_ACP,0,m_port,-1,s,20,NULL,NULL);
	portid=atoi(s);
	WideCharToMultiByte(CP_ACP,0,m_taiweilen,-1,s,20,NULL,NULL);
	taiweilen=atoi(s);
	WideCharToMultiByte(CP_ACP,0,m_caipulen,-1,s,20,NULL,NULL);
	caipulen=atoi(s);
	SAddr=htonl(SAddr);
	portid=htons(portid);
	hFile = CreateFile(CONFIGFILE, GENERIC_WRITE, FILE_SHARE_WRITE,
         NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	WriteFile(hFile,&SAddr,4,&len,NULL);
	WriteFile(hFile,&portid,2,&len,NULL);
	WriteFile(hFile,&taiweilen,4,&len,NULL);
	WriteFile(hFile,&caipulen,4,&len,NULL);
	WriteFile(hFile,"",1,&len,NULL);
	CloseHandle(hFile);
	CDialog::OnOK();
}

BOOL Cconfig::OnInitDialog() 
{
	CDialog::OnInitDialog();
		
	u_short portid;
	u_long SAddr;
	int taiweilen,caipulen;
	WCHAR wcCode[21];
	HANDLE hFile;
	unsigned long len;

	hFile = CreateFile(CONFIGFILE, GENERIC_READ, FILE_SHARE_READ,
         NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile!=NULL) 
	{
	
		ReadFile(hFile,&SAddr,4,&len,NULL);
		ReadFile(hFile,&portid,2,&len,NULL);
		ReadFile(hFile,&taiweilen,4,&len,NULL);
		ReadFile(hFile,&caipulen,4,&len,NULL);
		CloseHandle(hFile);
		SAddr=ntohl(SAddr);
		portid=ntohs(portid);
		swprintf(wcCode,L"%3d",SAddr/(256*256*256));
		m_ip1=wcCode;
		swprintf(wcCode,L"%3d",(SAddr&0x00ff0000)>>16);
		m_ip2=wcCode;
		swprintf(wcCode,L"%3d",(SAddr&0x0000ff00)>>8);
		m_ip3=wcCode;
		swprintf(wcCode,L"%3d",SAddr&0x000000ff);
		m_ip4=wcCode;
		swprintf(wcCode,L"%4d",portid);
		m_port=wcCode;
		swprintf(wcCode,L"%2d",taiweilen);
		m_taiweilen=wcCode;
		swprintf(wcCode,L"%2d",caipulen);
		m_caipulen=wcCode;
		UpdateData(FALSE);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void Cconfig::OnMaxtextEditIp1() 
{
	m_cip2.SetFocus();	
}

void Cconfig::OnMaxtextEditIp2() 
{
	m_cip3.SetFocus();		
}

void Cconfig::OnMaxtextEditIp3() 
{
	m_cip4.SetFocus();
}

void Cconfig::OnMaxtextEditIp4() 
{
	m_cport.SetFocus();		
}

void Cconfig::OnMaxtextEditPort() 
{
	m_ctaiweilen.SetFocus();		
}

void Cconfig::OnMaxtextEditTaiwei() 
{
	m_ccaipulen.SetFocus();		
}

void Cconfig::OnMaxtextEditCaipu() 
{
	m_ok.SetFocus();		
}

void Cconfig::OnChangeEditIp1() 
{
	UpdateData(TRUE);
	if (m_ip1.GetLength()>=3) m_cip2.SetFocus();	
}

void Cconfig::OnSetfocusEditIp1() 
{
	m_cip1.SetSel(0,-1);	
}

void Cconfig::OnChangeEditIp2() 
{
	UpdateData(TRUE);
	if (m_ip2.GetLength()>=3) m_cip3.SetFocus();
	
}

void Cconfig::OnSetfocusEditIp2() 
{
	m_cip2.SetSel(0,-1);
}

void Cconfig::OnChangeEditIp3() 
{
	UpdateData(TRUE);
	if (m_ip3.GetLength()>=3) m_cip4.SetFocus();
}

void Cconfig::OnSetfocusEditIp3() 
{
	m_cip3.SetSel(0,-1);
}

void Cconfig::OnChangeEditIp4() 
{
	UpdateData(TRUE);
	if (m_ip4.GetLength()>=3) m_cport.SetFocus();
}

void Cconfig::OnSetfocusEditIp4() 
{
	m_cip4.SetSel(0,-1);
}

void Cconfig::OnChangeEditPort() 
{
	UpdateData(TRUE);
	if (m_port.GetLength()>=4) m_ctaiweilen.SetFocus();
}

void Cconfig::OnSetfocusEditPort() 
{
	m_cport.SetSel(0,-1);
}

void Cconfig::OnChangeEditTaiwei() 
{
	UpdateData(TRUE);
	if (m_taiweilen.GetLength()>=2) m_ccaipulen.SetFocus();
	
}

void Cconfig::OnSetfocusEditTaiwei() 
{
	m_ctaiweilen.SetSel(0,-1);
}

void Cconfig::OnChangeEditCaipu() 
{
	UpdateData(TRUE);
	if (m_caipulen.GetLength()>=2) m_ok.SetFocus();
	
}

void Cconfig::OnSetfocusEditCaipu() 
{
	m_ccaipulen.SetSel(0,-1);
}

⌨️ 快捷键说明

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