?? unicodetransdlg.cpp
字號:
// UniCodeTransDlg.cpp : implementation file
//
#include "stdafx.h"
#include "UniCodeTrans.h"
#include "UniCodeTransDlg.h"
#include "CSpreadSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CUniCodeTransDlg dialog
CUniCodeTransDlg::CUniCodeTransDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUniCodeTransDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUniCodeTransDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CUniCodeTransDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUniCodeTransDlg)
DDX_Control(pDX, IDC_LISTACCESS, m_AccessList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUniCodeTransDlg, CDialog)
//{{AFX_MSG_MAP(CUniCodeTransDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON2, OnLoad)
ON_BN_CLICKED(IDC_BUTTON1, OnWrite)
ON_BN_CLICKED(IDC_CREATEFILE, OnCreatefile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUniCodeTransDlg message handlers
BOOL CUniCodeTransDlg::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
memset(StrIDBuf, 0 , sizeof(StrIDBuf));
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CUniCodeTransDlg::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 CUniCodeTransDlg::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 CUniCodeTransDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CUniCodeTransDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CUniCodeTransDlg::OnLoad()
{
CFileStatus status;
CString DspBuf;
CFileDialog mFileDlg(TRUE, NULL,NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, "All Files (*.xls)|*.xls| |", AfxGetMainWnd());
if( mFileDlg.DoModal ()==IDOK )
{
pathName = mFileDlg.GetPathName();
fileName = mFileDlg.GetFileTitle ();
fileExt = mFileDlg.GetFileExt();
SetWindowText(fileName);
}
if(fileExt.CompareNoCase("xls") != 0)
{
AfxMessageBox("文件格式不匹配,請重新選擇!");
pathName.Empty();
GetDlgItem(IDOK)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
return;
}
DspBuf = "文件名: " ;
DspBuf += 9;
DspBuf += pathName;
m_AccessList.AddString(DspBuf);
DspBuf.Empty();
GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
resIDFileOK = false;
OnRead();
}
void CUniCodeTransDlg::OnWrite()
{
if (resIDFileOK == false)
{
if (WriteResId() == true)
{
resIDFileOK = true;
WriteCnResStr();
}
}
else
WriteCnResStr();
return;
}
void CUniCodeTransDlg::OnRead()
{
int nIDCount = 0;
int i;
CString BufForView;
CString DspBuf;
CSpreadSheet SS(pathName, "TestSheet");
CStringArray Rows, Column;
ResID.Empty();
ResEnStr.Empty();
DspBuf = "正在讀取數據......" ;
m_AccessList.AddString(DspBuf);
//清空列表框
//m_AccessList.ResetContent();
for (i = 2; i <= SS.GetTotalRows(); i++)
{
// 讀取一行
SS.ReadRow(Rows, i);
for (int j = 0; j <= Rows.GetSize(); j++)
{
if(j == 0)/*id*/
{
BufForView.Empty();
BufForView = Rows.GetAt(j);
BufForView += '\n';
ResID += Rows.GetAt(j);
ResID += ",";
strcpy(StrIDBuf[nIDCount++], Rows.GetAt(j));
DspBuf = StrIDBuf[nIDCount-1];
m_AccessList.AddString(DspBuf);
//m_AccessList.AddString(BufForView);
}
else if(j == 1)/*簡體中文*/
{
ResCnStr += Rows.GetAt(j);
ResCnStr += (char)14;
ResCnStr += (char)15;
}
else if(j == 2) /*英文*/
{
ResEnStr += Rows.GetAt(j);
ResEnStr += (char)15;
}
else
{
}
}
}
/*修改字符串*/
nLengthNeedTranStr = ResCnStr.GetLength();
for(i = 0; i < nLengthNeedTranStr; i++)
{
char temp = ResCnStr.GetAt(i);
if(temp == 32)/*去掉中文資源中的空格*/
{
ResCnStr.Delete(i);
i--;
nLengthNeedTranStr--;
continue;
}
if(temp > 0 && temp < 128 && temp != 14 && temp != 15)
{
ResCnStr.Insert(i+1, char(0));
i++;
nLengthNeedTranStr++;
}
}
int length = ResEnStr.GetLength();
/*去掉英文資源中的空格*/
for(i = 0 ;i <length; i++)
{
char temp = ResCnStr.GetAt(i);
if(temp == 32)
{
ResEnStr.Delete(i);
i--;
continue;
}
}
DspBuf = "請按“生成”軟鍵,生成resID.h和resStrTab.h。" ;
m_AccessList.AddString(DspBuf);
i = m_AccessList.GetCount();
if (i > 0)
m_AccessList.SetCurSel(i-1);
}
void CUniCodeTransDlg::OnCreatefile()
{
CSpreadSheet SS("c:\\temp\\resource.xls", "TestSheet");
CStringArray sampleArray, testRow;
SS.BeginTransaction();
// 加入標題
sampleArray.RemoveAll();
sampleArray.Add("資源ID");
sampleArray.Add("簡體中文");
sampleArray.Add("英文");
SS.AddHeaders(sampleArray);
SS.Commit();
AfxMessageBox("文件創建成功!");
}
bool CUniCodeTransDlg::WriteResId()
{
int j;/*計算*/
int length = 0;
int count = 1;
CFileException e;
CString toWrite;
CString strTemp;
COleDateTime dateTest = COleDateTime::GetCurrentTime();
CString dateStr;
CString DspBuf;
char* pFileName = "\\numan\\apps\\brew\\application\\inc\\resID.h";
/*打開文件,如果不存在就創建該文件*/
if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeText) )
{
/* AfxMessageBox("resID.h文件屬性只讀,請先checkout");*/
DspBuf = "resID.h文件屬性只讀,請先checkout" ;
m_AccessList.AddString(DspBuf);
j = m_AccessList.GetCount();
if (j > 0)
m_AccessList.SetCurSel(j-1);
return false;
}
j = 0;
DspBuf = "正在寫入數據......";
m_AccessList.AddString(DspBuf);
/*寫文件頭*/
toWrite += "#ifndef RES_ID_H";
toWrite += '\n';
toWrite += "#define RES_ID_H";
toWrite += '\n';
toWrite += "/*-------------------------------------------*/";
toWrite += '\n';
toWrite += "/* this is func of make the res id file */";
toWrite += '\n';
toWrite += "/* author: jian ai, jf jiang Huntel tech. */";
toWrite += '\n';
dateStr.Format("/* %s */", dateTest.Format("%A, %B %d, %Y, %H:%M:%S"));
toWrite += dateStr;
toWrite += '\n';
toWrite += "/* filename: RESID.H */";
toWrite += '\n';
toWrite += "/*-------------------------------------------*/";
toWrite += '\n';
toWrite += '\n';
toWrite += '\n';
toWrite += '\n';
toWrite += "typedef enum";
toWrite += "{";
toWrite += '\n';
toWrite += "IDS_NULL";
toWrite += '=';
toWrite += '0';
toWrite += ',';
toWrite += "/* 空 */";
toWrite += '\n';
f.Write(toWrite,toWrite.GetLength());
toWrite.Empty();
/*從ResID中讀取內容并且進行轉換*/
length = ResID.GetLength();
for(int i = 0; i< length; i++)
{
if(ResID.GetAt(i) != ',')
{
toWrite += ResID.GetAt(i);
}else
{
j++;
toWrite += '=';
strTemp.Format("%d", j);
toWrite += strTemp;
strTemp.Empty();
toWrite += ",";
toWrite += 9;
f.Write(toWrite, toWrite.GetLength());/*寫文件*/
m_AccessList.AddString(toWrite);
WriteStringNameWithCount(count);
WriteStringEnglishNameWithCount(count);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -