handle.c
资源名称:大熊猫输入法原码.zip [点击查看]
上传用户:szljw888
上传日期:2010-04-11
资源大小:124k
文件大小:43k
源码类别:
输入法编程
开发平台:
C/C++
- /* 大熊猫输入法(Free Chinese Input) 由YJMSIR(yjmsir@163.com)编写
- * 协议: GPL
- * freeinput( A Chinese Input Method) by YJMSIR(yjmsir@163.com)
- * Licence: GPL
- */
- #include "freepy.h"
- /**********************************************************************/
- /* */
- /* IMEKeyupHandler() */
- /* */
- /* A function which handles WM_IMEKEYUP */
- /* */
- /**********************************************************************/
- BOOL IMEKeyupHandler(
- HIMC hIMC,
- WPARAM wParam,
- LPARAM lParam,
- LPBYTE lpbKeyState)
- {
- return FALSE;
- }
- /**********************************************************************/
- /* */
- /* IMEKeydownHandler() */
- /* */
- /* A function which handles WM_IMEKEYDOWN */
- /* */
- /**********************************************************************/
- BOOL IMEKeydownHandler(
- HIMC hIMC,
- WPARAM wParam,
- LPARAM lParam,
- LPBYTE lpbKeyState)
- {
- if(HotKeyPressed){
- HotKeyPressed=0;
- return TRUE;
- }
- if(!HaveInitDictionary) return TRUE;
- if(wConversionMode == CONVERSION_MODE_WUBI||
- wConversionMode == CONVERSION_MODE_HISTORYREUSE)
- YJMIMEKeydownHandlerWubi( hIMC, wParam, lParam, lpbKeyState );
- else if(wConversionMode == CONVERSION_MODE_WUBIATTACHLIB)
- YJMIMEKeydownHandlerWbAtt( hIMC, wParam, lParam, lpbKeyState );
- else if(wConversionMode == CONVERSION_MODE_ATTACHLIB||
- wConversionMode == CONVERSION_MODE_TEMPATTACHLIB)
- YJMIMEKeydownHandlerAttachLib( hIMC, wParam, lParam, lpbKeyState );
- else
- YJMIMEKeydownHandler( hIMC, wParam, lParam, lpbKeyState );
- return TRUE;
- }
- BOOL YJMIMEKeydownHandlerWbAtt(
- HIMC hIMC,
- WPARAM wParam,
- LPARAM lParam,
- LPBYTE lpbKeyState)
- {
- WORD wVKey;
- if( wVKey=(wParam & 0x00FF)){
- if( !KeydownHandlerWbAtt( hIMC, wVKey, lParam, lpbKeyState ) ) {
- #ifdef _UNICODE
- CharHandlerWbAtt( hIMC, HIWORD(wParam), lParam );
- #else
- CharHandlerWbAtt( hIMC,(WORD)((BYTE)HIBYTE(wParam)),lParam );
- #endif
- }
- }
- return TRUE;
- }
- BOOL YJMIMEKeydownHandlerAttachLib(
- HIMC hIMC,
- WPARAM wParam,
- LPARAM lParam,
- LPBYTE lpbKeyState)
- {
- WORD wVKey;
- if( wVKey=(wParam & 0x00FF)){
- if( !KeydownHandlerAttachLib( hIMC, wVKey, lParam, lpbKeyState ) ) {
- #ifdef _UNICODE
- CharHandlerAttachLib( hIMC, HIWORD(wParam), lParam );
- #else
- CharHandlerAttachLib( hIMC,(WORD)((BYTE)HIBYTE(wParam)),lParam );
- #endif
- }
- }
- return TRUE;
- }
- BOOL YJMIMEKeydownHandlerWubi(
- HIMC hIMC,
- WPARAM wParam,
- LPARAM lParam,
- LPBYTE lpbKeyState)
- {
- WORD wVKey;
- if( wVKey=(wParam & 0x00FF)){
- if( !KeydownHandlerWubi( hIMC, wVKey, lParam, lpbKeyState ) ) {
- #ifdef _UNICODE
- CharHandlerWubi( hIMC, HIWORD(wParam), lParam );
- #else
- CharHandlerWubi( hIMC,(WORD)((BYTE)HIBYTE(wParam)),lParam );
- #endif
- }
- }
- return TRUE;
- }
- BOOL YJMIMEKeydownHandler(
- HIMC hIMC,
- WPARAM wParam,
- LPARAM lParam,
- LPBYTE lpbKeyState)
- {
- WORD wVKey;
- if( wVKey=(wParam & 0x00FF)){
- if( !KeydownHandler( hIMC, wVKey, lParam, lpbKeyState ) ) {
- #ifdef _UNICODE
- CharHandler( hIMC, HIWORD(wParam), lParam );
- #else
- CharHandler( hIMC,(WORD)((BYTE)HIBYTE(wParam)),lParam );
- #endif
- }
- }
- return TRUE;
- }
- /**********************************************************************/
- /* */
- /* KeydownHandler() */
- /* */
- /* WM_KEYDOWN handler for dictionary routine */
- /* */
- /* wParam */
- /* virtual key */
- /* */
- /* lParam */
- /* differ depending on wParam */
- /* */
- /**********************************************************************/
- BOOL KeydownHandlerAttachLib(
- HIMC hIMC,
- WORD wParam,
- LONG lParam,
- LPBYTE lpbKeyState)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- GENEMSG GnMsg;
- SHORT *lpwEditCaret;
- SHORT wUnConvPos;
- LPTSTR lpStr;
- TCHAR YjmPressKey[2];
- YjmPressKey[0]=(char)wParam;
- YjmPressKey[1]=' ';
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
- wUnConvPos = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos;
- lpStr = GETLPCOMPSTR(lpCompStr);
- switch( wParam )
- {
- case VK_ESCAPE:
- MakeResultString(hIMC,FALSE); //清空所有字符
- break;
- case VK_RETURN: // 清空所有字符
- MakeResultString(hIMC,FALSE);
- break;
- //俞建明添加
- case VK_BACK://退格键
- DeleteCharBackward(hIMC,wParam);
- break;
- case VK_DELETE://delete键?
- //DeleteCharForward(hIMC,wParam);
- break;
- case VK_HOME://home键
- if( *lpwEditCaret > 0 ) {
- if( wUnConvPos ){
- *lpwEditCaret = wUnConvPos;
- }
- else {
- *lpwEditCaret = 0;
- }
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_END://end键
- if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
- *lpwEditCaret = (SHORT)_tcslen(lpStr);
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_UP:
- case VK_LEFT://左向键
- if( *lpwEditCaret > 0 ) {
- if( *lpwEditCaret == wUnConvPos) AddChar(hIMC,wParam,EDIT_BACK);
- else {
- *lpwEditCaret -= 1;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_DOWN:
- case VK_RIGHT://右向键
- if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
- *lpwEditCaret += 1;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_SPACE://空格键
- //SpaceSelect(hIMC,wParam); //或者
- SelectCandFromCandlist( hIMC, _T('1'));
- /*
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- */
- break;
- default:
- break;
- }
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- if (( VK_0 <= wParam && VK_9 >= wParam ) ||
- ( VK_A <= wParam && VK_Z >= wParam ) ||
- ( VK_NUMPAD0 <= wParam && VK_NUMPAD9 >= wParam ) ||
- ( VK_OEM_1 <= wParam && VK_OEM_9 >= wParam ) ||
- ( VK_MULTIPLY <= wParam && VK_DIVIDE >= wParam )||
- (_tcsstr(AttUsedcodes,YjmPressKey)))
- {
- return( FALSE );//以上按键被许可继续执行CharHandlerAttachLib
- }
- else
- return( TRUE );//其它按键被忽略
- }
- BOOL KeydownHandlerWubi(
- HIMC hIMC,
- WORD wParam,
- LONG lParam,
- LPBYTE lpbKeyState)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- GENEMSG GnMsg;
- SHORT *lpwEditCaret;
- SHORT wUnConvPos;
- LPTSTR lpStr;
- TCHAR YjmPressKey[2];
- YjmPressKey[0]=(char)wParam;
- YjmPressKey[1]=' ';
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
- wUnConvPos = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos;
- lpStr = GETLPCOMPSTR(lpCompStr);
- switch( wParam )
- {
- case VK_ESCAPE:
- MakeResultString(hIMC,FALSE); //清空所有字符
- break;
- case VK_RETURN:
- if(wConversionSet1 & C_SET1_RETURN_ENGLISH){
- wPreConversionMode=wConversionMode;
- fTempState=1;
- wConversionMode=CONVERSION_MODE_ENGLISH;
- MakeResultString(hIMC,TRUE);
- //TurnIntoPinyinMode(hIMC);
- }
- else
- MakeResultString(hIMC,FALSE); //清空所有字符
- break;
- case VK_BACK:
- DeleteCharBackward(hIMC,wParam);//退格键
- break;
- case VK_DELETE:
- //DeleteCharForward(hIMC,wParam);//delete键?
- break;
- case VK_HOME://home键
- if( *lpwEditCaret > 0 ) {
- if( wUnConvPos ){
- *lpwEditCaret = wUnConvPos;
- }
- else {
- *lpwEditCaret = 0;
- }
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_END://end键
- if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
- *lpwEditCaret = (SHORT)_tcslen(lpStr);
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_UP:
- case VK_LEFT://左向键
- if( *lpwEditCaret > 0 ) {
- if( *lpwEditCaret == wUnConvPos) AddChar(hIMC,wParam,EDIT_BACK);
- else {
- *lpwEditCaret -= 1;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_DOWN:
- case VK_RIGHT://右向键
- if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
- *lpwEditCaret += 1;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_SPACE://空格键
- _tcscpy(szPreResultCode,lpStr);
- SpaceSelect(hIMC,wParam);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- break;
- default:
- break;
- }
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- if (( VK_0 <= wParam && VK_9 >= wParam ) ||
- ( VK_A <= wParam && VK_Z >= wParam ) ||
- ( VK_NUMPAD0 <= wParam && VK_NUMPAD9 >= wParam ) ||
- ( VK_OEM_1 <= wParam && VK_OEM_9 >= wParam ) ||
- ( VK_MULTIPLY <= wParam && VK_DIVIDE >= wParam )||
- (_tcsstr(WbUsedcodes,YjmPressKey)))
- {
- return( FALSE );//以上按键被许可继续执行CharHandlerWubi
- }
- else
- return( TRUE );//其它按键被忽略
- }
- BOOL KeydownHandlerWbAtt(
- HIMC hIMC,
- WORD wParam,
- LONG lParam,
- LPBYTE lpbKeyState)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- GENEMSG GnMsg;
- SHORT *lpwEditCaret;
- SHORT wUnConvPos;
- LPTSTR lpStr;
- TCHAR YjmPressKey[2];
- YjmPressKey[0]=(char)wParam;
- YjmPressKey[1]=' ';
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
- wUnConvPos = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos;
- lpStr = GETLPCOMPSTR(lpCompStr);
- switch( wParam )
- {
- case VK_ESCAPE:
- MakeResultString(hIMC,FALSE); //清空所有字符
- break;
- case VK_RETURN:
- MakeResultString(hIMC,FALSE); //清空所有字符
- break;
- case VK_BACK:
- DeleteCharBackward(hIMC,wParam);//退格键
- break;
- case VK_DELETE:
- //DeleteCharForward(hIMC,wParam);//delete键?
- break;
- case VK_HOME://home键
- if( *lpwEditCaret > 0 ) {
- if( wUnConvPos ){
- *lpwEditCaret = wUnConvPos;
- }
- else {
- *lpwEditCaret = 0;
- }
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_END://end键
- if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
- *lpwEditCaret = (SHORT)_tcslen(lpStr);
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_UP:
- case VK_LEFT://左向键
- if( *lpwEditCaret > 0 ) {
- if( *lpwEditCaret == wUnConvPos) AddChar(hIMC,wParam,EDIT_BACK);
- else {
- *lpwEditCaret -= 1;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_DOWN:
- case VK_RIGHT://右向键
- if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
- *lpwEditCaret += 1;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_SPACE://空格键
- _tcscpy(szPreResultCode,lpStr);
- SpaceSelect(hIMC,wParam);
- /*
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- */
- break;
- default:
- break;
- }
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- if (( VK_0 <= wParam && VK_9 >= wParam ) ||
- ( VK_A <= wParam && VK_Z >= wParam ) ||
- ( VK_NUMPAD0 <= wParam && VK_NUMPAD9 >= wParam ) ||
- ( VK_OEM_1 <= wParam && VK_OEM_9 >= wParam ) ||
- ( VK_MULTIPLY <= wParam && VK_DIVIDE >= wParam )||
- (_tcsstr(WbUsedcodes,YjmPressKey))||
- (_tcsstr(AttUsedcodes,YjmPressKey)))
- {
- return( FALSE );//以上按键被许可继续执行CharHandlerWubi
- }
- else
- return( TRUE );//其它按键被忽略
- }
- BOOL KeydownHandler(
- HIMC hIMC,
- WORD wParam,
- LONG lParam,
- LPBYTE lpbKeyState)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- GENEMSG GnMsg;
- SHORT *lpwEditCaret;
- SHORT wUnConvPos;
- LPTSTR lpStr;
- /*/
- TCHAR szStr[100];
- _stprintf(szStr,"wParam: %d",wParam);
- MessageBox(NULL,szStr,_T("提示"),MB_OK);
- return( TRUE );
- /*/
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
- wUnConvPos = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos;
- lpStr = GETLPCOMPSTR(lpCompStr);
- switch( wParam )
- {//五种需要稳定状态:拼音,五笔,区位,自定义,时间
- //三种不需要稳定状态:以词定字,五笔半自动加码,五笔手工加码
- case VK_ESCAPE:
- if(wConversionMode == CONVERSION_MODE_WUBIADD||wConversionMode == CONVERSION_MODE_WUBIADDSELF)
- wConversionMode = CONVERSION_MODE_WUBI;
- //if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR)
- // wConversionMode =wPreConversionMode;
- MakeResultString(hIMC,FALSE); //清空所有字符
- break;
- //俞建明添加
- case VK_RETURN: //以词定字
- {
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- LPTSTR lpPaintStr;
- /*if(wConversionMode == CONVERSION_MODE_WUBI){
- MakeResultString(hIMC,FALSE);
- break;
- }
- else */
- if( wConversionMode == CONVERSION_MODE_WUBIADD) {
- if((wConversionSet1 & C_SET1_ERBIMAKEWORD)?
- AutoGetWordErbiCode (AutoWuBiWord,1):
- AutoGetWordWubiCode (AutoWuBiWord,1)) {
- /*LPTSTR lpStr1;
- _tcscpy(lpStr,AutoWuBiCode);
- _tcscpy(YJMMessage,_T("(编码结果):"));
- lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpStr1,WUBIMODELADD);//显示标志
- _tcscat(lpStr1,YJMMessage);//显示提示
- _tcscat(lpStr1,lpStr);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);*/
- MessageBox(NULL,AutoWuBiCode,AutoWuBiWord,MB_OK);
- wConversionMode = CONVERSION_MODE_WUBI;
- MakeResultString(hIMC,FALSE);
- break;
- }
- }
- else if( wConversionMode == CONVERSION_MODE_WUBIADDSELF) {
- if(InsertPhrase (lpStr, AutoWuBiWord))
- MessageBox(NULL,lpStr,"手工造词失败",MB_OK);
- MakeResultString(hIMC,FALSE);
- wConversionMode = CONVERSION_MODE_WUBI;
- break;
- }
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
- if( lpCandList->dwCount ){
- //从其它模式进入,先保存一下原先模式参数
- if(wConversionMode != CONVERSION_MODE_PHRASETOCHAR)
- wPreConversionMode =wConversionMode;
- //
- wConversionMode = CONVERSION_MODE_PHRASETOCHAR;
- //
- lpPaintStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpPaintStr,PHTOCHMODEL);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- ImmUnlockIMCC(lpIMC->hCandInfo);
- break;
- }
- case VK_BACK://退格键
- if( wConversionMode == CONVERSION_MODE_WUBIADDSELF) {
- LPTSTR lpStr1;
- WORD wStrLen = _tcslen(lpStr);
- if(wStrLen>=1) *(lpStr + wStrLen-1) = _T(' ');
- lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpStr1,WUBIMODELADDSELF);//显示标志
- _tcscat(lpStr1,YJMMessage);//显示提示
- _tcscat(lpStr1,lpStr);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- break;
- }
- DeleteCharBackward(hIMC,wParam);
- break;
- case VK_DELETE://delete键
- DeleteCharForward(hIMC,wParam);
- break;
- case VK_HOME://home键
- if( *lpwEditCaret > 0 ) {
- if( wUnConvPos ){
- *lpwEditCaret = wUnConvPos;
- }
- else {
- *lpwEditCaret = 0;
- }
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_END://end键
- if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
- *lpwEditCaret = (SHORT)_tcslen(lpStr);
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_UP:
- case VK_LEFT://左向键
- if( *lpwEditCaret > 0 ) {
- if( *lpwEditCaret == wUnConvPos) AddChar(hIMC,wParam,EDIT_BACK);
- else {
- *lpwEditCaret -= 1;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_DOWN:
- case VK_RIGHT://右向键
- if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
- *lpwEditCaret += 1;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- else MessageBeep(0xFFFFFFFF );
- break;
- case VK_SPACE://空格键
- SpaceSelect(hIMC,wParam);
- /*
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- */
- break;
- default:
- break;
- }
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- //DebugLog(2,(DebugLogFile,"入口wParam: %d ",wParam));
- if (( VK_0 <= wParam && VK_9 >= wParam ) ||
- ( VK_A <= wParam && VK_Z >= wParam ) ||
- ( VK_NUMPAD0 <= wParam && VK_NUMPAD9 >= wParam ) ||
- ( VK_OEM_1 <= wParam && VK_OEM_9 >= wParam ) ||
- ( VK_MULTIPLY <= wParam && VK_DIVIDE >= wParam ))
- {
- return( FALSE );//以上按键被许可继续执行CharHandler
- }
- else
- return( TRUE );//其它按键被忽略
- }
- BOOL CharHandlerAttachLib(
- HIMC hIMC,
- WORD wParam,
- LONG lParam)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- LPCANDIDATEINFO lpCandInfo;
- DWORD dwStrLen;
- GENEMSG GnMsg;
- TCHAR YjmPressKey[2];
- YjmPressKey[0]=(char)wParam;
- YjmPressKey[1]=' ';
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- dwStrLen = lpCompStr->dwCompStrLen;
- if (!dwStrLen)//首键进入此
- {
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- ClearCompStr(lpCompStr);
- ClearCandidate(lpCandInfo);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- //
- GnMsg.msg = WM_IME_STARTCOMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- if( (wParam < _T('a') || wParam > _T('z')) &&
- (wParam < _T('A') || wParam > _T('Z')) &&
- (wParam < _T('0') || wParam > _T('9')) &&
- (!_tcsstr(AttUsedcodes,YjmPressKey))){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return GeneratePunct(hIMC,wParam);//首键非数字字母键,止步于此。
- }
- }
- if( CharHandleAttachLib(hIMC,wParam,lParam)) goto my_exit;
- //当返回为1时,跳过如下半角符号转化为全角的部分
- FullHalfShapeHandler(hIMC,lpCompStr,wParam);
- my_exit:
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- void FullHalfShapeHandler(HIMC hIMC,LPCOMPOSITIONSTRING lpCompStr,WPARAM wParam)
- {
- LPTSTR lpConvStr;
- if( wParam >= _T('!') && wParam <= _T('~') && lpCompStr->dwCompStrLen == 0) {
- lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
- if(wConversionSet & CONVERSION_SET_FULLSHAPE) {
- BYTE bChar[4];
- bChar[0] = 0xA3;
- bChar[1] = (BYTE)wParam + 0x80;
- bChar[2] = 0;
- bChar[3] = 0;
- memcpy((LPBYTE)lpConvStr,bChar,4);
- }
- else{
- *lpConvStr = (TCHAR)wParam;
- *(lpConvStr+1) = _T(' ');
- }
- MakeResultString(hIMC,TRUE);
- }
- }
- BOOL CharHandlerWubi(
- HIMC hIMC,
- WORD wParam,
- LONG lParam)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- LPCANDIDATEINFO lpCandInfo;
- DWORD dwStrLen;
- GENEMSG GnMsg;
- LPTSTR lpStr;
- TCHAR YjmPressKey[2];
- YjmPressKey[0]=(char)wParam;
- YjmPressKey[1]=' ';
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- dwStrLen = lpCompStr->dwCompStrLen;
- if (!dwStrLen)//首键进入此
- {
- //历史复用
- if((wConversionSet & CONVERSION_SET_HISTORYREUSE) &&
- (wConversionMode == CONVERSION_MODE_WUBI) &&
- (wParam == _T('\'))&&_tcslen(YJMMessage)>1){
- wPreConversionMode=wConversionMode;
- fTempState=1;
- wConversionMode=CONVERSION_MODE_HISTORYREUSE;
- lpCompStr->dwCompStrLen=1;
- lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpStr,_T("历史复用(0-9):"));
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- goto my_exit;
- }
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- ClearCompStr(lpCompStr);
- ClearCandidate(lpCandInfo);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- GnMsg.msg = WM_IME_STARTCOMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- //转入临时拼音状态
- if(wConversionSet & CONVERSION_SET_TEMPPINYIN && wParam == _T('/')){
- wPreConversionMode=wConversionMode;
- fTempState=1;
- TurnIntoPinyinMode(hIMC);
- wConversionMode=CONVERSION_MODE_TEMPPINYIN;
- goto my_exit;
- }
- //转入附加词库状态
- else if((wConversionSet & CONVERSION_SET_ATTACHLIB) && (wParam == _T('/'))){
- wPreConversionMode=wConversionMode;
- fTempState=1;
- TurnIntoAttachLibMode(hIMC);
- wConversionMode=CONVERSION_MODE_TEMPATTACHLIB;
- goto my_exit;
- }
- else if((wParam < _T('a') || wParam > _T('z')) &&
- (wParam < _T('A') || wParam > _T('Z')) &&
- (wParam < _T('0') || wParam > _T('9')) &&
- (wConversionSet1 & C_SET1_FIRSTCODEPUNCT?1:!_tcsstr(WbUsedcodes,YjmPressKey))){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return GeneratePunct(hIMC,wParam);//首键非数字字母键,止步于此。
- }
- }
- //if(wConversionMode == CONVERSION_MODE_WUBIATTACHLIB)
- //if( CharHandleWuBiAttachLib(hIMC,wParam,lParam) ) goto my_exit;
- if(wConversionMode == CONVERSION_MODE_WUBI){
- //if(wConversionSet1 & C_SET1_WUBI_MODE2){
- //if(CharHandleWuBi2(hIMC,wParam,lParam)) goto my_exit;
- //}
- //else
- if(CharHandleWuBi(hIMC,wParam,lParam) ) goto my_exit;
- }
- if(wConversionMode == CONVERSION_MODE_HISTORYREUSE)
- if( CharHandleHistoryReuse(hIMC,wParam,lParam) ) goto my_exit;
- //当返回为1时,跳过如下半角符号转化为全角的部分
- FullHalfShapeHandler(hIMC,lpCompStr,wParam);
- my_exit:
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- BOOL CharHandlerWbAtt(
- HIMC hIMC,
- WORD wParam,
- LONG lParam)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- LPCANDIDATEINFO lpCandInfo;
- DWORD dwStrLen;
- GENEMSG GnMsg;
- LPTSTR lpStr;
- TCHAR YjmPressKey[2];
- YjmPressKey[0]=(char)wParam;
- YjmPressKey[1]=' ';
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- dwStrLen = lpCompStr->dwCompStrLen;
- if (!dwStrLen)//首键进入此
- {
- //历史复用
- if((wConversionSet & CONVERSION_SET_HISTORYREUSE) &&
- (wConversionMode == CONVERSION_MODE_WUBI) &&
- (wParam == _T('\'))&&_tcslen(YJMMessage)>1){
- wPreConversionMode=wConversionMode;
- fTempState=1;
- wConversionMode=CONVERSION_MODE_HISTORYREUSE;
- lpCompStr->dwCompStrLen=1;
- lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpStr,_T("历史复用(0-9):"));
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- goto my_exit;
- }
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- ClearCompStr(lpCompStr);
- ClearCandidate(lpCandInfo);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- GnMsg.msg = WM_IME_STARTCOMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- //转入临时拼音状态
- if(wConversionSet & CONVERSION_SET_TEMPPINYIN && wParam == _T('/')){
- wPreConversionMode=wConversionMode;
- fTempState=1;
- TurnIntoPinyinMode(hIMC);
- wConversionMode=CONVERSION_MODE_TEMPPINYIN;
- goto my_exit;
- }
- //转入附加词库状态
- else if((wConversionSet & CONVERSION_SET_ATTACHLIB) && (wParam == _T('/'))){
- wPreConversionMode=wConversionMode;
- fTempState=1;
- TurnIntoAttachLibMode(hIMC);
- wConversionMode=CONVERSION_MODE_TEMPATTACHLIB;
- goto my_exit;
- }
- else if((wParam < _T('a') || wParam > _T('z')) &&
- (wParam < _T('A') || wParam > _T('Z')) &&
- (wParam < _T('0') || wParam > _T('9')) &&
- (!_tcsstr(WbUsedcodes,YjmPressKey))&&
- (!_tcsstr(AttUsedcodes,YjmPressKey))){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return GeneratePunct(hIMC,wParam);//首键非数字字母键,止步于此。
- }
- }
- //if(wConversionMode == CONVERSION_MODE_WUBIATTACHLIB)
- if( CharHandleWuBiAttachLib(hIMC,wParam,lParam) ) goto my_exit;
- /*if(wConversionMode == CONVERSION_MODE_WUBI)
- if( CharHandleWuBi(hIMC,wParam,lParam) ) goto my_exit;
- if(wConversionMode == CONVERSION_MODE_HISTORYREUSE)
- if( CharHandleHistoryReuse(hIMC,wParam,lParam) ) goto my_exit;*/
- //当返回为1时,跳过如下半角符号转化为全角的部分
- FullHalfShapeHandler(hIMC,lpCompStr,wParam);
- my_exit:
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- BOOL CharHandler(
- HIMC hIMC,
- WORD wParam,
- LONG lParam)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- LPCANDIDATEINFO lpCandInfo;
- DWORD dwStrLen;
- GENEMSG GnMsg;
- //LPTSTR lpConvStr;
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- dwStrLen = lpCompStr->dwCompStrLen;
- if (!dwStrLen)//首键进入此
- {
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- ClearCompStr(lpCompStr);
- ClearCandidate(lpCandInfo);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- GnMsg.msg = WM_IME_STARTCOMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- //重复输入最后一次的输入结果
- if(wParam == _T('#')&& wConversionMode != CONVERSION_MODE_WUBI) {
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return RepeatPreResult(hIMC);
- }
- else if( (wParam < _T('a') || wParam > _T('z')) &&
- (wParam < _T('A') || wParam > _T('Z')) &&
- (wParam < _T('0') || wParam > _T('9')) ){
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return GeneratePunct(hIMC,wParam);//首键非数字字母键,止步于此。
- }
- if(wConversionSet & CONVERSION_SET_NO_IUV){
- if( wParam == _T('i') ) {
- LPTSTR lpStr;
- wPreConversionMode=wConversionMode;
- fTempState=1;
- wConversionMode = CONVERSION_MODE_I;
- lpStr = GETLPCOMPSTR(lpCompStr);
- *lpStr = (TCHAR)wParam;
- *(lpStr+1) = _T(' ');
- lpCompStr->dwCompStrLen = _tcslen(lpStr);
- lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpStr,IMODEL);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- goto my_exit;
- }
- if( wParam == _T('u') ) {
- LPTSTR lpStr;
- wPreConversionMode=wConversionMode;
- fTempState=1;
- wConversionMode = CONVERSION_MODE_U;
- lpStr = GETLPCOMPSTR(lpCompStr);
- *lpStr = (TCHAR)wParam;
- *(lpStr+1) = _T(' ');
- lpCompStr->dwCompStrLen = _tcslen(lpStr);
- lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpStr,UMODEL);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- goto my_exit;
- }
- if( wParam == _T('v') ) {
- LPTSTR lpStr;
- wPreConversionMode=wConversionMode;
- fTempState=1;
- wConversionMode = CONVERSION_MODE_V;
- lpStr = GETLPCOMPSTR(lpCompStr);
- *lpStr = (TCHAR)wParam;
- *(lpStr+1) = _T(' ');
- lpCompStr->dwCompStrLen = _tcslen(lpStr);
- lpCompStr->dwCompStrLen=1;
- lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpStr,VMODEL);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- goto my_exit;
- }
- }
- }
- if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR) {
- if( CharHandlePhToCh(hIMC,wParam,lParam) ) goto my_exit;
- }
- else if(wConversionMode == CONVERSION_MODE_I) {
- if( CharHandleI(hIMC,wParam,lParam) ) goto my_exit;
- }
- else if(wConversionMode == CONVERSION_MODE_U) {
- if( CharHandleU(hIMC,wParam,lParam) ) goto my_exit;
- }
- else if(wConversionMode == CONVERSION_MODE_V) {
- if( CharHandleV(hIMC,wParam,lParam) ) goto my_exit;
- }
- else if(wConversionMode == CONVERSION_MODE_WUBIADD) {
- if( CharHandleWuBiAdd(hIMC,wParam,lParam) ) goto my_exit;
- }
- else if(wConversionMode == CONVERSION_MODE_WUBIADDSELF) {
- if( CharHandleWuBiAddSelf(hIMC,wParam,lParam) ) goto my_exit;
- }
- else{
- if( CharHandleNormal(hIMC,wParam,lParam) ) goto my_exit;
- }
- //当返回为1时,跳过如下半角符号转化为全角的部分
- FullHalfShapeHandler(hIMC,lpCompStr,wParam);
- my_exit:
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- void ViewSharedMemoryCondition()
- {
- TCHAR szStr[1000],szStr1[200];
- _stprintf(szStr,"%s词库尾:%dn%s词库尾:%dn记录汉字符数:%dn%s单字库尾:%dn",
- StatusDisplay[CONVERSION_MODE_WUBI],dwWubiMapFileOffset,
- StatusDisplay[CONVERSION_MODE_ATTACHLIB],dwAttachLibMapFileOffset,strlen(HistoryTwoCodes)/2,
- StatusDisplay[CONVERSION_MODE_PINYIN],dwHistoryMapFileOffset);
- _stprintf(szStr1,"%s系统词库尾:%dn%s用户词库尾:%dn",StatusDisplay[CONVERSION_MODE_PINYIN],
- dwMapFileOffset,StatusDisplay[CONVERSION_MODE_PINYIN],dwMapFileUsrOffset);
- _tcscat(szStr,szStr1);
- if(wConversionSet &CONVERSION_SET_USEWB){
- _stprintf(szStr1,"%s全部码元:n%sn%s系统词库码元:n%sn%s用户词库码元:n%sn",
- StatusDisplay[CONVERSION_MODE_WUBI],WbUsedcodes,StatusDisplay[CONVERSION_MODE_WUBI],WbSysUsedcodes,
- StatusDisplay[CONVERSION_MODE_WUBI],WbUsrUsedcodes);
- _tcscat(szStr,szStr1);
- _stprintf(szStr1,"%s库末:%sn",StatusDisplay[CONVERSION_MODE_WUBI],(char *)wubiDictHead->prev->strHZ);
- _tcscat(szStr,szStr1);
- }
- if(wConversionSet &CONVERSION_SET_USEATTACH){
- _stprintf(szStr1,"%s词库全部码元:n%sn",StatusDisplay[CONVERSION_MODE_ATTACHLIB],AttUsedcodes);
- _tcscat(szStr,szStr1);
- _stprintf(szStr1,"%s库末:%sn",StatusDisplay[CONVERSION_MODE_ATTACHLIB],(char *)AttachLibDictHead->prev->strHZ);
- _tcscat(szStr,szStr1);
- }
- if(wConversionSet &CONVERSION_SET_USEWB){
- LPWBRecord recTemp=wubiDictHead->next;
- int uTotal=0,uSame=0;
- while(recTemp!=wubiDictHead->prev){
- uTotal++;
- if(!_tcscmp(recTemp->strCode,recTemp->next->strCode)) uSame++;
- recTemp=recTemp->next;
- }
- _stprintf(szStr1,"%s词条总数:%dn%s重码数:%dn%s重码率:%d%%n",
- StatusDisplay[CONVERSION_MODE_WUBI],uTotal,StatusDisplay[CONVERSION_MODE_WUBI],uSame,
- StatusDisplay[CONVERSION_MODE_WUBI],uSame*100/uTotal);
- _tcscat(szStr,szStr1);
- }
- if(wConversionSet &CONVERSION_SET_USEATTACH){
- LPAttachLibRecord recTemp=AttachLibDictHead->next;
- int uTotal=0,uSame=0;
- while(recTemp!=AttachLibDictHead->prev){
- uTotal++;
- if(!_tcscmp(recTemp->strCode,recTemp->next->strCode)) uSame++;
- recTemp=recTemp->next;
- }
- _stprintf(szStr1,"%s词条总数:%dn%s重码数:%dn%s重码率:%d%%n",
- StatusDisplay[CONVERSION_MODE_ATTACHLIB],uTotal,StatusDisplay[CONVERSION_MODE_ATTACHLIB],uSame,
- StatusDisplay[CONVERSION_MODE_ATTACHLIB],uSame*100/uTotal);
- _tcscat(szStr,szStr1);
- }
- MessageBox(NULL,szStr,_T("共享内存情况报告:"),MB_OK);
- }
- void DeleteSamePhrase()
- {
- if(SaySorry()) return;
- if (MessageBox(NULL, _T("你要自动删除相同的词条吗?"), _T("删除相同词条,提高词库效能"), MB_YESNO) == IDYES){
- AutoDelSamePhrase ();
- MessageBox(NULL,_T("已经完成整理工作"),_T("自动删除相同词条"),MB_OK);
- }
- }
- int SaySorry()
- {
- if(wConversionMode != CONVERSION_MODE_WUBI){
- MessageBoxPrintf(_T("对不起"),_T("本功能仅适用五笔模式。"));
- return 1;
- }
- else return 0;
- }
- void MakeWordFromClipboard(HIMC hIMC)
- {
- LPINPUTCONTEXT lpIMC;
- lpIMC = ImmLockIMC(hIMC);
- if(SaySorry()) return;
- if(OpenClipboard(NULL))
- {
- TCHAR szStr[200],szStr1[2000];
- HANDLE hData = GetClipboardData(CF_TEXT);
- char * lpStr = (char*)GlobalLock(hData);
- int nLen,i=0;
- if(lpStr==NULL){
- MessageBox(NULL,_T("剪贴板取词失败!"),_T("出错"),MB_OK);
- return ;
- //goto my_exit;
- }
- _tcscpy(szStr1,lpStr);
- GlobalUnlock(hData);
- CloseClipboard();
- nLen=_tcslen(szStr1);
- if(nLen>MAXSTRHZLENGTH-2){
- MessageBox(NULL, _T("字数至多35个。"), _T("字数太多了。"), MB_OK);
- return;
- }
- if(nLen%2){
- MessageBox(NULL, _T("不能包含半角符号。"), _T("含有半角符号"), MB_OK);
- return;
- }
- if(nLen<=2){
- MessageBox(NULL, _T("汉字数至少两个。"), _T("汉字数至少两个。"), MB_OK);
- return;
- }
- while (i<nLen ) {
- if (IsDBCSLeadByte((BYTE)*(szStr1+i))) {
- i+=2;
- continue;
- }
- else {
- MessageBox(NULL, _T("不能含非gbk字符。"), _T("含非gbk字符"), MB_OK);
- return;
- }
- }
- if((wConversionSet1 & C_SET1_ERBIMAKEWORD)?
- AutoGetWordErbiCode (szStr1,0):
- AutoGetWordWubiCode (szStr1,0)) {
- _stprintf(szStr,"%s:%sn要加入自动编码吗?n",szStr1,AutoWuBiCode);
- if (MessageBox(NULL, szStr, _T("自动加码提示:手工录码请选否。"), MB_YESNO) == IDYES){
- if(wConversionSet1 & C_SET1_ERBIMAKEWORD) AutoGetWordErbiCode (szStr1,1);
- else AutoGetWordWubiCode (szStr1,1);
- }
- else {
- _stprintf(szStr,"要手工录入编码吗?n%sn",szStr1);
- if(MessageBox(NULL,szStr,_T("请选择:"),MB_YESNO) == IDYES){
- //加入手工加码部分
- _tcscpy(AutoWuBiWord,szStr1);
- MakeResultString(hIMC,FALSE);
- lpIMC->fOpen=FALSE;
- DialogBox( hInst,MAKEINTRESOURCE(DIALOGADDCODE),NULL,AddDialogProc);
- InsertPhrase(AutoWuBiCode,AutoWuBiWord);
- lpIMC->fOpen=TRUE;
- }
- else MessageBox(NULL,_T("放弃了手工录码!"),_T("无为退出"),MB_OK);
- }
- }
- else {
- MessageBox(NULL,_T("对剪贴板中的词自动编码换失败!"),_T("出错信息"),MB_OK);
- }
- }
- else MessageBox(NULL,_T("剪贴板打开失败!"),_T("出错"),MB_OK);
- }
- void TurnUserWordIntoSys()
- { WORD UserWordNum=0;
- TCHAR szStr[256];
- if(SaySorry()) return;
- wubiDictCurrent = wubiDictHead->next;
- while (wubiDictCurrent != wubiDictHead->prev) {
- if (wubiDictCurrent->BeUser)
- UserWordNum++;
- wubiDictCurrent = wubiDictCurrent->next;
- }//计数
- _stprintf(szStr,"当前用户词库的词组个数%d个。",UserWordNum);
- if (MessageBox(NULL, szStr,_T("要将用户词导入系统词库吗?"),
- MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) == IDYES) {
- wubiDictCurrent = wubiDictHead->next;
- while (wubiDictCurrent != wubiDictHead->prev) {
- if (wubiDictCurrent->BeUser) wubiDictCurrent->BeUser=0;
- wubiDictCurrent = wubiDictCurrent->next;
- }
- MessageBox(NULL,_T("谢谢使用。"),_T("您已经升格了所有的用户词到系统词库中。"),MB_OK);
- }
- else MessageBoxPrintf(_T("建议:请经常将用户词升格到系统词库。"),_T("您已经放弃升格用户词到系统词库。"));
- if (MessageBox(NULL,_T("要立即保存系统词库吗?"),_T("建议:立即保存系统词库,除非你已经选择了保存系统词库的选项。"),
- MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) == IDYES) {
- SaveWubiSysDict();
- }
- }
- void TurnToNextWordLib(BOOL CurrentDir)
- {
- static int j=0;
- TCHAR TempTableDir[MAX_PATH];
- if(!CurrentDir){
- j++;
- if(_tcslen(RelativeTableDirList[j])==0) j=0;
- sprintf(TempTableDir,"%smb\%s\",InstallFromDir,RelativeTableDirList[j]);
- if(!_tcscmp(CurrentTableDir,TempTableDir)){
- j++;
- if(_tcslen(RelativeTableDirList[j])==0) j=0;
- }
- }
- TurnToNextWordLib1(j);
- }
- void TurnToNextWordLib1(UINT j)
- {
- TCHAR TempTableDir[MAX_PATH];
- if(j>=MAX_LIBDIRNUM)return;
- if(strlen(RelativeTableDirList[j])==0) return;
- SwitchUserPath=1;
- SwitchUserPathGT++;
- SwitchUserPathGT%=100;
- DestroyDictionary();//清除所有共享内存
- ClearPunct();
- LoadHZDictionary("",1);
- _tcscpy(StatusDisplay[CONVERSION_MODE_WUBI],_T("五笔"));
- sprintf(TempTableDir,"%smb\%s\",InstallFromDir,RelativeTableDirList[j]);
- MessageBoxPrintf(_T("码表目录切换"),_T("从%sn到%sn"),CurrentTableDir,TempTableDir);
- _tcscpy(CurrentTableDir,TempTableDir);
- //记录下CurrentTableDir
- WriteGlobalIni();
- //读入个性化数据
- ReadUserIni();
- InitDictionary();//重新载入所有文件至共享内存
- SwitchUserPath=0;
- }
- void ShowSystemTime()
- {
- SYSTEMTIME tm;
- TCHAR szStr[50];
- GetLocalTime(&tm);
- _stprintf(szStr,"%d时%d分%d秒",tm.wHour,tm.wMinute,tm.wSecond);
- MessageBox(NULL,szStr,_T("系统时间"),MB_OK);
- }
- void AbsorbZhongyiTable()
- {
- TCHAR szStr[200];
- _stprintf(szStr,"如果要吸收中易输入法生成器逆转换生成的码表,n请先将之保存为winwbx.txt。n你要加入winwb86格式的词条吗?n");
- if (MessageBox(NULL, szStr, _T("吸收中易输入法生成器逆转换生成的码表:"), MB_YESNO) == IDYES){
- LoadWinImegenTable();
- MessageBoxPrintf(_T("自动加入词条"),_T("已经完成加入词条工作"));
- }
- else{
- _stprintf(szStr,"提示:将中易输入法生成器逆转换生成的的词条加入。n可以让你继续使用的原来自造的特殊词汇。n");
- MessageBoxPrintf(_T("放弃加入词条"),szStr);
- }
- }
- void DeleteHistoryRecord()
- {
- if (MessageBox(NULL, _T("要将要清除输入历史吗?"),_T("若为快速造词,请保留输入历史。"),
- MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) == IDYES) {
- ClearWordHistory ();
- MessageBox(NULL,_T("谢谢使用。"),_T("您已经清除了输入历史。"),MB_OK);
- }
- else MessageBox(NULL,_T("建议:为安全起见,请清除输入历史。"),
- _T("您已经放弃清除输入历史。"),MB_OK);
- }
- void TurnIntoAttachLibMode(HIMC hIMC)
- {
- if(!(wConversionSet &CONVERSION_SET_USEATTACH)) return;
- wConversionMode = CONVERSION_MODE_ATTACHLIB;
- UpdateStatusByMessage(hIMC);
- if(!fTempState)WriteUserIni();
- }
- void TurnIntoWubiAttachLibMode(HIMC hIMC)
- {
- if(!(wConversionSet &CONVERSION_SET_USEWB)) return;
- if(!(wConversionSet &CONVERSION_SET_USEATTACH)) return;
- wConversionMode = CONVERSION_MODE_WUBIATTACHLIB;
- UpdateStatusByMessage(hIMC);
- WriteUserIni();
- }
- void TurnIntoWubiMode(HIMC hIMC)
- {
- if(!(wConversionSet &CONVERSION_SET_USEWB)) return;
- wConversionMode = CONVERSION_MODE_WUBI;
- UpdateStatusByMessage(hIMC);
- WriteUserIni();
- }
- void TurnIntoWubiModeAdd(HIMC hIMC)
- {
- LPINPUTCONTEXT lpIMC;
- LPCOMPOSITIONSTRING lpCompStr;
- GENEMSG GnMsg;
- LPTSTR lpStr;
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- wConversionMode = CONVERSION_MODE_WUBIADD;
- lpCompStr->dwCompStrLen=1;
- lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- _tcscpy(lpStr,WUBIMODELADD);
- GnMsg.msg = WM_IME_COMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_COMPSTR;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- void TurnIntoPinyinMode(HIMC hIMC)
- {
- if(!(wConversionSet &CONVERSION_SET_USEPY)) return;
- wConversionMode = CONVERSION_MODE_PINYIN;
- UpdateStatusByMessage(hIMC);
- if(!fTempState)WriteUserIni();
- }
- void TurnIntoQuickMode(HIMC hIMC)
- {
- wConversionMode = CONVERSION_MODE_QUICK;
- UpdateStatusByMessage(hIMC);
- WriteUserIni();
- }
- void TurnIntoMode_U(HIMC hIMC)
- {
- wConversionMode = CONVERSION_MODE_U;
- WriteUserIni();
- UpdateStatusByMessage(hIMC);
- }
- void TurnIntoMode_I(HIMC hIMC)
- {
- wConversionMode = CONVERSION_MODE_I;
- WriteUserIni();
- UpdateStatusByMessage(hIMC);
- }
- void TurnIntoMode_V(HIMC hIMC)
- {
- wConversionMode = CONVERSION_MODE_V;
- WriteUserIni();
- UpdateStatusByMessage(hIMC);
- }
- void ToggleConversionMode(HIMC hIMC)
- {
- if(wConversionMode == CONVERSION_MODE_WUBI)
- TurnIntoPinyinMode(hIMC);
- else
- TurnIntoWubiMode(hIMC);
- }
- void ToggleConversionMode1()
- {
- if(wConversionMode == CONVERSION_MODE_WUBI){
- if(!(wConversionSet &CONVERSION_SET_USEPY)) return;
- wConversionMode = CONVERSION_MODE_PINYIN;
- }
- else {
- if(!(wConversionSet &CONVERSION_SET_USEWB)) return;
- wConversionMode = CONVERSION_MODE_WUBI;
- }
- }
- void ToggleConversionSet(DWORD Conversion_Set_Value)
- {
- if(wConversionSet & Conversion_Set_Value)
- wConversionSet &= ~Conversion_Set_Value;
- else
- wConversionSet |= Conversion_Set_Value;
- WriteUserIni();
- }
- void UpdateStatusByMessage(HIMC hIMC)
- {
- GENEMSG GnMsg;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_SETCONVERSIONMODE;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }
- void CreateStatusByMessage(HIMC hIMC)
- {
- GENEMSG GnMsg;
- GnMsg.msg = WM_IME_NOTIFY;
- GnMsg.wParam = IMN_OPENSTATUSWINDOW;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
- }