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

📄 unicodestrdlg.cpp

📁 本程序主要用于Symbian系统应用程序汉化。 可以自由转化汉字字串到符合Symbian资源规则的字串。
💻 CPP
字号:
// UnicodeStrDlg.cpp : implementation file
//

#include "stdafx.h"
#include "UnicodeStr.h"
#include "UnicodeStrDlg.h"

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


/////////////////////////////////////////////////////////////////////////////
// CUnicodeStrDlg dialog

CUnicodeStrDlg::CUnicodeStrDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUnicodeStrDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUnicodeStrDlg)
	m_uniStr = _T("");
	m_strCHS = _T("");
	m_iAllLen = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CUnicodeStrDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUnicodeStrDlg)
	DDX_Control(pDX, IDC_CHECK1, m_btnNeedUnicodeCov);
	DDX_Control(pDX, IDC_EDIT_CHS_DIS, m_edChsDis);
	DDX_Control(pDX, IDC_EDIT_CHS_LEN, m_edChsLen);
	DDX_Control(pDX, IDC_EDIT_ALL_LEN, m_edAllLen);
	DDX_Control(pDX, IDC_EDIT_0F, m_ed0f);
	DDX_Control(pDX, IDC_EDIT_0E, m_ed0e);
	DDX_Control(pDX, IDC_CHECK_NEED0F, m_btnNeed0f);
	DDX_Control(pDX, IDC_CHECK_NEEDUNILEN, m_btnNeedUniLen);
	DDX_Control(pDX, IDC_CHECK_NEEDBLANK, m_btnNeedBlank);
	DDX_Control(pDX, IDC_CHECK_NEEDALLLEN, m_btnNeedAllLen);
	DDX_Control(pDX, IDC_CHECK_NEED0E, m_btnNeed0e);
	DDX_Control(pDX, IDC_EDIT_UNICODE, m_edUnicode);
	DDX_Text(pDX, IDC_EDIT1, m_uniStr);
	DDX_Text(pDX, IDC_EDIT_CHS, m_strCHS);
	DDV_MaxChars(pDX, m_strCHS, 100);
	DDX_Text(pDX, IDC_EDIT_LEN, m_iAllLen);
	DDV_MinMaxUInt(pDX, m_iAllLen, 0, 255);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUnicodeStrDlg, CDialog)
	//{{AFX_MSG_MAP(CUnicodeStrDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CHS2UNI, OnChs2uni)
	ON_BN_CLICKED(IDC_BUTTON_REF, OnButtonRef)
	ON_BN_CLICKED(IDC_CHECK_NEED0F, OnCheckNeed0f)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUnicodeStrDlg message handlers

BOOL CUnicodeStrDlg::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
	
	m_btnNeed0f.SetCheck(BST_CHECKED);
	m_btnNeedAllLen.SetCheck(BST_CHECKED);
	m_btnNeed0e.SetCheck(BST_CHECKED);
	m_btnNeedBlank.SetCheck(BST_CHECKED);
	m_btnNeedUniLen.SetCheck(BST_CHECKED);
	m_btnNeedUnicodeCov.SetCheck(BST_CHECKED);

	// TODO: Add extra initialization here
	
	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 CUnicodeStrDlg::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 CUnicodeStrDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CUnicodeStrDlg::OnOK() 
{
	return ;
}

void CUnicodeStrDlg::OnChs2uni() 
{
	// TODO: Add your control notification handler code here
	int iCHSLen = 0;
	int iAllLen = 0;
	int iBlankLen = 0;
	int i;
	CString Str0F = _T("0F");
	CString Str0E = _T("0E");
	CString StrBlank = _T("20");
	CString StrAllLen=_T("");
	CString StrChsLen=_T("");
	CString StrOutput=_T("");

	BOOL bNeed0F,bNeed0E,bNeedAllLen,bNeedChsLen,bNeedBlank,bNeedUniCov;



	CHAR buf[255];
	memset(buf,0x0000,255);
	
	m_ed0e.SetWindowText(_T(""));
	m_ed0f.SetWindowText(_T(""));
	m_edChsLen.SetWindowText(_T(""));
	m_edAllLen.SetWindowText(_T(""));
	m_edChsDis.SetWindowText(_T(""));

	
	UpdateData();
	bNeedBlank	= m_btnNeedBlank.GetCheck();
	bNeed0F		= m_btnNeed0f.GetCheck();
	bNeed0E		= m_btnNeed0e.GetCheck();
	bNeedAllLen = m_btnNeedAllLen.GetCheck();
	bNeedChsLen = m_btnNeedUniLen.GetCheck();
	bNeedUniCov = m_btnNeedUnicodeCov.GetCheck();

	iCHSLen = _tcslen(this->m_strCHS); //Get ChsLen
	iAllLen = m_iAllLen;
	
	if (!bNeedBlank || !bNeedAllLen)
		iBlankLen=0;//不需要补全或者没有指定总长度
	else 
	{
		iBlankLen=iAllLen-2*iCHSLen;
		if (iBlankLen == 1) //需要留给0x0F
		{
			MessageBox(_T("无法设置0E和空格,程序将继续"));
			bNeed0F = true;
			bNeed0E = false;
			bNeedBlank = false;
		}
		if (iBlankLen == 0) //无法设置0x0F
		{
			MessageBox(_T("无法设置0F,0E 和空格,程序无法继续"));
			return ;
		}
		if (bNeed0F)
			iBlankLen -=1;
		if (bNeed0E)
			iBlankLen -=1;

	}
	if(bNeedChsLen)
	{
		if (bNeedAllLen)
			if (bNeed0E)
				StrChsLen.Format(_T("%02X"),iAllLen-iCHSLen-2);
			else 
				StrChsLen.Format(_T("%02X"),iAllLen-iCHSLen-1);
		else 
			StrChsLen.Format(_T("%02X"),iCHSLen);
		StrOutput+=StrChsLen;
		m_edChsLen.SetWindowText(StrChsLen);
	}
	
	if (bNeedAllLen)
	{
		if (iAllLen<2*iCHSLen+1)
		{
			AfxMessageBox(_T("中文过长,不能全部装入\n或者指定了错误的最大长度"),MB_ICONSTOP);
			return ;
		}

		StrAllLen.Format(_T("%02X"),iAllLen);
		StrOutput+=StrAllLen;
		m_edAllLen.SetWindowText(StrAllLen);
	}
	if (m_btnNeed0f.GetCheck())
	{
		StrOutput+=Str0F;
		m_ed0f.SetWindowText(Str0F);
	}
	
	_tcscpy((TCHAR *)buf,this->m_strCHS);
	
	CString ChsStr	= _T("");
	CString tmpStr	= _T("");

	if (bNeedUniCov)
	{
		for(i = 0 ;i<iCHSLen;i++)
		{
			tmpStr.Format(_T("%02X"),buf[i*2+1]&0xFF);
			ChsStr +=tmpStr;
			tmpStr.Format(_T("%02X"),buf[i*2]&0xFF);
			ChsStr +=tmpStr;
		}
	}
	else
	{
		for(i = 0 ;i<iCHSLen*2;i++)
		{
			tmpStr.Format(_T("%02X"),buf[i]&0xFF);
			ChsStr +=tmpStr;
		}
	}
	StrOutput+=ChsStr;
	m_edChsDis.SetWindowText(ChsStr);
	if (bNeed0E)
	{
/*		if (iBlankLen<1)
		{
			MessageBox(_T("无法自动补足空格,请尝试在输入的中文中加入空格"));
			return;
		}
*/		StrOutput+=Str0E;
		m_ed0e.SetWindowText(Str0E);
	}

	if (bNeedBlank&&bNeedAllLen)
	{
		for (i=0;i<iAllLen-iCHSLen*2-2;i++)
		{
			StrOutput+=StrBlank;
		}
	}
	this->m_edUnicode.SetWindowText(StrOutput);

	return ;
	
}

void CUnicodeStrDlg::OnButtonRef() 
{
	// TODO: Add your control notification handler code here
	if (IDOK == AfxMessageBox(_T("本程序主要参考了WDA网友的经验总结,这里表示感谢!\n想观看原始文档吗?"),MB_OKCANCEL|MB_ICONQUESTION))
	{
		ShellExecute(this->m_hWnd,_T("open"),_T("http://211.157.105.29/viewthread.php?tid=171897"),_T(""),_T(""), SW_SHOW );
	}
		
}

void CUnicodeStrDlg::OnCheckNeed0f() 
{
	// TODO: Add your control notification handler code here
	m_btnNeed0f.SetCheck(BST_CHECKED);
	if (IDOK == AfxMessageBox(_T("一般来说,这个选项最好选中\n你取消吗?"),MB_OKCANCEL|MB_ICONQUESTION))
	{
		m_btnNeed0f.SetCheck(BST_UNCHECKED);
	}
	return;
}

⌨️ 快捷键说明

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