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

📄 hwcmppapidlg.cpp

📁 C++语言开发的受机短信相关的源程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// HWCmppAPIDlg.cpp : implementation file
//


#include "stdafx.h"
#include "HWCmppAPI.h"
#include "HWCmppAPIDlg.h"
#include "DataConvert.h"

#include "Export.h"
#include "lable.h"
#include "VariantBufConvert.h"

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

CString g_strLog = "ErrorLog.txt";
CString g_strSystemLog = "SystemLog.txt";
HANDLE	g_hLogFile = NULL;
HANDLE	g_hSysLogFile = NULL;
void GfWriteLog(CString str)
{
	if( WaitForSingleObject(g_hLogFile, 100) != WAIT_OBJECT_0 ){
		return;
	}
	CFile f;	
	if(f.Open(g_strLog,CFile::modeWrite|CFile::modeNoTruncate | CFile::modeCreate   ) )
	{
		if(f.GetLength() >= 5000000)
		{
			f.SetLength(0);
		}
		CTime t = CTime::GetCurrentTime();
		CString strTime = t.Format(" %Y-%m-%d %H:%M'%S\r\n");
		str += strTime;
		f.SeekToEnd();
		f.Write(str.GetBuffer(0),str.GetLength());
		f.Close();
	}
	else{
		TRACE("JXMT.txt  file open error!\n");
	}
	ReleaseMutex(g_hLogFile);

}

void GfWriteSysLog(CString str)
{
	if( WaitForSingleObject(g_hSysLogFile, 100) != WAIT_OBJECT_0 ){
		return;
	}
	CFile f;	
	if(f.Open(g_strSystemLog, CFile::modeWrite|CFile::modeNoTruncate | CFile::modeCreate   ) )
	{
		if(f.GetLength() >= 500000)
		{
			f.SetLength(0);
		}
		CTime t = CTime::GetCurrentTime();
		CString strTime = t.Format(" %Y-%m-%d %H:%M'%S\r\n");
		str += strTime;
		f.SeekToEnd();
		f.Write(str.GetBuffer(0),str.GetLength());
		f.Close();
	}

	ReleaseMutex(g_hSysLogFile);
}

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CHWCmppAPIDlg dialog

CHWCmppAPIDlg::CHWCmppAPIDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHWCmppAPIDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHWCmppAPIDlg)
	m_strMONum = _T("");
	m_strMTNum = _T("");
	m_strRTNum = _T("");
	m_strRPNum = _T("");
	m_strQueueIn = _T("");
	m_strQueueOut = _T("");
	m_strMsgCont = _T("");
	m_bIsShowMsg = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_bySendFailNum = 0;
	m_bIsLog = FALSE;
	m_bIsStart = FALSE;
	m_bIsRestarting = FALSE;
//	m_hSendHandle = NULL;
//	m_hRecvHandle = NULL;

	m_hmtxMsgContent = CreateMutex(NULL, FALSE, NULL);
	m_hmtxIsShowMsg = CreateMutex(NULL, FALSE, NULL);

	m_nSendThreadNum = 1;
	m_nRecvThreadNum = 1;

	for(int i=0;i<1000;i++){
//		m_hSend[i] = NULL;
		m_pSendThread[i] = NULL;
	}
	for(i=0;i<10;i++){
//		m_hRecv[i] = NULL;
		m_pRecvThread[i] = NULL;
	}

	m_nMONum=0;
	m_nMTNum=0;
	m_nRTNum=0;
	m_nRPNum=0;
	char chPath[_MAX_PATH] = "";
	GetModuleFileName(NULL, chPath, _MAX_PATH);
	strcpy(strrchr(chPath, '\\'), "\\HWCMPPAPI.ini");	
	m_strIniFilename = chPath;
	LoadParam();
	m_strConnectPara.Format("%s %d 5000", m_chServerIP, m_nServerPort); //"ip port delaytime"
}
CHWCmppAPIDlg::~CHWCmppAPIDlg()
{
	if(!IFExitInterface()){		
		AfxMessageBox("SMEIDLL.dll没有完全卸载,请从任务管理器强制退出该程序!");
	}
//	KillTimer(RestartTimer);
}
void CHWCmppAPIDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHWCmppAPIDlg)
	DDX_Text(pDX, IDC_STATIC_MO, m_strMONum);
	DDX_Text(pDX, IDC_STATIC_MT, m_strMTNum);
	DDX_Text(pDX, IDC_STATIC_RT, m_strRTNum);
	DDX_Text(pDX, IDC_STATIC_RP, m_strRPNum);
	DDX_Text(pDX, IDC_EDIT_QUEUE_UP, m_strQueueIn);
	DDX_Text(pDX, IDC_EDIT_QUEUE_DOWN, m_strQueueOut);
	DDX_Text(pDX, IDC_EDIT_MSG, m_strMsgCont);
	DDX_Check(pDX, IDC_CHECK_SHOW_MSG, m_bIsShowMsg);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CHWCmppAPIDlg, CDialog)
	//{{AFX_MSG_MAP(CHWCmppAPIDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_CONNECT, OnStart)
	ON_WM_TIMER()
	ON_BN_CLICKED(ID_DisConnect, OnStop)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_INIT, OnButtonInit)
	ON_BN_CLICKED(IDC_CHECK_SHOW_MSG, OnCheckShowMsg)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_USER+600,IncreaseSendProcessNum)
	ON_MESSAGE(WM_USER+601,IncreaseRecvProcessNum)
	ON_MESSAGE(WM_USER+605,ShowMessage)//
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHWCmppAPIDlg message handlers
BOOL CHWCmppAPIDlg::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

	CString strTitle;
	char chBuf[50];
	this->GetWindowText(chBuf, 50);
	strTitle = chBuf;
	strTitle += "   启动时间:";
	CTime tm = CTime::GetCurrentTime();
	strTitle += tm.Format("%Y-%m-%d %H:%M");
	this->SetWindowText(strTitle);


	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CHWCmppAPIDlg::LoadParam()
{
	char buf[_MAX_PATH];
	memset (buf, 0, sizeof(buf));
	GetPrivateProfileString("Queue", "InQueue", "DIRECT=OS:Airlink\\private$\\p20up",buf, _MAX_PATH, m_strIniFilename);
	m_strQueueIn = buf;
	GetPrivateProfileString("Queue", "OutQueue", "DIRECT=OS:Airlink\\private$\\p20down", buf, _MAX_PATH, m_strIniFilename);
	m_strQueueOut = buf;
	GetPrivateProfileString("Interface", "ShowCheck", "1", buf, 10, m_strIniFilename);
	m_bIsShowMsg = (BOOL)atoi(buf);	

	GetPrivateProfileString("CMPP", "ServerIP", "", m_chServerIP, sizeof(m_chServerIP), m_strIniFilename);
	GetPrivateProfileString("CMPP", "ServerPort", "7890", buf, 20, m_strIniFilename);
	m_nServerPort = atoi(buf);
	GetPrivateProfileString("CMPP", "SystemID", "", m_chIcpId, sizeof(m_chIcpId), m_strIniFilename);
	GetPrivateProfileString("CMPP", "Password", "", m_chIcpAuth, sizeof(m_chIcpAuth), m_strIniFilename);
	GetPrivateProfileString("CMPP", "SUBMITWINDOW", "1",			 buf		,	10, m_strIniFilename);
	m_nSubmitWindow = atoi(buf);

	GetPrivateProfileString("Config", "SendTimer", "10",			 buf		,	10, m_strIniFilename);
	m_nSendTimer = atoi(buf);
	GetPrivateProfileString("Config", "RecvTimer", "10",			 buf		,	10, m_strIniFilename);
	m_nRecvTimer = atoi(buf);
	GetPrivateProfileString("Config", "ActiveTestTimer", "60000",			 buf		,	10, m_strIniFilename);
	m_nActiveTestTimer = atoi(buf);
	GetPrivateProfileString("Config", "ReLoginTimer", "20000",			 buf		,	10, m_strIniFilename);
	m_nReLoginTimer = atoi(buf);	
	GetPrivateProfileString("Config", "RestartTimer", "720000000",			 buf		,	10, m_strIniFilename);//小于一小时则关闭此功能
	m_nRestartTimer = atoi(buf);

	GetPrivateProfileString("Config", "SendThreadNum", "1",			 buf		,	10, m_strIniFilename);//小于一小时则关闭此功能
	m_nSendThreadNum = atoi(buf);
	if(m_nSendThreadNum > 1000){
		AfxMessageBox("发送线程不能超过1000!最好小于100,现在将置为20!");
		m_nSendThreadNum =20;
	}
	GetPrivateProfileString("Config", "RecvThreadNum", "1",			 buf		,	10, m_strIniFilename);//小于一小时则关闭此功能
	m_nRecvThreadNum = atoi(buf);
	if(m_nRecvThreadNum > 10){
		AfxMessageBox("接收线程不能超过10!将置为1!");
		m_nRecvThreadNum =1;
	}
	GetPrivateProfileString("Debug", "SystenFilename", "SysLog.txt",			 buf		,	10, m_strIniFilename);//小于一小时则关闭此功能
	::g_strSystemLog = buf;
}

void CHWCmppAPIDlg::SaveParam()
{
	char buf[32];

	WritePrivateProfileString("Queue", "InQueue", m_strQueueIn, m_strIniFilename);
	WritePrivateProfileString("Queue", "OutQueue", m_strQueueOut, m_strIniFilename);
	if(m_bIsShowMsg == TRUE){
		WritePrivateProfileString("Interface", "ShowCheck", "1",m_strIniFilename);
	}
	else{
		WritePrivateProfileString("Interface", "ShowCheck", "0", m_strIniFilename);
	}

	WritePrivateProfileString("CMPP", "ServerIP",		m_chServerIP,	 m_strIniFilename);
	itoa(m_nServerPort, buf,10);
	WritePrivateProfileString("CMPP", "ServerPort",		buf,			 m_strIniFilename);
	WritePrivateProfileString("CMPP", "SystemID",			m_chIcpId,		 m_strIniFilename);
	WritePrivateProfileString("CMPP", "Password",		m_chIcpAuth,	 m_strIniFilename);
	itoa(m_nSubmitWindow, buf,10);
	WritePrivateProfileString("CMPP", "SUBMITWINDOW",	buf ,			 m_strIniFilename);
	
	itoa(m_nSendTimer, buf,10);
	WritePrivateProfileString("Config", "SendTimer",	buf ,			 m_strIniFilename);
	itoa(m_nRecvTimer , buf,10);
	WritePrivateProfileString("Config", "RecvTimer",	buf ,			 m_strIniFilename);
	itoa(m_nActiveTestTimer, buf,10);
	WritePrivateProfileString("Config", "ActiveTestTimer",	buf ,			 m_strIniFilename);
	itoa(m_nReLoginTimer, buf,10);
	WritePrivateProfileString("Config", "ReLoginTimer",	buf ,			 m_strIniFilename);
	itoa(m_nRestartTimer, buf,10);
	WritePrivateProfileString("Config", "RestartTimer",	buf ,			 m_strIniFilename);

	itoa(m_nSendThreadNum, buf,10);
	WritePrivateProfileString("Config", "SendThreadNum",	buf ,			 m_strIniFilename);
	itoa(m_nRecvThreadNum, buf,10);
	WritePrivateProfileString("Config", "RecvThreadNum",	buf ,			 m_strIniFilename);

	WritePrivateProfileString("Debug", "SystenFilename",::g_strSystemLog, m_strIniFilename);//小于一小时则关闭此功能
}


void CHWCmppAPIDlg::UpdateInterface()
{
	this->m_strMONum.Format("%d", this->m_nMONum);
	this->m_strMTNum.Format("%d", this->m_nMTNum);
	this->m_strRTNum.Format("%d", this->m_nRTNum);
	this->m_strRPNum.Format("%d", this->m_nRPNum);
	UpdateData(FALSE);
}

void CHWCmppAPIDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	SaveParam();	
	CDialog::OnClose();
}


void CHWCmppAPIDlg::OnButtonInit() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	//初始化接口
/*	CString sConnectPara;
	sConnectPara.Format("%s %d 5000", m_chServerIP, m_nServerPort); //"ip port delaytime"

⌨️ 快捷键说明

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