LanguageDlg.cpp
上传用户:yangacai01
上传日期:2020-10-06
资源大小:1730k
文件大小:5k
源码类别:

多国语言处理

开发平台:

Visual C++

  1. // LanguageDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Language.h"
  5. #include "LanguageDlg.h"
  6. #include "TranslateLanguage.h"
  7. #include <io.h>
  8. #include <string.h>
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CLanguageDlg dialog
  16. CLanguageDlg::CLanguageDlg(CWnd* pParent /*=NULL*/)
  17. : CDialog(CLanguageDlg::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(CLanguageDlg)
  20. // NOTE: the ClassWizard will add member initialization here
  21. //}}AFX_DATA_INIT
  22. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  23. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  24. }
  25. void CLanguageDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CLanguageDlg)
  29. // NOTE: the ClassWizard will add DDX and DDV calls here
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CLanguageDlg, CDialog)
  33. //{{AFX_MSG_MAP(CLanguageDlg)
  34. ON_WM_PAINT()
  35. ON_WM_QUERYDRAGICON()
  36. ON_BN_CLICKED(IDC_Btn_big5_to_gb2312, OnBtnbig5togb2312)
  37. ON_BN_CLICKED(IDC_Btn_gb2312_to_big5, OnBtngb2312tobig5)
  38. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  39. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  40. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  41. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CLanguageDlg message handlers
  46. BOOL CLanguageDlg::OnInitDialog()
  47. {
  48. CDialog::OnInitDialog();
  49. // Set the icon for this dialog.  The framework does this automatically
  50. //  when the application's main window is not a dialog
  51. SetIcon(m_hIcon, TRUE); // Set big icon
  52. SetIcon(m_hIcon, FALSE); // Set small icon
  53. // TODO: Add extra initialization here
  54. language_intial();
  55. return TRUE;  // return TRUE  unless you set the focus to a control
  56. }
  57. // If you add a minimize button to your dialog, you will need the code below
  58. //  to draw the icon.  For MFC applications using the document/view model,
  59. //  this is automatically done for you by the framework.
  60. void CLanguageDlg::OnPaint() 
  61. {
  62. if (IsIconic())
  63. {
  64. CPaintDC dc(this); // device context for painting
  65. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  66. // Center icon in client rectangle
  67. int cxIcon = GetSystemMetrics(SM_CXICON);
  68. int cyIcon = GetSystemMetrics(SM_CYICON);
  69. CRect rect;
  70. GetClientRect(&rect);
  71. int x = (rect.Width() - cxIcon + 1) / 2;
  72. int y = (rect.Height() - cyIcon + 1) / 2;
  73. // Draw the icon
  74. dc.DrawIcon(x, y, m_hIcon);
  75. }
  76. else
  77. {
  78. CDialog::OnPaint();
  79. }
  80. }
  81. // The system calls this to obtain the cursor to display while the user drags
  82. //  the minimized window.
  83. HCURSOR CLanguageDlg::OnQueryDragIcon()
  84. {
  85. return (HCURSOR) m_hIcon;
  86. }
  87. void CLanguageDlg::OnBtnbig5togb2312() 
  88. {
  89. CString big;
  90. GetDlgItemText(IDC_Edt_big5,big);
  91. char *p=big.GetBuffer(big.GetLength()+1);
  92. language_big5_to_gbk2312(p);
  93. big.ReleaseBuffer();
  94. SetDlgItemText(IDC_Edt_gb2312,big);
  95. }
  96. void CLanguageDlg::OnBtngb2312tobig5() 
  97. {
  98. CString big;
  99. GetDlgItemText(IDC_Edt_gb2312,big);
  100. char *p=big.GetBuffer(big.GetLength()+1);
  101. language_gbk2312_to_big5(p);
  102. big.ReleaseBuffer();
  103. SetDlgItemText(IDC_Edt_big5,big);
  104. }
  105. void CLanguageDlg::OnButton1() 
  106. {
  107. CFileDialog dlg(1,"*.*",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"所有文件|*.*||");
  108. dlg.m_ofn.lStructSize=88;
  109. if(dlg.DoModal()==IDOK)
  110. {
  111. SetDlgItemText(IDC_EDIT1,dlg.GetPathName());
  112. }
  113. }
  114. void CLanguageDlg::OnButton3() 
  115. {
  116. CFileDialog dlg(0,"*.*",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"所有文件|*.*||");
  117. dlg.m_ofn.lStructSize=88;
  118. if(dlg.DoModal()==IDOK)
  119. {
  120. SetDlgItemText(IDC_EDIT2,dlg.GetPathName());
  121. }
  122. }
  123. typedef unsigned char byte;
  124. typedef unsigned int dword;
  125. byte* readfile(const char *filename,dword &flen,dword buffer=10 )
  126. {
  127. FILE *fp=fopen(filename,"rb");
  128. if(!fp)
  129. {
  130. printf("can't open file %s for input.n",filename);
  131. return 0;
  132. }
  133. dword k=_filelength(fp->_file);
  134. byte *aa=new byte [k+buffer+4];
  135. if(!aa)
  136. {
  137. printf("not enough memory when read file %s.n",filename);
  138. return 0;
  139. }
  140. fread(aa,1,k,fp);
  141. for(dword i=k;i<k+buffer+4;i++) aa[i]=0;
  142. flen=k;
  143. fclose(fp);
  144. return aa;
  145. }
  146. void CLanguageDlg::OnButton2() 
  147. {
  148. CString fi,fo;
  149. GetDlgItemText(IDC_EDIT1,fi);
  150. GetDlgItemText(IDC_EDIT2,fo);
  151. unsigned int filen;
  152. byte *p=readfile(fi.GetBuffer(300),filen);
  153. language_big5_to_gbk2312((char *)p);
  154. FILE *fp=fopen(fo.GetBuffer(300),"wb");
  155. fwrite(p,1,filen,fp);
  156. fclose(fp);
  157. delete []p;
  158. fi.ReleaseBuffer();
  159. fo.ReleaseBuffer();
  160. MessageBox("ok.");
  161. }
  162. void CLanguageDlg::OnButton4() 
  163. {
  164. CString fi,fo;
  165. GetDlgItemText(IDC_EDIT2,fi);
  166. GetDlgItemText(IDC_EDIT1,fo);
  167. unsigned int filen;
  168. byte *p=readfile(fi.GetBuffer(300),filen);
  169. language_gbk2312_to_big5((char *)p);
  170. FILE *fp=fopen(fo.GetBuffer(300),"wb");
  171. fwrite(p,1,filen,fp);
  172. fclose(fp);
  173. delete []p;
  174. fi.ReleaseBuffer();
  175. fo.ReleaseBuffer();
  176. MessageBox("ok.");
  177. }