HZmodewubiadd.c
上传用户:szljw888
上传日期:2010-04-11
资源大小:124k
文件大小:6k
源码类别:

输入法编程

开发平台:

C/C++

  1. /* 大熊猫输入法(Free Chinese Input)  由YJMSIR(yjmsir@163.com)编写
  2.  * 协议: GPL
  3.  * freeinput( A Chinese Input Method) by YJMSIR(yjmsir@163.com)
  4.  * Licence: GPL 
  5.  */
  6. #include "freepy.h"
  7. BOOL CharHandleWuBiAdd( HIMC hIMC,WORD wParam,LONG lParam)
  8. {
  9.     LPINPUTCONTEXT lpIMC;
  10. LPCANDIDATEINFO lpCandInfo;
  11. LPCANDIDATELIST lpCandList;
  12. LPCOMPOSITIONSTRING lpCompStr;
  13. GENEMSG GnMsg;
  14.     LPTSTR lpStr,lpStr1;
  15. WORD wStrLen1;
  16. _tcscpy(YJMMessage,_T("(编码词语):"));
  17. WordHistoryStrLen=_tcslen(WordHistoryStr);
  18. if(WordHistoryStrLen<4) return 1;
  19.     lpIMC = ImmLockIMC(hIMC);
  20. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  21. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  22. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  23. lpStr = GETLPCOMPSTR(lpCompStr);
  24. if(WubiAddLength<4){//默认为二个汉字 //复制历史记录
  25. WubiAddLength=4;
  26. _tcscpy(lpStr,WordHistoryStr+WordHistoryStrLen-WubiAddLength);
  27. }
  28. //接收键盘输入
  29. if( wParam == _T('D')||wParam == _T('S')||wParam == _T('A')||wParam == _T('=') || wParam == _T('.') || wParam == _T('>')||wParam == _T('-') || wParam == _T(',') || wParam == _T('<')) {
  30. switch(wParam){
  31. case _T('.'):
  32. case _T('>'):
  33. if(WubiAddLength<=WordHistoryStrLen-2) WubiAddLength +=2;
  34. _tcscpy(YJMMessage,_T("(加2):"));
  35. break;
  36. case _T('='):
  37. if(WubiAddLength<=WordHistoryStrLen-1)WubiAddLength ++;
  38. _tcscpy(YJMMessage,_T("(加1):"));
  39. break;
  40. case _T(','):
  41. case _T('<'):
  42. if(WubiAddLength>=6) WubiAddLength -=2;
  43. _tcscpy(YJMMessage,_T("(减2):"));
  44. break;
  45. case _T('-'):
  46. if(WubiAddLength>=5) WubiAddLength --;
  47. _tcscpy(YJMMessage,_T("(减1):"));
  48. break;
  49. case _T('A'):
  50. //这个地方将是重点,
  51. //DebugLog(2,(DebugLogFile,"lpStr:%sAAAn",lpStr));
  52. if((wConversionSet1 & C_SET1_ERBIMAKEWORD)?
  53. AutoGetWordErbiCode (lpStr,1):
  54. AutoGetWordWubiCode (lpStr,1)) {
  55. //MakeResultString(hIMC,FALSE);
  56. //_tcscpy(lpStr,AutoWuBiCode);
  57. //_tcscpy(YJMMessage,_T("(编码结果):"));
  58. //wConversionMode = CONVERSION_MODE_WUBI;
  59. //goto yjmwubidisplay;
  60. MessageBox(NULL,AutoWuBiCode,lpStr,MB_OK);
  61. wConversionMode = CONVERSION_MODE_WUBI;
  62. MakeResultString(hIMC,FALSE);
  63. goto yjmwubiexit;
  64. //break;
  65. }
  66. else {//这里需要补充对话框
  67. MakeResultString(hIMC,FALSE);
  68. wConversionMode = CONVERSION_MODE_WUBIADDSELF;
  69. DialogBox( hInst,MAKEINTRESOURCE(DIALOGADDCODE),NULL,AddDialogProc);
  70. InsertPhrase(AutoWuBiCode,lpStr);
  71. lpIMC->fOpen=TRUE;
  72. wConversionMode = CONVERSION_MODE_WUBI;
  73. break;
  74. }
  75. case _T('S'):
  76. _tcscpy(AutoWuBiWord,lpStr);
  77. MakeResultString(hIMC,FALSE);
  78. lpIMC->fOpen=FALSE;
  79. DialogBox( hInst,MAKEINTRESOURCE(DIALOGADDCODE),NULL,AddDialogProc);
  80. //DebugLog(2,(DebugLogFile,"%s   %sn",AutoWuBiCode,AutoWuBiWord));
  81. InsertPhrase(AutoWuBiCode,AutoWuBiWord);
  82. lpIMC->fOpen=TRUE;
  83. wConversionMode = CONVERSION_MODE_WUBI;
  84. break;
  85. case _T('D'):
  86. _tcscpy(AutoWuBiWord,lpStr);
  87. MakeResultString(hIMC,FALSE);
  88. wConversionMode = CONVERSION_MODE_WUBIADDSELF;
  89. lpCompStr->dwCompStrLen =1;
  90. //DebugLog(2,(DebugLogFile,"%s   %sn",AutoWuBiCode,AutoWuBiWord));
  91. break;
  92. }
  93. }
  94. else {
  95. MessageBeep(0xFFFFFFFF );
  96.     _tcscpy(YJMMessage,_T("(有效按键:减-,< 增=.>确定A,录码S,录码D):"));
  97. }
  98. //DebugLog(2,(DebugLogFile,"WubiAddLength: %d ,%dn",WubiAddLength,WordHistoryStrLen));
  99. //复制历史记录
  100. _tcscpy(lpStr,WordHistoryStr+WordHistoryStrLen-WubiAddLength);
  101. //显示
  102. _tcscpy(AutoWuBiWord,lpStr);
  103. //yjmwubidisplay:
  104. lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  105. wStrLen1 = _tcslen(lpStr1);
  106. _tcscpy(lpStr1,WUBIMODELADD);//显示标志
  107. _tcscat(lpStr1,YJMMessage);//显示提示
  108. _tcscat(lpStr1,lpStr);
  109. GnMsg.msg = WM_IME_COMPOSITION;
  110. GnMsg.wParam = 0;
  111. GnMsg.lParam = GCS_COMPSTR;
  112. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  113. yjmwubiexit:
  114. ImmUnlockIMCC(lpIMC->hCompStr);
  115. ImmUnlockIMCC(lpIMC->hCandInfo);
  116. ImmUnlockIMC(hIMC);
  117. return TRUE;
  118. }
  119. //手工加代码
  120. BOOL CharHandleWuBiAddSelf( HIMC hIMC,WORD wParam,LONG lParam)
  121. {
  122.     LPINPUTCONTEXT lpIMC;
  123. LPCANDIDATEINFO lpCandInfo;
  124. LPCANDIDATELIST lpCandList;
  125. LPCOMPOSITIONSTRING lpCompStr;
  126. GENEMSG GnMsg;
  127.     LPTSTR lpStr,lpStr1;
  128. WORD wStrLen,wStrLen1,WordHistoryStrLen;
  129. _tcscpy(YJMMessage,_T("(回车确定):"));
  130. WordHistoryStrLen=_tcslen(WordHistoryStr);
  131.     lpIMC = ImmLockIMC(hIMC);
  132. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  133. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  134. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  135. lpStr = GETLPCOMPSTR(lpCompStr);
  136. if(*lpStr<_T('a')||*lpStr>_T('z')) *lpStr=_T('');
  137. wStrLen = _tcslen(lpStr);
  138. if(wParam >= _T('a') && wParam <= _T('z')){
  139. //接收键盘输入
  140. *(lpStr + wStrLen) = (TCHAR)wParam;
  141. *(lpStr + wStrLen +1) = _T('');
  142. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  143. }
  144. else if( wParam == _T(',')) {
  145. if(wStrLen>=1) *(lpStr + wStrLen-1) =  _T('');
  146. }
  147. /* else if( wParam == _T('D') ) {
  148. if(InsertPhrase (lpStr, AutoWuBiWord))
  149. MessageBox(NULL,lpStr,"手工造词失败",MB_OK);
  150. MakeResultString(hIMC,FALSE);
  151. wConversionMode = CONVERSION_MODE_WUBI;
  152. }*/
  153. else {
  154. MessageBeep(0xFFFFFFFF );
  155.     _tcscpy(YJMMessage,_T("(有效按键:输入(a-z)删除(,或退格)回车确定):"));
  156. }
  157. //DebugLog(2,(DebugLogFile,"WubiAddLength: %d ,%dn",WubiAddLength,WordHistoryStrLen));
  158. //显示
  159. //yjmwubidisplay:
  160. lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  161. wStrLen1 = _tcslen(lpStr1);
  162. _tcscpy(lpStr1,WUBIMODELADDSELF);//显示标志
  163. _tcscat(lpStr1,YJMMessage);//显示提示
  164. _tcscat(lpStr1,lpStr);
  165. GnMsg.msg = WM_IME_COMPOSITION;
  166. GnMsg.wParam = 0;
  167. GnMsg.lParam = GCS_COMPSTR;
  168. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  169. //yjmwubiexit:
  170. ImmUnlockIMCC(lpIMC->hCompStr);
  171. ImmUnlockIMCC(lpIMC->hCandInfo);
  172. ImmUnlockIMC(hIMC);
  173. return TRUE;
  174. }