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

📄 clientdlg.cpp

📁 socket编程
💻 CPP
字号:
// ClientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Client.h"
#include "ClientDlg.h"
#include "Resource.h"

#include "ProcFunc.h"

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

//char * g_IniFile	;	//[256] ;
TCHAR g_IniFile[256] ;

/////////////////////////////////////////////////////////////////////////////
// CClientDlg dialog

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

	ZeroMemory( g_IniFile , 256 ) ;

	//memset( g_IniFile , '\0' , 256 ) ;

	DWORD dwans = GetCurrentDirectory( 256 , g_IniFile );
	if ( dwans <= 0 )
	{
		return ;
	}

	_tcscpy(&g_IniFile[_tcslen(g_IniFile)] , _TEXT("\\Client.ini") ) ;
}

void CClientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClientDlg)
	DDX_Check(pDX, IDC_CODECHG, m_CodeChg);
	DDX_CBIndex(pDX, IDC_COMBO1, m_ClientCode);
	DDX_CBIndex(pDX, IDC_COMBO2, m_SvrCode);
	DDX_Check(pDX, IDC_BINTYPE, m_bBinType);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
	//{{AFX_MSG_MAP(CClientDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_STORE, OnStore)
	ON_BN_CLICKED(IDC_GET, OnGet)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClientDlg message handlers

BOOL CClientDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	CComboBox * pCtrl ;

	pCtrl = (CComboBox*)GetDlgItem(IDC_COMBO1) ;
	pCtrl->SetCurSel(0) ;
	
	pCtrl = (CComboBox*)GetDlgItem(IDC_COMBO2) ;
	pCtrl->SetCurSel(0) ;

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

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


void CClientDlg::OnStore() 
{
	this->UpdateData(true) ;

	CString	pData	;
	CWnd *	pCtrl	;
	LPTSTR	p_data	;
	LPTSTR	p_tmp = NULL	;//for hz transform use

	pCtrl = GetDlgItem(IDC_SENDDATA) ;
	pCtrl->GetWindowText(pData) ;

	if ( pData.GetLength() == 0 ) 
	{
		MessageBox(_T("Please input data!"));
		return ;
	}
	
	if ( pData.GetLength() > 500 ) 
	{
		MessageBox(_T("The input data is too long!"));
		return ;
	}

	p_data = (LPTSTR)LPCTSTR(pData) ;

	// hz transform
	if ( (this->m_CodeChg == TRUE) && (this->m_ClientCode!=this->m_SvrCode) )
	{
		// Client : GB ; Server : BIG 5
		if( (this->m_ClientCode==0) && (this->m_SvrCode==1) )
		{
			Covert_HZCode(p_data , &p_tmp , GB_2_BIG5) ;
		}
		// Client : BIG 5 ; Server : GB
		else if( (this->m_ClientCode==1) && (this->m_SvrCode==0) )
		{
			Covert_HZCode(p_data , &p_tmp , BIG5_2_GB) ;
		}
		p_data = p_tmp ;
		
	}
	
	Func_StoreData( p_data ,this->m_bBinType);

	if ( p_tmp )
	{
		delete[]p_tmp ;
		p_tmp = NULL ;
	}

}

void CClientDlg::OnGet() 
{
	int num , i ;
	LPTSTR p_data[1024];
	LPTSTR p_tmp;// for hz transform use

	CListBox * pList ;
	pList = (CListBox*)GetDlgItem(IDC_LISTDATA) ;

	// clear listbox
	num = pList->GetCount() ;
	for (i=num-1 ; i >= 0 ;i--)
	{
	   pList->DeleteString( i );
	}
	// get data, return how many lines
	this->UpdateData();
	num = Func_GetData( p_data ,this->m_bBinType ) ;
	
	if ( num > 0 )
	{
		for (i=0 ; i < num ;i++)// num lines
		{

			//hz transform
			if ( (this->m_CodeChg == TRUE) && (this->m_ClientCode!=this->m_SvrCode) )
			{
				p_tmp = NULL ;
				// Client : GB ; Server : BIG 5
				if( (this->m_ClientCode==0) && (this->m_SvrCode==1) )
				{
					Covert_HZCode(p_data[i] , &p_tmp , BIG5_2_GB) ;
				}
				// Client : BIG 5 ; Server : GB
				else if( (this->m_ClientCode==1) && (this->m_SvrCode==0) )
				{
					Covert_HZCode(p_data[i] , &p_tmp , GB_2_BIG5) ;
				}

				// add to list
				if ( p_tmp )
				{
					pList->AddString( p_tmp );
					delete[]p_tmp ;
					p_tmp = NULL ;
				}
			}
			else
			{
				// add to list
				pList->AddString( p_data[i] );
			}

			delete[]p_data[i] ;
			p_data[i] = NULL  ;
		}
	}

}

void CClientDlg::OnClear() 
{
	int rval ;

	this->UpdateData();// retrieve data
	if (MessageBox(_T("Do you want to clear all the log files really ?") , _T("Warning") , MB_YESNO)==IDYES)
	{
		rval = Func_ClearLog(this->m_bBinType ) ;
		if( rval==0 )
			TraceLog_clear() ;
	}
}


⌨️ 快捷键说明

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