MainFrm.cpp
上传用户:hddq88
上传日期:2010-01-15
资源大小:910k
文件大小:6k
源码类别:

多国语言处理

开发平台:

C/C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "RMM.h"
  5. #include "sen.h"
  6. #include "RMMAPI.h"
  7. #include "word.h"
  8. #include "MainFrm.h"
  9. #include "UserDlg.h"
  10. #include <string.h>
  11. #include <map>
  12. using namespace std;
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMainFrame
  20. CString strInp;
  21. FILE* fpInp;
  22. CString result;
  23. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  24. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  25. //{{AFX_MSG_MAP(CMainFrame)
  26. ON_WM_CREATE()
  27. ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  28. ON_COMMAND(ID_DO, OnDo)
  29. ON_BN_CLICKED(IDC_OPEN, OnOpen)
  30. ON_BN_CLICKED(IDC_SAVE, OnSave)
  31. ON_BN_CLICKED(IDC_MAKE, OnMake)
  32. ON_COMMAND(ID_COUNT, OnCount)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. static UINT indicators[] =
  36. {
  37. ID_SEPARATOR,           // status line indicator
  38. ID_INDICATOR_CAPS,
  39. ID_INDICATOR_NUM,
  40. ID_INDICATOR_SCRL,
  41. };
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CMainFrame construction/destruction
  44. CMainFrame::CMainFrame()
  45. {
  46. // TODO: add member initialization code here
  47. }
  48. CMainFrame::~CMainFrame()
  49. {
  50. }
  51. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  52. {
  53. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  54. return -1;
  55. if (!m_wndStatusBar.Create(this) ||
  56. !m_wndStatusBar.SetIndicators(indicators,
  57.   sizeof(indicators)/sizeof(UINT)))
  58. {
  59. TRACE0("Failed to create status barn");
  60. return -1;      // fail to create
  61. }
  62. // TODO: Delete these three lines if you don't want the toolbar to
  63. //  be dockable
  64. //m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  65. //EnableDocking(CBRS_ALIGN_ANY);
  66. //DockControlBar(&m_wndToolBar);
  67. return 0;
  68. }
  69. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
  70. CCreateContext* pContext)
  71. {
  72.     BOOL rtn=m_wndSplitter.CreateStatic(this,2,1);
  73. m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(Csen), CSize(0, 0), pContext);
  74. m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(Cword), CSize(0, 0), pContext);
  75. m_wndSplitter.SetRowInfo(0,200,0); 
  76. m_DialogBar.Create(this,IDD_DIALOGBAR,CBRS_TOP,IDD_DIALOGBAR);
  77. return rtn;
  78. }
  79. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  80. {
  81. if( !CFrameWnd::PreCreateWindow(cs) )
  82. return FALSE;
  83. // TODO: Modify the Window class or styles here by modifying
  84. //  the CREATESTRUCT cs
  85.     
  86. return TRUE;
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CMainFrame diagnostics
  90. #ifdef _DEBUG
  91. void CMainFrame::AssertValid() const
  92. {
  93. CFrameWnd::AssertValid();
  94. }
  95. void CMainFrame::Dump(CDumpContext& dc) const
  96. {
  97. CFrameWnd::Dump(dc);
  98. }
  99. #endif //_DEBUG
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CMainFrame message handlers
  102. void CMainFrame::OnFileOpen() 
  103. {
  104.      
  105. CString strOut;
  106. Csen* psen=(Csen*)m_wndSplitter.GetPane(0,0);
  107. Cword* pword=(Cword*)m_wndSplitter.GetPane(1,0);
  108. CFileDialog FileDialog(true);
  109. if ( FileDialog.DoModal() == IDOK ){
  110. strInp=FileDialog.GetPathName( );
  111. FILE* fpInp;
  112. fpInp=fopen(strInp.GetBuffer(1024),"rb");
  113. if ( fpInp == NULL ){
  114. AfxMessageBox("Error open file!n");
  115. }
  116.     
  117. char szLine[1024];
  118. while( fgets(szLine,1024,fpInp) != NULL ){
  119.      strOut+=szLine;
  120.     }
  121. fclose(fpInp);
  122. psen->SetWindowText(strOut);
  123. }
  124. RMMInit("segment.idx","segment.dat");
  125. }
  126. void CMainFrame::OnDo() {
  127. CString TszSeged;
  128. char szSegmented[1024];
  129. Csen* psen=(Csen*)m_wndSplitter.GetPane(0,0);
  130. Cword* pword=(Cword*)m_wndSplitter.GetPane(1,0);
  131. int len=psen->GetWindowTextLength();
  132. CString szSeged;
  133. int nPos1=1;
  134. psen->GetWindowText(szSeged.GetBuffer(len+1),len+1);
  135. fpInp=fopen(strInp.GetBuffer(1024),"rb");
  136. if ( fpInp == NULL ){
  137. AfxMessageBox("Error open file!n");
  138. }
  139.     
  140. char szLine[1024];
  141. while(!feof(fpInp)){
  142.     fscanf(fpInp,"%s",szLine);
  143.     RMMMain(szLine,szSegmented);
  144.     result+=szSegmented;
  145. result+=" ";
  146. }
  147. fclose(fpInp);
  148.     pword->SetWindowText(result);
  149. }
  150. void CMainFrame::OnOpen() 
  151. {
  152. // TODO: Add your control notification handler code here
  153.     CString strOut;
  154. Csen* psen=(Csen*)m_wndSplitter.GetPane(0,0);
  155. CFileDialog FileDialog(true);
  156. if ( FileDialog.DoModal() == IDOK ){
  157. strInp=FileDialog.GetPathName( );
  158. fpInp=fopen(strInp.GetBuffer(1024),"rb");
  159. if ( fpInp == NULL ){
  160. AfxMessageBox("Error open file!n");
  161. }
  162.     
  163. char szLine[1024];
  164. while( fgets(szLine,1024,fpInp) != NULL ){
  165.      strOut+=szLine;
  166.     }
  167. fclose(fpInp);
  168. psen->SetWindowText(strOut);
  169. }
  170. RMMInit("segment.idx","segment.dat");
  171. }
  172. void CMainFrame::OnSave() 
  173. {
  174. // TODO: Add your control notification handler code here
  175. char szDir[1024];
  176.     ::GetCurrentDirectory(1024,szDir);
  177. CFileDialog FileDialog(false);
  178. if(FileDialog.DoModal()==IDOK)
  179. {
  180. CString strPath=FileDialog.GetPathName();
  181. FILE *fpOut;
  182. fpOut=fopen(strPath.GetBuffer(1024),"wb");
  183. if ( fpOut == NULL ){
  184. AfxMessageBox("Error open file!n");
  185. return;
  186. }
  187. Csen* psen=(Csen*)m_wndSplitter.GetPane(0,0);
  188. int len=psen->GetWindowTextLength();
  189. CString szSeged;
  190. psen->GetWindowText(szSeged.GetBuffer(len+1),len+1);
  191.     
  192. fprintf(fpOut,"%sn",szSeged.GetBuffer(len+1));
  193. fclose(fpOut);
  194. }
  195. }
  196. void CMainFrame::OnMake() 
  197. {
  198. // TODO: Add your control notification handler code here
  199.     CString TszSeged;
  200. char szSegmented[1024];
  201. Csen* psen=(Csen*)m_wndSplitter.GetPane(0,0);
  202. Cword* pword=(Cword*)m_wndSplitter.GetPane(1,0);
  203. int len=psen->GetWindowTextLength();
  204. CString szSeged;
  205. int nPos1=1;
  206. psen->GetWindowText(szSeged.GetBuffer(len+1),len+1);
  207. fpInp=fopen(strInp.GetBuffer(1024),"rb");
  208. if ( fpInp == NULL ){
  209. AfxMessageBox("Error open file!n");
  210. }
  211.     
  212. char szLine[1024];
  213. while(!feof(fpInp)){
  214.     fscanf(fpInp,"%s",szLine);
  215.     RMMMain(szLine,szSegmented);
  216.     result+=szSegmented;
  217. result+=" ";
  218. }
  219. fclose(fpInp);
  220.     pword->SetWindowText(result);
  221.     
  222. }
  223. void CMainFrame::OnCount() 
  224. {
  225. // TODO: Add your command handler code here
  226.              CUserDlg obUserDlg;
  227.  if ( obUserDlg.DoModal() == IDOK ){}
  228. }