HZmodewubiadd.c
资源名称:大熊猫输入法原码.zip [点击查看]
上传用户:szljw888
上传日期:2010-04-11
资源大小:124k
文件大小:6k
源码类别:
输入法编程
开发平台:
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"
- BOOL CharHandleWuBiAdd( HIMC hIMC,WORD wParam,LONG lParam)
- {
- LPINPUTCONTEXT lpIMC;
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- LPCOMPOSITIONSTRING lpCompStr;
- GENEMSG GnMsg;
- LPTSTR lpStr,lpStr1;
- WORD wStrLen1;
- _tcscpy(YJMMessage,_T("(编码词语):"));
- WordHistoryStrLen=_tcslen(WordHistoryStr);
- if(WordHistoryStrLen<4) return 1;
- lpIMC = ImmLockIMC(hIMC);
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpStr = GETLPCOMPSTR(lpCompStr);
- if(WubiAddLength<4){//默认为二个汉字 //复制历史记录
- WubiAddLength=4;
- _tcscpy(lpStr,WordHistoryStr+WordHistoryStrLen-WubiAddLength);
- }
- //接收键盘输入
- if( wParam == _T('D')||wParam == _T('S')||wParam == _T('A')||wParam == _T('=') || wParam == _T('.') || wParam == _T('>')||wParam == _T('-') || wParam == _T(',') || wParam == _T('<')) {
- switch(wParam){
- case _T('.'):
- case _T('>'):
- if(WubiAddLength<=WordHistoryStrLen-2) WubiAddLength +=2;
- _tcscpy(YJMMessage,_T("(加2):"));
- break;
- case _T('='):
- if(WubiAddLength<=WordHistoryStrLen-1)WubiAddLength ++;
- _tcscpy(YJMMessage,_T("(加1):"));
- break;
- case _T(','):
- case _T('<'):
- if(WubiAddLength>=6) WubiAddLength -=2;
- _tcscpy(YJMMessage,_T("(减2):"));
- break;
- case _T('-'):
- if(WubiAddLength>=5) WubiAddLength --;
- _tcscpy(YJMMessage,_T("(减1):"));
- break;
- case _T('A'):
- //这个地方将是重点,
- //DebugLog(2,(DebugLogFile,"lpStr:%sAAAn",lpStr));
- if((wConversionSet1 & C_SET1_ERBIMAKEWORD)?
- AutoGetWordErbiCode (lpStr,1):
- AutoGetWordWubiCode (lpStr,1)) {
- //MakeResultString(hIMC,FALSE);
- //_tcscpy(lpStr,AutoWuBiCode);
- //_tcscpy(YJMMessage,_T("(编码结果):"));
- //wConversionMode = CONVERSION_MODE_WUBI;
- //goto yjmwubidisplay;
- MessageBox(NULL,AutoWuBiCode,lpStr,MB_OK);
- wConversionMode = CONVERSION_MODE_WUBI;
- MakeResultString(hIMC,FALSE);
- goto yjmwubiexit;
- //break;
- }
- else {//这里需要补充对话框
- MakeResultString(hIMC,FALSE);
- wConversionMode = CONVERSION_MODE_WUBIADDSELF;
- DialogBox( hInst,MAKEINTRESOURCE(DIALOGADDCODE),NULL,AddDialogProc);
- InsertPhrase(AutoWuBiCode,lpStr);
- lpIMC->fOpen=TRUE;
- wConversionMode = CONVERSION_MODE_WUBI;
- break;
- }
- case _T('S'):
- _tcscpy(AutoWuBiWord,lpStr);
- MakeResultString(hIMC,FALSE);
- lpIMC->fOpen=FALSE;
- DialogBox( hInst,MAKEINTRESOURCE(DIALOGADDCODE),NULL,AddDialogProc);
- //DebugLog(2,(DebugLogFile,"%s %sn",AutoWuBiCode,AutoWuBiWord));
- InsertPhrase(AutoWuBiCode,AutoWuBiWord);
- lpIMC->fOpen=TRUE;
- wConversionMode = CONVERSION_MODE_WUBI;
- break;
- case _T('D'):
- _tcscpy(AutoWuBiWord,lpStr);
- MakeResultString(hIMC,FALSE);
- wConversionMode = CONVERSION_MODE_WUBIADDSELF;
- lpCompStr->dwCompStrLen =1;
- //DebugLog(2,(DebugLogFile,"%s %sn",AutoWuBiCode,AutoWuBiWord));
- break;
- }
- }
- else {
- MessageBeep(0xFFFFFFFF );
- _tcscpy(YJMMessage,_T("(有效按键:减-,< 增=.>确定A,录码S,录码D):"));
- }
- //DebugLog(2,(DebugLogFile,"WubiAddLength: %d ,%dn",WubiAddLength,WordHistoryStrLen));
- //复制历史记录
- _tcscpy(lpStr,WordHistoryStr+WordHistoryStrLen-WubiAddLength);
- //显示
- _tcscpy(AutoWuBiWord,lpStr);
- //yjmwubidisplay:
- lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- wStrLen1 = _tcslen(lpStr1);
- _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);
- yjmwubiexit:
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- //手工加代码
- BOOL CharHandleWuBiAddSelf( HIMC hIMC,WORD wParam,LONG lParam)
- {
- LPINPUTCONTEXT lpIMC;
- LPCANDIDATEINFO lpCandInfo;
- LPCANDIDATELIST lpCandList;
- LPCOMPOSITIONSTRING lpCompStr;
- GENEMSG GnMsg;
- LPTSTR lpStr,lpStr1;
- WORD wStrLen,wStrLen1,WordHistoryStrLen;
- _tcscpy(YJMMessage,_T("(回车确定):"));
- WordHistoryStrLen=_tcslen(WordHistoryStr);
- lpIMC = ImmLockIMC(hIMC);
- lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
- lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- lpStr = GETLPCOMPSTR(lpCompStr);
- if(*lpStr<_T('a')||*lpStr>_T('z')) *lpStr=_T(' ');
- wStrLen = _tcslen(lpStr);
- if(wParam >= _T('a') && wParam <= _T('z')){
- //接收键盘输入
- *(lpStr + wStrLen) = (TCHAR)wParam;
- *(lpStr + wStrLen +1) = _T(' ');
- lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
- }
- else if( wParam == _T(',')) {
- if(wStrLen>=1) *(lpStr + wStrLen-1) = _T(' ');
- }
- /* else if( wParam == _T('D') ) {
- if(InsertPhrase (lpStr, AutoWuBiWord))
- MessageBox(NULL,lpStr,"手工造词失败",MB_OK);
- MakeResultString(hIMC,FALSE);
- wConversionMode = CONVERSION_MODE_WUBI;
- }*/
- else {
- MessageBeep(0xFFFFFFFF );
- _tcscpy(YJMMessage,_T("(有效按键:输入(a-z)删除(,或退格)回车确定):"));
- }
- //DebugLog(2,(DebugLogFile,"WubiAddLength: %d ,%dn",WubiAddLength,WordHistoryStrLen));
- //显示
- //yjmwubidisplay:
- lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
- wStrLen1 = _tcslen(lpStr1);
- _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);
- //yjmwubiexit:
- ImmUnlockIMCC(lpIMC->hCompStr);
- ImmUnlockIMCC(lpIMC->hCandInfo);
- ImmUnlockIMC(hIMC);
- return TRUE;
- }