ADDORDEL.CPP
上传用户:zhang8947
上传日期:2007-01-08
资源大小:1910k
文件大小:4k
- // addordel.cpp : implementation file
- //
- #include "stdafx.h"
- #include <afxdlgs.h>
- #include "resource.h"
- #include "addordel.h"
- #include "iniinput.h"
- //#include "inputlib.h"
- extern CInputInit OInputInit ; //输入环境初始化对象
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAddOrDelInputMethod dialog
- CAddOrDelInputMethod::CAddOrDelInputMethod(void)
- : CPropertyPage(CAddOrDelInputMethod::IDD)
- {
- //{{AFX_DATA_INIT(CAddOrDelInputMethod)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CAddOrDelInputMethod::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAddOrDelInputMethod)
- DDX_Control(pDX, IDC_LIST1, m_AddedInputMethods);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAddOrDelInputMethod, CPropertyPage )
- //{{AFX_MSG_MAP(CAddOrDelInputMethod)
- ON_BN_CLICKED(ID_INSTALL, OnInstall)
- ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
- ON_BN_CLICKED(ID_DELETE, OnDelete)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAddOrDelInputMethod message handlers
- void CAddOrDelInputMethod::OnInstall()
- {
- CFileDialog fileDialog( TRUE , "txt" , "*.txt" ,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT ,
- "UCDOS输入法(*.txt)|*.txt|梦笔生花输入法(*.iml)|*.iml| All Files (*.*) | *.* ||"
- ) ;
- if( fileDialog.DoModal() == IDOK )
- {
- //得到文件后缀
- CString fileExt =fileDialog.GetFileExt() ;
- if( fileExt != "TXT" && fileExt != "IML" )
- AfxMessageBox( "文件类型不对,必须是.txt或.iml文件!" ,
- MB_OK|MB_ICONINFORMATION ) ;
- else
- {
- //增加一种输入法
- CString path =fileDialog.GetPathName() ;
- //判断文件类型
- if( fileExt == "TXT" ) //是UCDOS文本文件
- {
- if( !TranslateUcdos( path ) ) //转换失败
- return ;
-
- ::MessageBox( this->m_hWnd , "输入法文件转换成功" ,
- "转换输入法" ,
- MB_OK|MB_ICONEXCLAMATION ) ;
- //重新组织文件名,组织库文件名
- path =path.Left( path.GetLength()-3 ) ; //去掉TXT后缀
- path +="iml" ; //新后缀
- }
-
- //关闭以前的输入法
- UnloadInputLib() ;
- //安装该输入法
- if( !LoadInputLib( path ) )
- return ;
-
- //得到输入法名
- char sName[20] ;
- GetInputMethodName( sName , 20 ) ;
- char sBuff[100] ;
- wsprintf( sBuff , "%s输入法安装成功!" , sName ) ;
- ::MessageBox( this->m_hWnd , sBuff , "安装输入法" ,
- MB_OK|MB_ICONEXCLAMATION ) ;
-
- //将输入法加入列表框
- m_AddedInputMethods.InsertString( 0 , sName ) ;
- //将输入法加入INI文件和菜单
- OInputInit.AddInputMethod( sName , path ) ;
- }
- }
- }
- void CAddOrDelInputMethod::OnDblclkList1()
- {
- DeleteInputMethod() ;
- }
- void CAddOrDelInputMethod::OnDelete()
- {
- DeleteInputMethod() ;
- }
- void CAddOrDelInputMethod::DeleteInputMethod( void )
- {
- int nSelectItem =m_AddedInputMethods.GetCurSel() ;
- if( nSelectItem == LB_ERR ) //没有选择
- return ;
-
- CDialog dialog( IDD_DIALOG4 ) ;
- if( dialog.DoModal() == IDOK )
- {
- //将其从列表框中删除
- m_AddedInputMethods.DeleteString( nSelectItem ) ;
- //将其从INI文件和菜单中删除
- OInputInit.DeleteInputMethod( nSelectItem ) ;
- }
- }
- //对输入法列表框进行初始化
- BOOL CAddOrDelInputMethod::OnInitDialog()
- {
- CPropertyPage ::OnInitDialog();
- //得到输入法数
- int nMethodNum =OInputInit.GetInputMethodNum() ;
- char sInputName[100] ; //输入法名称
- char sInputFileName[100] ; //输入法文件名
-
- for( int i=1 ; i<nMethodNum ; i++ )
- {
- //得到输入法的名字与文件名
- OInputInit.GetInputMethod( i , sInputName , 100 ,
- sInputFileName , 100 ) ;
- //将输入法名加入列表框
- m_AddedInputMethods.InsertString( 0 , sInputName ) ;
- }
-
- return TRUE ;
- }