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

📄 setserver.cpp

📁 客户端: 这是一个完整的基于Wince 4.1图形图象,网络通讯(C/S)模式下的商用程序源代码包.
💻 CPP
字号:
// SetServer.cpp : implementation file
//

#include "stdafx.h"
#include "PPPClient.h"
#include "SetServer.h"
#include "pppclientdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern SYSTEM_PARAMETER m_system_para;
extern CPPPClientDlg *m_main_dlg;
extern CString m_ini_pathname;
/////////////////////////////////////////////////////////////////////////////
// CSetServer dialog


CSetServer::CSetServer(CWnd* pParent /*=NULL*/)
	: CDialog(CSetServer::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSetServer)
	m_autorun_flag = FALSE;
	m_rundogwatch_flag = FALSE;
	m_savepath_str = _T("");
	m_timeout = 0;
	//}}AFX_DATA_INIT
}


void CSetServer::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetServer)
	DDX_Control(pDX, IDC_SOFTMODE_COMBO, m_softmode_combobox);
	DDX_Control(pDX, IDC_DATETIMEPICKER, m_datetimectrl);
	DDX_Control(pDX, IDC_OKSERVER_BUTTON, m_okserverbtn);
	DDX_Control(pDX, IDC_SETSERVER_BUTTON, m_setserverbtn);
	DDX_Control(pDX, IDC_SERVER_IPADDRESS, m_serverip);
	DDX_Check(pDX, IDC_AUTORUN_CHECK, m_autorun_flag);
	DDX_Check(pDX, IDC_RUNWATCHDOG_CHECK, m_rundogwatch_flag);
	DDX_Text(pDX, IDC_SAVEPATH_EDIT, m_savepath_str);
	DDX_Text(pDX, IDC_TIMEOUT_EDIT, m_timeout);
	DDV_MinMaxLong(pDX, m_timeout, 0, 180);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetServer, CDialog)
	//{{AFX_MSG_MAP(CSetServer)
	ON_BN_CLICKED(IDC_OKSERVER_BUTTON, OnOkserverButton)
	ON_BN_CLICKED(IDC_SETSERVER_BUTTON, OnSetserverButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetServer message handlers

BOOL CSetServer::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	 //将CString  型IP地址在IPAddressCtrl中显示  
     //CString  strIP="127.0.0.1";  
	 /*CString  strIP="192.168.1.2";  
     DWORD  dwIP;  
     dwIP  =  inet_addr(strIP);  
     unsigned  char  *pIP  =  (unsigned  char*)&dwIP;  
     m_ipaddr.SetAddress(*pIP,  *(pIP+1),  *(pIP+2),  *(pIP+3)); 	
	//将IPAddressCtrl中的IP地址获得并转换成CString型  
     unsigned  char  *pIP;  
     CString  ipstr;  
     DWORD  dwIP;  
     m_ipaddr.GetAddress(dwIP);  
     pIP  =  (unsigned  char*)&dwIP;  
     ipstr.Format("%u.%u.%u.%u",*(pIP+3),  *(pIP+2),  *(pIP+1),  *pIP);
	 //
	char ServerAddr[256];
	strcpy(ServerAddr,ipstr.GetBuffer(ipstr.GetLength()));
	*/
	//server ip	
	 CString ipstr(m_system_para.m_server_ip); 
     DWORD  dwIP;  
     dwIP  =  inet_addr(ipstr);  
     unsigned  char  *pIP  =  (unsigned  char*)&dwIP;  
     m_serverip.SetAddress(*pIP,  *(pIP+1),  *(pIP+2),  *(pIP+3)); 
	 //auto run system
	 if(m_system_para.m_auto_run_flag==0)
		 m_autorun_flag=FALSE;
	 else
         m_autorun_flag=TRUE;
	//run watch dog
    if(m_system_para.m_watchdog_flag==0) 		
		 m_rundogwatch_flag=FALSE;
	 else
        m_rundogwatch_flag=TRUE;
	 m_savepath_str=m_system_para.m_savepath_str;
	 //auto reset server time
	 COleDateTime m_oledatetime(2006,9,1,m_system_para.hour,m_system_para.minute,m_system_para.second);
	 m_datetimectrl.SetTime(m_oledatetime); 
     //softmode
	 m_softmode_combobox.ResetContent();	
	 m_softmode_combobox.AddString("Stand-alone"); 
	 m_softmode_combobox.AddString("Network-client"); 	  	 
	//
	 m_softmode_combobox.SetCurSel(m_system_para.softmode);  
	 //
    CSpinButtonCtrl *pSpin=(CSpinButtonCtrl *)GetDlgItem(IDC_TIMEOUT_SPIN);
	ASSERT(pSpin!=NULL);
	pSpin->SetBuddy(GetDlgItem(IDC_TIMEOUT_EDIT));
	pSpin->SetRange(0,180);
	//pSpin->SetPos(m_system_para.timeout);
    m_timeout=m_system_para.timeout;

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

void CSetServer::OnOkserverButton() 
{
	// TODO: Add your control notification handler code here
	
    EndDialog(0);	
}

void CSetServer::OnSetserverButton() 
{
	// TODO: Add your control notification handler code here
	//set
    UpdateData();
    //将IPAddressCtrl中的IP地址获得并转换成CString型  
     unsigned  char  *pIP;  
     CString  ipstr;  
     DWORD  dwIP;  
     m_serverip.GetAddress(dwIP);  
     pIP  =  (unsigned  char*)&dwIP;  
     ipstr.Format("%u.%u.%u.%u",*(pIP+3),  *(pIP+2),  *(pIP+1),  *pIP);
	 //
	//char ServerAddr[256];
	strcpy(m_system_para.m_server_ip,ipstr.GetBuffer(ipstr.GetLength()));
	//
	if(m_autorun_flag)
     m_system_para.m_auto_run_flag=1;
	else
     m_system_para.m_auto_run_flag=0;
	//
	if(m_rundogwatch_flag)
      m_system_para.m_watchdog_flag=1;
	else
      m_system_para.m_watchdog_flag=0;
	//
	strcpy(m_system_para.m_savepath_str,m_savepath_str.GetBuffer(m_savepath_str.GetLength())); 
    //
	COleDateTime m_oledatetime;
	m_datetimectrl.GetTime(m_oledatetime);

    //hour
	m_system_para.hour =m_oledatetime.GetHour();
	//minute
	m_system_para.minute =m_oledatetime.GetMinute();
	//second
	m_system_para.second =m_oledatetime.GetSecond();
	//softmode
	m_system_para.softmode =m_softmode_combobox.GetCurSel();
	//timeout
	m_system_para.timeout =m_timeout;
	//save file
	 FILE *fp;
	 fp=fopen(m_ini_pathname,"wb");
	 if(fp)
	 {
       fwrite((char*)&m_system_para,1,sizeof(SYSTEM_PARAMETER),fp);  	   
       fclose(fp);
	 }
	 //network-client
	 if(m_system_para.softmode)
	 {
	  //send auto watchdog
      //m_main_dlg->SetAutoWatchDog( m_system_para.m_watchdog_flag==1?1:2);
	 m_main_dlg->SetAutoWatchDog( m_system_para.m_watchdog_flag==1?1:2);
	
	 //
	 if(m_main_dlg->SetServerOnline())
	 {
	 //send auto playtable
	  m_main_dlg->SetAutoRunPlayTable( m_system_para.m_auto_run_flag==1?1:2);
	 //send save directory
	  m_main_dlg->SetServerSaveDIR(m_system_para.m_savepath_str);
	  //set auto reset server time
	  m_main_dlg->SetAutoResetServerTimes(m_system_para.hour,m_system_para.minute,m_system_para.second);

	 }
	 else
	 {
		 CString str;
		 str.Format("IP:(%s) may be not exist!",m_system_para.m_server_ip); 	  
         m_main_dlg->ShowMessage(str);  
	 }
	}

	EndDialog(0);
}

⌨️ 快捷键说明

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