LanguageDlg.cpp
资源名称:Language.rar [点击查看]
上传用户:yangacai01
上传日期:2020-10-06
资源大小:1730k
文件大小:5k
源码类别:
多国语言处理
开发平台:
Visual C++
- // LanguageDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Language.h"
- #include "LanguageDlg.h"
- #include "TranslateLanguage.h"
- #include <io.h>
- #include <string.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CLanguageDlg dialog
- CLanguageDlg::CLanguageDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CLanguageDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CLanguageDlg)
- // 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 CLanguageDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CLanguageDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CLanguageDlg, CDialog)
- //{{AFX_MSG_MAP(CLanguageDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_Btn_big5_to_gb2312, OnBtnbig5togb2312)
- ON_BN_CLICKED(IDC_Btn_gb2312_to_big5, OnBtngb2312tobig5)
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CLanguageDlg message handlers
- BOOL CLanguageDlg::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
- language_intial();
- 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 CLanguageDlg::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 CLanguageDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CLanguageDlg::OnBtnbig5togb2312()
- {
- CString big;
- GetDlgItemText(IDC_Edt_big5,big);
- char *p=big.GetBuffer(big.GetLength()+1);
- language_big5_to_gbk2312(p);
- big.ReleaseBuffer();
- SetDlgItemText(IDC_Edt_gb2312,big);
- }
- void CLanguageDlg::OnBtngb2312tobig5()
- {
- CString big;
- GetDlgItemText(IDC_Edt_gb2312,big);
- char *p=big.GetBuffer(big.GetLength()+1);
- language_gbk2312_to_big5(p);
- big.ReleaseBuffer();
- SetDlgItemText(IDC_Edt_big5,big);
- }
- void CLanguageDlg::OnButton1()
- {
- CFileDialog dlg(1,"*.*",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"所有文件|*.*||");
- dlg.m_ofn.lStructSize=88;
- if(dlg.DoModal()==IDOK)
- {
- SetDlgItemText(IDC_EDIT1,dlg.GetPathName());
- }
- }
- void CLanguageDlg::OnButton3()
- {
- CFileDialog dlg(0,"*.*",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"所有文件|*.*||");
- dlg.m_ofn.lStructSize=88;
- if(dlg.DoModal()==IDOK)
- {
- SetDlgItemText(IDC_EDIT2,dlg.GetPathName());
- }
- }
- typedef unsigned char byte;
- typedef unsigned int dword;
- byte* readfile(const char *filename,dword &flen,dword buffer=10 )
- {
- FILE *fp=fopen(filename,"rb");
- if(!fp)
- {
- printf("can't open file %s for input.n",filename);
- return 0;
- }
- dword k=_filelength(fp->_file);
- byte *aa=new byte [k+buffer+4];
- if(!aa)
- {
- printf("not enough memory when read file %s.n",filename);
- return 0;
- }
- fread(aa,1,k,fp);
- for(dword i=k;i<k+buffer+4;i++) aa[i]=0;
- flen=k;
- fclose(fp);
- return aa;
- }
- void CLanguageDlg::OnButton2()
- {
- CString fi,fo;
- GetDlgItemText(IDC_EDIT1,fi);
- GetDlgItemText(IDC_EDIT2,fo);
- unsigned int filen;
- byte *p=readfile(fi.GetBuffer(300),filen);
- language_big5_to_gbk2312((char *)p);
- FILE *fp=fopen(fo.GetBuffer(300),"wb");
- fwrite(p,1,filen,fp);
- fclose(fp);
- delete []p;
- fi.ReleaseBuffer();
- fo.ReleaseBuffer();
- MessageBox("ok.");
- }
- void CLanguageDlg::OnButton4()
- {
- CString fi,fo;
- GetDlgItemText(IDC_EDIT2,fi);
- GetDlgItemText(IDC_EDIT1,fo);
- unsigned int filen;
- byte *p=readfile(fi.GetBuffer(300),filen);
- language_gbk2312_to_big5((char *)p);
- FILE *fp=fopen(fo.GetBuffer(300),"wb");
- fwrite(p,1,filen,fp);
- fclose(fp);
- delete []p;
- fi.ReleaseBuffer();
- fo.ReleaseBuffer();
- MessageBox("ok.");
- }