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

输入法编程

开发平台:

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. UINT ReturnHaveAutoCandList(LPTSTR,LPTSTR);
  8. UINT ReturnHaveAutoCandListErbi(LPTSTR,LPTSTR);
  9. BOOL CharHandleWuBiAttachLib( HIMC hIMC,WORD wParam,LONG lParam)
  10. {
  11.     LPINPUTCONTEXT lpIMC;
  12. LPCANDIDATEINFO lpCandInfo;
  13. LPCANDIDATELIST lpCandList;
  14. LPCOMPOSITIONSTRING lpCompStr;
  15. GENEMSG GnMsg;
  16.     LPTSTR lpStr,lpStr1;
  17. WORD wStrLen,i,k=2;
  18. TCHAR YjmPressKey[2];
  19. int ComXResult1,ComXResult2;
  20. WBRecord  __based(lpWubiMapFileBase)      *recTemp1;
  21. AttachLibRecord  __based(lpAttachLibMapFileBase) *recTemp2;
  22. YjmPressKey[0]=(char)wParam;
  23. YjmPressKey[1]='';
  24. if(!(wConversionSet &CONVERSION_SET_USEWB)) return 1;
  25. if(!(wConversionSet &CONVERSION_SET_USEATTACH)) return 1;
  26. /* if((wConversionSet & CONVERSION_SET_WBSPEED) && (WuBiSpeed!=0))
  27. _stprintf(YJMMessage,"(%d字/分):",WuBiSpeed);
  28. else*/
  29. _tcscpy(YJMMessage,_T(""));
  30.     lpIMC = ImmLockIMC(hIMC);
  31. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  32. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  33. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  34. lpCandList->dwPageSize=CAND_PAGESIZE;
  35. if(lpCandList->dwPageStart <2)  lpCandList->dwPageStart = 2;
  36. lpStr = GETLPCOMPSTR(lpCompStr);
  37. wStrLen = _tcslen(lpStr);
  38. //接收键盘输入
  39. //if(wParam >= _T('a') && wParam <= _T('z')){
  40. if(_tcsstr(WbUsedcodes,YjmPressKey)||_tcsstr(AttUsedcodes,YjmPressKey)){
  41. wStrLen = _tcslen(lpStr);
  42. *(lpStr + wStrLen) = (TCHAR)wParam;
  43. *(lpStr + wStrLen +1) = _T('');
  44. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  45. //对于极点z万能键的兼容
  46. if(wParam == _T('z')&&wStrLen==1){
  47. if(_tcslen(((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr)!=0){
  48. _tcscpy(GETLPCANDSTR(lpCandList,2),((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr);
  49. lpCandList->dwCount =1;
  50. wubiDictCurrent = wubiDictHead->next;
  51. goto yjmwubidisplay;
  52. }
  53. }
  54. //多于4键(即5键)的处理,适用于盲打,不浪费输入的字符
  55. if(!(wConversionSet & CONVERSION_SET_CODEGT4)){
  56. if(wStrLen>4){
  57. SpaceSelect(hIMC,wParam);
  58. szPreResultCode[wStrLen-1]=_T('');
  59. _tcscpy(lpStr,lpStr+wStrLen-1);
  60. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  61. }
  62. }
  63. if(CodeForward && wStrLen>2&&
  64. AttachLibDictCurrent!=AttachLibDictHead->prev &&
  65. wubiDictCurrent!=wubiDictHead->prev ){
  66. ComXResult1=(int)CompareWBCodeX(lpStr,wubiDictCurrent->strCode);
  67. ComXResult1-=MaxCompareWBCodeX-(wStrLen-1);
  68. ComXResult2=(int)CompareWBCodeX(lpStr,AttachLibDictCurrent->strCode);
  69. ComXResult2-=MaxCompareWBCodeX-(wStrLen-1);
  70. if(ComXResult1>0 &&ComXResult2>0){
  71. SpaceSelect(hIMC,wParam);
  72. szPreResultCode[wStrLen-1]=_T('');
  73. _tcscpy(lpStr,lpStr+wStrLen-1);
  74. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  75. }
  76. else if(ComXResult1==0 &&ComXResult2==0){
  77. if(_tcscmp(lpStr,AttachLibDictCurrent->strCode)<0 &&
  78. _tcscmp(lpStr,wubiDictCurrent->strCode)<0){
  79. SpaceSelect(hIMC,wParam);
  80. szPreResultCode[wStrLen-1]=_T('');
  81. _tcscpy(lpStr,lpStr+wStrLen-1);
  82. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  83. }
  84. else if(_tcscmp(lpStr,AttachLibDictCurrent->strCode)>0&&
  85.     _tcscmp(lpStr,wubiDictCurrent->strCode)>0){
  86. recTemp2=AttachLibDictCurrent;
  87. while(recTemp2->next!=AttachLibDictHead->prev&&
  88. _tcscmp(lpStr,recTemp2->strCode)>0)
  89. recTemp2=recTemp2->next;
  90. recTemp1=wubiDictCurrent;
  91. while(recTemp1->next!=wubiDictHead->prev&&
  92. _tcscmp(lpStr,recTemp1->strCode)>0)
  93. recTemp1=recTemp1->next;
  94. ComXResult1=(int)CompareWBCodeX(lpStr,recTemp1->strCode);
  95. ComXResult1-=MaxCompareWBCodeX-wStrLen;
  96. ComXResult2=(int)CompareWBCodeX(lpStr,recTemp2->strCode);
  97. ComXResult2-=MaxCompareWBCodeX-wStrLen;
  98. if(_tcscmp(lpStr,recTemp1->strCode)<0 && ComXResult1>0&&
  99. _tcscmp(lpStr,recTemp2->strCode)<0 && ComXResult2>0){
  100. SpaceSelect(hIMC,wParam);
  101. szPreResultCode[wStrLen-1]=_T('');
  102. _tcscpy(lpStr,lpStr+wStrLen-1);
  103. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  104. }
  105. }
  106. }
  107. }
  108. CodeForward=1;
  109. //依编码查找五笔//加快速度的方案
  110. if(wStrLen<2)
  111. wubiDictCurrent = wubiDictHead->next;
  112. else wubiDictCurrent = wubiDictCurrentRecord;
  113. while (wubiDictCurrent != wubiDictHead->prev) {
  114. if (_tcscmp(lpStr, wubiDictCurrent->strCode)<=0) {
  115. if (_tcscmp(lpStr,wubiDictCurrent->strCode)<0) {
  116. lpCandList->dwCount=0;
  117. break;
  118. }
  119. wubiDictCurrentRecord=wubiDictCurrent;
  120. for( i=0,k=2;i<CAND_PAGESIZE;i++){
  121. if(wubiDictCurrent == wubiDictHead->prev) break;
  122. if(_tcscmp (lpStr, wubiDictCurrent->strCode)) break;
  123. if(!(wConversionSet & CONVERSION_SET_GBK) && 
  124. !IsStringGb2312(wubiDictCurrent->strHZ)) {
  125. wubiDictCurrent = wubiDictCurrent->next;
  126. continue;
  127. }
  128. //取消对非gb2312字的上屏
  129. _tcscpy(GETLPCANDSTR(lpCandList,k),wubiDictCurrent->strHZ);
  130. k++;
  131. wubiDictCurrent = wubiDictCurrent->next;
  132. }
  133. lpCandList->dwCount =k-2;
  134. break;
  135. }
  136. wubiDictCurrent = wubiDictCurrent->next;
  137. }
  138. //依编码查找附加词库//加快速度的方案
  139. if(wStrLen<2)
  140. AttachLibDictCurrent = AttachLibDictHead->next;
  141. else AttachLibDictCurrent = AttachLibDictCurrentRecord;
  142. while (AttachLibDictCurrent != AttachLibDictHead->prev) {
  143. if (_tcscmp(lpStr, AttachLibDictCurrent->strCode)<=0) {
  144. AttachLibDictCurrentRecord=AttachLibDictCurrent;
  145. for(i=0;i<CAND_PAGESIZE && k<CAND_PAGESIZE+2;i++){// 
  146. if(AttachLibDictCurrent == AttachLibDictHead->prev) break;
  147. if(_tcscmp (lpStr, AttachLibDictCurrent->strCode)) break;
  148. //仅gb2312字符集汉字上屏
  149. if(!(wConversionSet & CONVERSION_SET_GBK) && 
  150. !IsStringGb2312(AttachLibDictCurrent->strHZ)) {
  151. AttachLibDictCurrent = AttachLibDictCurrent->next;
  152. continue;
  153. }
  154. _tcscpy(GETLPCANDSTR(lpCandList,k),AttachLibDictCurrent->strHZ);
  155. k++;
  156. AttachLibDictCurrent = AttachLibDictCurrent->next;
  157. }
  158. lpCandList->dwCount =k-2;
  159. break;
  160. }
  161. AttachLibDictCurrent = AttachLibDictCurrent->next;
  162. }
  163. //
  164. if(wStrLen>2&&(lpCandList->dwCount ==1)&&
  165. AttachLibDictCurrent!=AttachLibDictHead->prev&& 
  166. wubiDictCurrent!=wubiDictHead->prev){
  167. ComXResult1=(int)CompareWBCodeX(lpStr,wubiDictCurrent->strCode);
  168. ComXResult1-=MaxCompareWBCodeX-(wStrLen-1);
  169. ComXResult2=(int)CompareWBCodeX(lpStr,AttachLibDictCurrent->strCode);
  170. ComXResult2-=MaxCompareWBCodeX-(wStrLen-1);
  171. if(ComXResult1>0&&ComXResult2>0){
  172. SpaceSelect(hIMC,wParam);
  173. goto yjmwubidisplay;
  174. }
  175. }
  176. }
  177. //以上接收键盘输入a-z
  178. //翻页功能
  179. else if( wParam == _T('=') || wParam == _T('>')) {//wParam == _T('.') || 
  180. //SelectForwardFromCand(hIMC,lpCandList);
  181. wubiDictCurrentRecord=wubiDictCurrent;
  182. AttachLibDictCurrentRecord=AttachLibDictCurrent;
  183. wParam=*(lpStr+wStrLen-1);
  184. *(lpStr+wStrLen-1)=_T('');
  185. CodeForward=0;
  186. ImmUnlockIMCC(lpIMC->hCompStr);
  187. ImmUnlockIMC(hIMC);
  188. CharHandleWuBiAttachLib(hIMC,wParam,0);
  189. }
  190. else if( wParam == _T('-') || wParam == _T('<')) {//wParam == _T(',') || 
  191. //SelectBackwardFromCand(hIMC,lpCandList);
  192. UINT i;
  193. for(i=0;i<CAND_PAGESIZE && wubiDictCurrentRecord!=wubiDictHead->next;i++){
  194. wubiDictCurrentRecord=wubiDictCurrentRecord->prev;
  195. }
  196. for(i=0;i<CAND_PAGESIZE && AttachLibDictCurrentRecord!=AttachLibDictHead->next;i++){
  197. AttachLibDictCurrentRecord=AttachLibDictCurrentRecord->prev;
  198. }
  199. wParam=*(lpStr+wStrLen-1);
  200. *(lpStr+wStrLen-1)=_T('');
  201. CodeForward=0;
  202. ImmUnlockIMCC(lpIMC->hCompStr);
  203. ImmUnlockIMC(hIMC);
  204. CharHandleWuBiAttachLib(hIMC,wParam,0);
  205. }
  206. //选择功能1234567890
  207. else if( wParam >= _T('0') && wParam <= _T('9') ){
  208. if( !IsCompStr(hIMC)) return FALSE;//如果首键是数字,放行。
  209. SelectCandFromCandlist(hIMC, wParam);
  210. }
  211. //选用第二候选词的方便键
  212. else if( wParam == _T(';')&&lpCandList->dwCount >=2){
  213. SelectCandFromCandlist(hIMC, _T('2'));
  214. }
  215. //选用第三候选词的方便键
  216. else if( wParam == _T(''')&&lpCandList->dwCount >=3){
  217. SelectCandFromCandlist(hIMC, _T('3'));
  218. }
  219. //符号推字上屏
  220. else if( wParam == _T('!')||wParam == _T('@')||wParam == _T('#')||wParam == _T('$')||
  221. wParam == _T('%')||wParam == _T('^')||wParam == _T('&')||wParam == _T('*')||
  222. wParam == _T('(')||wParam == _T(')')||wParam == _T(',')||wParam == _T('.')||
  223. wParam == _T(';')||wParam == _T(''')||wParam == _T('\')||wParam == _T('/')||
  224. wParam == _T(':')||wParam == _T('"')||wParam == _T('?')||
  225. wParam == _T('[')||wParam == _T(']')||wParam == _T('{')||wParam == _T('}')){
  226. PunctPushWordFlag=1;
  227. SelectCandFromCandlist( hIMC, _T('1'));
  228. PunctPushWordFlag=0;
  229. GeneratePunct(hIMC,wParam);
  230. return TRUE;
  231. }
  232. else return FALSE;
  233. //显示
  234. yjmwubidisplay:
  235. lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  236. _tcscpy(lpStr1,lpStr);
  237. ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret=_tcslen(lpStr1);
  238. if(wConversionSet & CONVERSION_SET_WBSPEED) _tcscat(lpStr1,SpeedMessage);//显示提示
  239. GnMsg.msg = WM_IME_COMPOSITION;
  240. GnMsg.wParam = 0;
  241. GnMsg.lParam = GCS_COMPSTR;
  242. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  243. //yjmwubiexit:
  244. ImmUnlockIMCC(lpIMC->hCompStr);
  245. ImmUnlockIMCC(lpIMC->hCandInfo);
  246. ImmUnlockIMC(hIMC);
  247. return TRUE;
  248. }
  249. /*
  250. BOOL CharHandleWuBiAttachLib( HIMC hIMC,WORD wParam,LONG lParam)
  251. {
  252.     LPINPUTCONTEXT lpIMC;
  253. LPCANDIDATEINFO lpCandInfo;
  254. LPCANDIDATELIST lpCandList;
  255. LPCOMPOSITIONSTRING lpCompStr;
  256. GENEMSG GnMsg;
  257.     LPTSTR lpStr,lpStr1;
  258. WORD wStrLen,i,k=2;
  259. TCHAR YjmPressKey[2];
  260. int ComXResult1,ComXResult2;
  261. WBRecord  __based(lpWubiMapFileBase)      *recTemp1;
  262. AttachLibRecord  __based(lpAttachLibMapFileBase) *recTemp2;
  263. YjmPressKey[0]=(char)wParam;
  264. YjmPressKey[1]='';
  265. if(!(wConversionSet &CONVERSION_SET_USEWB)) return 1;
  266. if(!(wConversionSet &CONVERSION_SET_USEATTACH)) return 1;
  267. /* if((wConversionSet & CONVERSION_SET_WBSPEED) && (WuBiSpeed!=0))
  268. _stprintf(YJMMessage,"(%d字/分):",WuBiSpeed);
  269. else
  270. _tcscpy(YJMMessage,_T(""));/
  271.     lpIMC = ImmLockIMC(hIMC);
  272. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  273. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  274. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  275. lpCandList->dwPageSize=CAND_PAGESIZE;
  276. if(lpCandList->dwPageStart <2)  lpCandList->dwPageStart = 2;
  277. lpStr = GETLPCOMPSTR(lpCompStr);
  278. wStrLen = _tcslen(lpStr);
  279. //接收键盘输入
  280. //if(wParam >= _T('a') && wParam <= _T('z')){
  281. if(_tcsstr(WbUsedcodes,YjmPressKey)||_tcsstr(AttUsedcodes,YjmPressKey)){
  282. wStrLen = _tcslen(lpStr);
  283. *(lpStr + wStrLen) = (TCHAR)wParam;
  284. *(lpStr + wStrLen +1) = _T('');
  285. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  286. //对于极点z万能键的兼容
  287. if(wParam == _T('z')&&wStrLen==1){
  288. if(_tcslen(((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr)!=0){
  289. _tcscpy(GETLPCANDSTR(lpCandList,2),((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr);
  290. lpCandList->dwCount =1;
  291. wubiDictCurrent = wubiDictHead->next;
  292. goto yjmwubidisplay;
  293. }
  294. }
  295. //多于4键(即5键)的处理,适用于盲打,不浪费输入的字符
  296. if(!(wConversionSet & CONVERSION_SET_CODEGT4)){
  297. if(wStrLen>4){
  298. SpaceSelect(hIMC,wParam);
  299. szPreResultCode[wStrLen-1]=_T('');
  300. _tcscpy(lpStr,lpStr+wStrLen-1);
  301. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  302. }
  303. }
  304. if(CodeForward && wStrLen>2&&
  305. AttachLibDictCurrent!=AttachLibDictHead->prev &&
  306. wubiDictCurrent!=wubiDictHead->prev ){
  307. ComXResult1=(int)CompareWBCodeX(lpStr,wubiDictCurrent->strCode);
  308. ComXResult1-=MaxCompareWBCodeX-(wStrLen-1);
  309. ComXResult2=(int)CompareWBCodeX(lpStr,AttachLibDictCurrent->strCode);
  310. ComXResult2-=MaxCompareWBCodeX-(wStrLen-1);
  311. if(ComXResult1>0 &&ComXResult2>0){
  312. SpaceSelect(hIMC,wParam);
  313. szPreResultCode[wStrLen-1]=_T('');
  314. _tcscpy(lpStr,lpStr+wStrLen-1);
  315. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  316. }
  317. else if(ComXResult1==0 &&ComXResult2==0){
  318. if(_tcscmp(lpStr,AttachLibDictCurrent->strCode)<0 &&
  319. _tcscmp(lpStr,wubiDictCurrent->strCode)<0){
  320. SpaceSelect(hIMC,wParam);
  321. szPreResultCode[wStrLen-1]=_T('');
  322. _tcscpy(lpStr,lpStr+wStrLen-1);
  323. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  324. }
  325. else if(_tcscmp(lpStr,AttachLibDictCurrent->strCode)>0&&
  326.     _tcscmp(lpStr,wubiDictCurrent->strCode)>0){
  327. recTemp2=AttachLibDictCurrent;
  328. while(recTemp2->next!=AttachLibDictHead->prev&&
  329. _tcscmp(lpStr,recTemp2->strCode)>0)
  330. recTemp2=recTemp2->next;
  331. recTemp1=wubiDictCurrent;
  332. while(recTemp1->next!=wubiDictHead->prev&&
  333. _tcscmp(lpStr,recTemp1->strCode)>0)
  334. recTemp1=recTemp1->next;
  335. ComXResult1=(int)CompareWBCodeX(lpStr,recTemp1->strCode);
  336. ComXResult1-=MaxCompareWBCodeX-wStrLen;
  337. ComXResult2=(int)CompareWBCodeX(lpStr,recTemp2->strCode);
  338. ComXResult2-=MaxCompareWBCodeX-wStrLen;
  339. if(_tcscmp(lpStr,recTemp1->strCode)<0 && ComXResult1>0&&
  340. _tcscmp(lpStr,recTemp2->strCode)<0 && ComXResult2>0){
  341. SpaceSelect(hIMC,wParam);
  342. szPreResultCode[wStrLen-1]=_T('');
  343. _tcscpy(lpStr,lpStr+wStrLen-1);
  344. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  345. }
  346. }
  347. }
  348. }
  349. CodeForward=1;
  350. //依编码查找五笔//加快速度的方案
  351. if(wStrLen<2)
  352. wubiDictCurrent = wubiDictHead->next;
  353. else wubiDictCurrent = wubiDictCurrentRecord;
  354. while (wubiDictCurrent != wubiDictHead->prev) {
  355. if (_tcscmp(lpStr, wubiDictCurrent->strCode)<=0) {
  356. if (_tcscmp(lpStr,wubiDictCurrent->strCode)<0) {
  357. lpCandList->dwCount=0;
  358. break;
  359. }
  360. wubiDictCurrentRecord=wubiDictCurrent;
  361. //for( i=0,k=2;i<MAXCANDSTRNUM;i++){
  362. if(wubiDictCurrent == wubiDictHead->prev) break;
  363. if(_tcscmp (lpStr, wubiDictCurrent->strCode)) break;
  364. if(!(wConversionSet & CONVERSION_SET_GBK) && 
  365. !IsStringGb2312(wubiDictCurrent->strHZ)) {
  366. wubiDictCurrent = wubiDictCurrent->next;
  367. continue;
  368. }
  369. //取消对非gb2312字的上屏
  370. _tcscpy(GETLPCANDSTR(lpCandList,k),wubiDictCurrent->strHZ);
  371. k++;
  372. wubiDictCurrent = wubiDictCurrent->next;
  373. }
  374. lpCandList->dwCount =k-2;
  375. break;
  376. }
  377. wubiDictCurrent = wubiDictCurrent->next;
  378. }
  379. //依编码查找附加词库//加快速度的方案
  380. if(wStrLen<2)
  381. AttachLibDictCurrent = AttachLibDictHead->next;
  382. else AttachLibDictCurrent = AttachLibDictCurrentRecord;
  383. while (AttachLibDictCurrent != AttachLibDictHead->prev) {
  384. if (_tcscmp(lpStr, AttachLibDictCurrent->strCode)<=0) {
  385. AttachLibDictCurrentRecord=AttachLibDictCurrent;
  386. //for( i=0;i<MAXCANDSTRNUM;i++){
  387. if(AttachLibDictCurrent == AttachLibDictHead->prev) break;
  388. if(_tcscmp (lpStr, AttachLibDictCurrent->strCode)) break;
  389. //仅gb2312字符集汉字上屏
  390. if(!(wConversionSet & CONVERSION_SET_GBK) && 
  391. !IsStringGb2312(AttachLibDictCurrent->strHZ)) {
  392. AttachLibDictCurrent = AttachLibDictCurrent->next;
  393. continue;
  394. }
  395. _tcscpy(GETLPCANDSTR(lpCandList,k),AttachLibDictCurrent->strHZ);
  396. k++;
  397. AttachLibDictCurrent = AttachLibDictCurrent->next;
  398. }
  399. lpCandList->dwCount =k-2;
  400. break;
  401. }
  402. AttachLibDictCurrent = AttachLibDictCurrent->next;
  403. }
  404. if(wStrLen>2&&(lpCandList->dwCount ==1)&&
  405. AttachLibDictCurrent!=AttachLibDictHead->prev&& 
  406. wubiDictCurrent!=wubiDictHead->prev){
  407. ComXResult1=(int)CompareWBCodeX(lpStr,wubiDictCurrent->strCode);
  408. ComXResult1-=MaxCompareWBCodeX-(wStrLen-1);
  409. ComXResult2=(int)CompareWBCodeX(lpStr,AttachLibDictCurrent->strCode);
  410. ComXResult2-=MaxCompareWBCodeX-(wStrLen-1);
  411. if(ComXResult1>0&&ComXResult2>0){
  412. SpaceSelect(hIMC,wParam);
  413. goto yjmwubidisplay;
  414. }
  415. }
  416. }
  417. //以上接收键盘输入a-z
  418. //翻页功能
  419. else if( wParam == _T('=') || wParam == _T('>')) {//wParam == _T('.') || 
  420. SelectForwardFromCand(hIMC,lpCandList);
  421. }
  422. else if( wParam == _T('-') || wParam == _T('<')) {//wParam == _T(',') || 
  423. SelectBackwardFromCand(hIMC,lpCandList);
  424. }
  425. //选择功能1234567890
  426. else if( wParam >= _T('0') && wParam <= _T('9') ){
  427. if( !IsCompStr(hIMC)) return FALSE;//如果首键是数字,放行。
  428. SelectCandFromCandlist(hIMC, wParam);
  429. }
  430. //选用第二候选词的方便键
  431. else if( wParam == _T(';')&&lpCandList->dwCount >=2){
  432. SelectCandFromCandlist(hIMC, _T('2'));
  433. }
  434. //选用第三候选词的方便键
  435. else if( wParam == _T(''')&&lpCandList->dwCount >=3){
  436. SelectCandFromCandlist(hIMC, _T('3'));
  437. }
  438. //符号推字上屏
  439. else if( wParam == _T('!')||wParam == _T('@')||wParam == _T('#')||wParam == _T('$')||
  440. wParam == _T('%')||wParam == _T('^')||wParam == _T('&')||wParam == _T('*')||
  441. wParam == _T('(')||wParam == _T(')')||wParam == _T(',')||wParam == _T('.')||
  442. wParam == _T(';')||wParam == _T(''')||wParam == _T('\')||wParam == _T('/')||
  443. wParam == _T(':')||wParam == _T('"')||wParam == _T('?')||
  444. wParam == _T('[')||wParam == _T(']')||wParam == _T('{')||wParam == _T('}')){
  445. PunctPushWordFlag=1;
  446. SelectCandFromCandlist( hIMC, _T('1'));
  447. PunctPushWordFlag=0;
  448. GeneratePunct(hIMC,wParam);
  449. return TRUE;
  450. }
  451. else return FALSE;
  452. //显示
  453. yjmwubidisplay:
  454. lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  455. _tcscpy(lpStr1,lpStr);
  456. ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret=_tcslen(lpStr1);
  457. if(wConversionSet & CONVERSION_SET_WBSPEED) _tcscat(lpStr1,SpeedMessage);//显示提示
  458. GnMsg.msg = WM_IME_COMPOSITION;
  459. GnMsg.wParam = 0;
  460. GnMsg.lParam = GCS_COMPSTR;
  461. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  462. //yjmwubiexit:
  463. ImmUnlockIMCC(lpIMC->hCompStr);
  464. ImmUnlockIMCC(lpIMC->hCandInfo);
  465. ImmUnlockIMC(hIMC);
  466. return TRUE;
  467. }*/
  468. /*
  469. BOOL CharHandleWuBi( HIMC hIMC,WORD wParam,LONG lParam)
  470. {
  471.     LPINPUTCONTEXT lpIMC;
  472. LPCANDIDATEINFO lpCandInfo;
  473. LPCANDIDATELIST lpCandList;
  474. LPCOMPOSITIONSTRING lpCompStr;
  475. GENEMSG GnMsg;
  476.     LPTSTR lpStr,lpStr1;
  477. WORD wStrLen,i,k;
  478. TCHAR YjmPressKey[2];
  479. int ComXResult;
  480. WBRecord __based(lpWubiMapFileBase) *recTemp;
  481. YjmPressKey[0]=(char)wParam;
  482. YjmPressKey[1]='';
  483. if(!(wConversionSet &CONVERSION_SET_USEWB)) return 1;
  484. /*if((wConversionSet & CONVERSION_SET_WBSPEED) && (WuBiSpeed!=0))
  485. _stprintf(YJMMessage,"(%d字/分):",WuBiSpeed);
  486. else/
  487. _tcscpy(YJMMessage,_T(""));
  488.     lpIMC = ImmLockIMC(hIMC);
  489. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  490. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  491. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  492. lpCandList->dwPageSize=CAND_PAGESIZE;
  493. if(lpCandList->dwPageStart <2)  lpCandList->dwPageStart = 2;
  494. lpStr = GETLPCOMPSTR(lpCompStr);
  495. wStrLen = _tcslen(lpStr);
  496. //接收键盘输入
  497. //if(wParam >= _T('a') && wParam <= _T('z')){
  498. if(_tcsstr(WbUsedcodes,YjmPressKey)){
  499. wStrLen = _tcslen(lpStr);
  500. *(lpStr + wStrLen) = (TCHAR)wParam;
  501. *(lpStr + wStrLen +1) = _T('');
  502. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  503. //对自然码,二笔的符号的支持
  504. //if(wConversionSet1 & C_SET1_ERBIMAKEWORD && wStrLen==1 && (wParam == _T(',')||wParam == _T('/')||wParam == _T(';')||wParam == _T('''))){//||wParam == _T(';')
  505. // GeneratePunct(hIMC,wParam);
  506. // return TRUE;
  507. //}
  508. //对极点z万能键的兼容
  509. if(wParam == _T('z')&&wStrLen==1){
  510. if(_tcslen(((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr)!=0){
  511. _tcscpy(GETLPCANDSTR(lpCandList,2),((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr);
  512. lpCandList->dwCount =1;
  513. wubiDictCurrent = wubiDictHead->next;
  514. goto yjmwubidisplay;
  515. }
  516. }
  517. //多于4键(即5键)的处理,适用于盲打,不浪费输入的字符
  518. if(!(wConversionSet & CONVERSION_SET_CODEGT4)&&
  519. (wConversionSet1 & C_SET1_AUTO_INPUT)){
  520. if(wStrLen>4){
  521. SpaceSelect(hIMC,wParam);
  522. szPreResultCode[wStrLen-1]=_T('');
  523. _tcscpy(lpStr,lpStr+wStrLen-1);
  524. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  525. }
  526. }
  527. //查找最后输入的MAXAUTOWUBINUM/2个汉字中是否与输入的编码相同
  528. //如果已经输入了四个编码并且许可全自动造词提示
  529. if(wStrLen==4 && (wConversionSet & CONVERSION_SET_AUTOWORD)){
  530. if(wConversionSet1 & C_SET1_ERBIMAKEWORD)
  531. HaveAutoCandList=ReturnHaveAutoCandListErbi(lpStr,_T(""));
  532. else
  533. HaveAutoCandList=ReturnHaveAutoCandList(lpStr,_T(""));
  534. }
  535. else
  536. HaveAutoCandList=0;
  537. //非前缀化解决方法
  538. ComXResult=(int)CompareWBCodeX(lpStr,wubiDictCurrent->strCode);
  539. ComXResult-=MaxCompareWBCodeX-(wStrLen-1);
  540. if(!HaveAutoCandList && wStrLen>3 && 
  541. CodeForward &&wubiDictCurrent!=wubiDictHead->prev &&
  542. (wConversionSet1 & C_SET1_AUTO_INPUT)){
  543. if(ComXResult>0){
  544. SpaceSelect(hIMC,wParam);
  545. szPreResultCode[wStrLen-1]=_T('');
  546. _tcscpy(lpStr,lpStr+wStrLen-1);
  547. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  548. }
  549. else if(ComXResult==0){
  550. if(_tcscmp(lpStr,wubiDictCurrent->strCode)<0){
  551. SpaceSelect(hIMC,wParam);
  552. szPreResultCode[wStrLen-1]=_T('');
  553. _tcscpy(lpStr,lpStr+wStrLen-1);
  554. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  555. }
  556. else if(_tcscmp(lpStr,wubiDictCurrent->strCode)>0){
  557. recTemp=wubiDictCurrent;
  558. while(recTemp->next!=wubiDictHead->prev&&
  559. _tcscmp(lpStr,recTemp->strCode)>0)
  560. recTemp=recTemp->next;
  561. ComXResult=(int)CompareWBCodeX(lpStr,recTemp->strCode);
  562. ComXResult-=MaxCompareWBCodeX-wStrLen;
  563. if(_tcscmp(lpStr,recTemp->strCode)<0 && ComXResult>0){
  564. SpaceSelect(hIMC,wParam);
  565. szPreResultCode[wStrLen-1]=_T('');
  566. _tcscpy(lpStr,lpStr+wStrLen-1);
  567. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  568. }
  569. }
  570. }
  571. }
  572. CodeForward=1;
  573. //依编码查找五笔//加快速度的方案
  574. if(wStrLen<2)
  575. wubiDictCurrent = wubiDictHead->next;
  576. else wubiDictCurrent = wubiDictCurrentRecord;
  577. while (wubiDictCurrent != wubiDictHead->prev) {
  578. if (_tcscmp(lpStr, wubiDictCurrent->strCode)<=0) {
  579. if (_tcscmp(lpStr,wubiDictCurrent->strCode)<0) {
  580. lpCandList->dwCount=0;
  581. break;
  582. }
  583. wubiDictCurrentRecord=wubiDictCurrent;
  584. //for( i=0,k=2;i<MAXCANDSTRNUM;i++){
  585. if(wubiDictCurrent == wubiDictHead->prev) break;
  586. if(_tcscmp (lpStr, wubiDictCurrent->strCode)) break;
  587. if(!(wConversionSet & CONVERSION_SET_GBK) && 
  588. !IsStringGb2312(wubiDictCurrent->strHZ)) {
  589. wubiDictCurrent = wubiDictCurrent->next;
  590. continue;
  591. }
  592. //取消对非gb2312字的上屏
  593. _tcscpy(GETLPCANDSTR(lpCandList,k),wubiDictCurrent->strHZ);
  594. k++;
  595. wubiDictCurrent = wubiDictCurrent->next;
  596. }
  597. lpCandList->dwCount =k-2;
  598. break;
  599. }
  600. wubiDictCurrent = wubiDictCurrent->next;
  601. }
  602. //如果自动加词找到与输入编码相同词组,则添加于最后。//如果自动词与最后一项相同,不显示
  603. if(HaveAutoCandList){
  604. k=0;//重复利用k作为标志
  605. for(i=0;i<lpCandList->dwCount;i++){
  606. if(!strcmp(AutoWuBiWord,GETLPCANDSTR(lpCandList,2+i))){//如果与某个已有的选项相同
  607. k=1;
  608. if((wConversionSet1 & C_SET1_ERBIMAKEWORD)?
  609. !ReturnHaveAutoCandListErbi(lpStr,GETLPCANDSTR(lpCandList,2+i)):
  610. !ReturnHaveAutoCandList(lpStr,GETLPCANDSTR(lpCandList,2+i))){//二次造词
  611. HaveAutoCandList=0;
  612. goto NoAddAutoMakeWord;//如果二次造词失败
  613. }
  614. }
  615. }
  616. if(k==1){
  617. for(i=0;i<lpCandList->dwCount;i++){
  618. if(!strcmp(AutoWuBiWord,GETLPCANDSTR(lpCandList,2+i))){
  619. HaveAutoCandList=0;
  620. goto NoAddAutoMakeWord;//二次清除
  621. }
  622. }
  623. }
  624. _tcscpy(YJMMessage,_T("(末项造词:)"));//提示
  625. _tcscpy(GETLPCANDSTR(lpCandList,2+lpCandList->dwCount),AutoWuBiWord);
  626. lpCandList->dwCount +=1;
  627. }
  628. NoAddAutoMakeWord:
  629. CodeHintTextBegin=lpCandList->dwCount;
  630. if(wConversionSet1 & C_SET1_CODE_HINT){
  631. for(i=0;i<lpCandList->dwCount;i++)
  632. _tcscpy(CodeHintText[i],"");
  633. recTemp=wubiDictCurrent;
  634. while(lpCandList->dwCount<CAND_PAGESIZE){
  635. _tcscpy(GETLPCANDSTR(lpCandList,2+lpCandList->dwCount),recTemp->strHZ);
  636. _tcscpy(CodeHintText[lpCandList->dwCount],recTemp->strCode);
  637. recTemp = recTemp->next;
  638. lpCandList->dwCount +=1;
  639. }
  640. }
  641. ComXResult=(int)CompareWBCodeX(lpStr,wubiDictCurrent->strCode);
  642. ComXResult-=MaxCompareWBCodeX-wStrLen;
  643. if(!HaveAutoCandList && wStrLen>2&& 
  644. wubiDictCurrent!=wubiDictHead->prev){
  645. if((lpCandList->dwCount ==1)&&
  646. ComXResult>0 &&
  647. (wConversionSet1 & C_SET1_AUTO_INPUT)){//单个选项自动上屏
  648. SpaceSelect(hIMC,wParam);
  649. goto yjmwubidisplay;
  650. }
  651. }
  652. }
  653. //以上接收键盘输入a-z
  654. //翻页功能
  655. else if( wParam == _T('=') || wParam == _T('>')) {//wParam == _T('.') || 
  656. SelectForwardFromCand(hIMC,lpCandList);
  657. }
  658. else if( wParam == _T('-') || wParam == _T('<')) {//wParam == _T(',') || 
  659. SelectBackwardFromCand(hIMC,lpCandList);
  660. }
  661. //选择功能1234567890
  662. else if( wParam >= _T('0') && wParam <= _T('9') ){
  663. if( !IsCompStr(hIMC)) return FALSE;//如果首键是数字,放行。
  664. SelectCandFromCandlist(hIMC, wParam);
  665. }
  666. //选用第二候选词的方便键
  667. else if( wParam == _T(';')&&lpCandList->dwCount >=2){
  668. SelectCandFromCandlist(hIMC, _T('2'));
  669. }
  670. //选用第三候选词的方便键
  671. else if( wParam == _T(''')&&lpCandList->dwCount >=3){
  672. SelectCandFromCandlist(hIMC, _T('3'));
  673. }
  674. //符号推字上屏
  675. else if( wParam == _T('!')||wParam == _T('@')||wParam == _T('#')||wParam == _T('$')||
  676. wParam == _T('%')||wParam == _T('^')||wParam == _T('&')||wParam == _T('*')||
  677. wParam == _T('(')||wParam == _T(')')||wParam == _T(',')||wParam == _T('.')||
  678. wParam == _T(';')||wParam == _T(''')||wParam == _T('\')||wParam == _T('/')||
  679. wParam == _T(':')||wParam == _T('"')||wParam == _T('?')||
  680. wParam == _T('[')||wParam == _T(']')||wParam == _T('{')||wParam == _T('}')){
  681. //if(wConversionSet1 & C_SET1_AUTO_INPUT){
  682. PunctPushWordFlag=1;
  683. SelectCandFromCandlist( hIMC, _T('1'));
  684. PunctPushWordFlag=0;
  685. GeneratePunct(hIMC,wParam);
  686. return TRUE;
  687. /*}
  688. else {
  689. PunctPushWordFlag=1;
  690. wPreConversionMode=wConversionMode;
  691. fTempState=1;
  692. wConversionMode=CONVERSION_MODE_ENGLISH;
  693. //SelectCandFromCandlist( hIMC, _T('1'));
  694. MakeResultString(hIMC,TRUE);
  695. PunctPushWordFlag=0;
  696. GeneratePunct(hIMC,wParam);
  697. return TRUE;
  698. }/
  699. }
  700. else {
  701. ImmUnlockIMCC(lpIMC->hCompStr);
  702. ImmUnlockIMCC(lpIMC->hCandInfo);
  703. ImmUnlockIMC(hIMC);
  704. return FALSE;
  705. }
  706. //显示
  707. yjmwubidisplay:
  708. lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  709. _tcscpy(lpStr1,lpStr);
  710. ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret=_tcslen(lpStr1);
  711. if(wConversionSet & CONVERSION_SET_WBSPEED) _tcscat(lpStr1,SpeedMessage);//显示提示YJMMessage
  712. _tcscat(lpStr1,YJMMessage);
  713. GnMsg.msg = WM_IME_COMPOSITION;
  714. GnMsg.wParam = 0;
  715. GnMsg.lParam = GCS_COMPSTR;
  716. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  717. //yjmwubiexit:
  718. ImmUnlockIMCC(lpIMC->hCompStr);
  719. ImmUnlockIMCC(lpIMC->hCandInfo);
  720. ImmUnlockIMC(hIMC);
  721. return TRUE;
  722. }*/
  723. //
  724. BOOL CharHandleWuBi( HIMC hIMC,WORD wParam,LONG lParam)
  725. {
  726.     LPINPUTCONTEXT lpIMC;
  727. LPCANDIDATEINFO lpCandInfo;
  728. LPCANDIDATELIST lpCandList;
  729. LPCOMPOSITIONSTRING lpCompStr;
  730. GENEMSG GnMsg;
  731.     LPTSTR lpStr,lpStr1;
  732. WORD wStrLen,i,k;
  733. TCHAR YjmPressKey[2];
  734. int ComXResult;
  735. WBRecord __based(lpWubiMapFileBase) *recTemp;
  736. YjmPressKey[0]=(char)wParam;
  737. YjmPressKey[1]='';
  738. if(!(wConversionSet &CONVERSION_SET_USEWB)) return 1;
  739. _tcscpy(YJMMessage,_T(""));
  740.     lpIMC = ImmLockIMC(hIMC);
  741. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  742. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  743. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  744. lpCandList->dwPageSize=CAND_PAGESIZE;
  745. if(lpCandList->dwPageStart <2)  lpCandList->dwPageStart = 2;
  746. lpStr = GETLPCOMPSTR(lpCompStr);
  747. wStrLen = _tcslen(lpStr);
  748. //接收键盘输入
  749. if(_tcsstr(WbUsedcodes,YjmPressKey)){
  750. wStrLen = _tcslen(lpStr);
  751. *(lpStr + wStrLen) = (TCHAR)wParam;
  752. *(lpStr + wStrLen +1) = _T('');
  753. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  754. //对极点z万能键的兼容
  755. if(wParam == _T('z')&&wStrLen==1){
  756. if(_tcslen(((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr)!=0){
  757. _tcscpy(GETLPCANDSTR(lpCandList,2),((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr);
  758. lpCandList->dwCount =1;
  759. //wubiDictCurrent = wubiDictHead->next;
  760. //{
  761. SetwubiFirstLeadChr((TCHAR)wParam);
  762. wubiDictCurrentRecord=wubiFirstLeadChr[(TCHAR)wParam-_T('!')];
  763. //}
  764. goto yjmwubidisplay;
  765. }
  766. }
  767. //多于4键(即5键)的处理,适用于盲打,不浪费输入的字符
  768. if(!(wConversionSet & CONVERSION_SET_CODEGT4)&&
  769. (wConversionSet1 & C_SET1_AUTO_INPUT)){
  770. if(wStrLen>4){
  771. SpaceSelect(hIMC,wParam);
  772. szPreResultCode[wStrLen-1]=_T('');
  773. _tcscpy(lpStr,lpStr+wStrLen-1);
  774. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  775. }
  776. }
  777. //查找最后输入的MAXAUTOWUBINUM/2个汉字中是否与输入的编码相同
  778. //如果已经输入了四个编码并且许可全自动造词提示
  779. if(wStrLen==4 && (wConversionSet & CONVERSION_SET_AUTOWORD)){
  780. if(wConversionSet1 & C_SET1_ERBIMAKEWORD)
  781. HaveAutoCandList=ReturnHaveAutoCandListErbi(lpStr,_T(""));
  782. else
  783. HaveAutoCandList=ReturnHaveAutoCandList(lpStr,_T(""));
  784. }
  785. else
  786. HaveAutoCandList=0;
  787. //非前缀化解决方法
  788. ComXResult=(int)CompareWBCodeX(lpStr,wubiDictCurrent->strCode);
  789. ComXResult-=MaxCompareWBCodeX-(wStrLen-1);
  790. if(!HaveAutoCandList && wStrLen>3 && 
  791. CodeForward && wubiDictCurrent!=wubiDictHead->prev &&
  792. (wConversionSet1 & C_SET1_AUTO_INPUT)){
  793. if(ComXResult>0){
  794. SpaceSelect(hIMC,wParam);
  795. szPreResultCode[wStrLen-1]=_T('');
  796. _tcscpy(lpStr,lpStr+wStrLen-1);
  797. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  798. }
  799. else if(ComXResult==0){
  800. if(_tcscmp(lpStr,wubiDictCurrent->strCode)<0){
  801. SpaceSelect(hIMC,wParam);
  802. szPreResultCode[wStrLen-1]=_T('');
  803. _tcscpy(lpStr,lpStr+wStrLen-1);
  804. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  805. }
  806. else if(_tcscmp(lpStr,wubiDictCurrent->strCode)>0){
  807. recTemp=wubiDictCurrent;
  808. while(recTemp->next!=wubiDictHead->prev&&
  809. _tcscmp(lpStr,recTemp->strCode)>0)
  810. recTemp=recTemp->next;
  811. ComXResult=(int)CompareWBCodeX(lpStr,recTemp->strCode);
  812. ComXResult-=MaxCompareWBCodeX-wStrLen;
  813. if(_tcscmp(lpStr,recTemp->strCode)<0 && ComXResult>0){
  814. SpaceSelect(hIMC,wParam);
  815. szPreResultCode[wStrLen-1]=_T('');
  816. _tcscpy(lpStr,lpStr+wStrLen-1);
  817. lpCompStr->dwCompStrLen = wStrLen = _tcslen(lpStr);
  818. }
  819. }
  820. }
  821. }
  822. CodeForward=1;
  823. //依编码查找五笔//加快速度的方案
  824. if(wStrLen<2)
  825. //wubiDictCurrent = wubiDictHead->next;
  826. //if(cFirstChr=*lpStr)
  827. {
  828. SetwubiFirstLeadChr((TCHAR)wParam);
  829. wubiDictCurrent=wubiFirstLeadChr[(TCHAR)wParam-_T('!')];
  830. }
  831. //else 
  832. else wubiDictCurrent = wubiDictCurrentRecord;
  833. while (wubiDictCurrent != wubiDictHead->prev) {
  834. if (_tcscmp(lpStr, wubiDictCurrent->strCode)<=0) {
  835. if (_tcscmp(lpStr,wubiDictCurrent->strCode)<0) {
  836. lpCandList->dwCount=0;
  837. break;
  838. }
  839. wubiDictCurrentRecord=wubiDictCurrent;
  840. //
  841. for( i=0,k=2;i<CAND_PAGESIZE;i++){//MAXCANDSTRNUM
  842. if(wubiDictCurrent == wubiDictHead->prev) break;
  843. if(_tcscmp (lpStr, wubiDictCurrent->strCode)) break;
  844. if(!(wConversionSet & CONVERSION_SET_GBK) && 
  845. !IsStringGb2312(wubiDictCurrent->strHZ)) {
  846. wubiDictCurrent = wubiDictCurrent->next;
  847. continue;
  848. }
  849. //取消对非gb2312字的上屏
  850. _tcscpy(GETLPCANDSTR(lpCandList,k),wubiDictCurrent->strHZ);
  851. k++;
  852. wubiDictCurrent = wubiDictCurrent->next;
  853. }
  854. lpCandList->dwCount =k-2;
  855. break;
  856. }
  857. wubiDictCurrent = wubiDictCurrent->next;
  858. }
  859. //如果自动加词找到与输入编码相同词组,则添加于最后。//如果自动词与最后一项相同,不显示
  860. if(HaveAutoCandList){
  861. k=0;//重复利用k作为标志
  862. recTemp=wubiDictCurrentRecord;
  863. while(_tcscmp(lpStr,recTemp->strCode)<=0 && recTemp!=wubiDictHead->next) 
  864. recTemp=recTemp->prev;
  865. while(_tcscmp(lpStr,recTemp->strCode)>=0 && recTemp!=wubiDictHead->prev){ 
  866. if(!strcmp(AutoWuBiWord,recTemp->strHZ)){//清除
  867. k=1;
  868. if((wConversionSet1 & C_SET1_ERBIMAKEWORD)?
  869. !ReturnHaveAutoCandListErbi(lpStr,GETLPCANDSTR(lpCandList,2+i)):
  870. !ReturnHaveAutoCandList(lpStr,GETLPCANDSTR(lpCandList,2+i))){//二次造词
  871. HaveAutoCandList=0;
  872. goto NoAddAutoMakeWord;//如果二次造词失败
  873. }
  874. }
  875. recTemp=recTemp->next;
  876. }
  877. if(k==1){
  878. recTemp=wubiDictCurrentRecord;
  879. while(_tcscmp(lpStr,recTemp->strCode)<=0 && recTemp!=wubiDictHead->next) 
  880. recTemp=recTemp->prev;
  881. while(_tcscmp(lpStr,recTemp->strCode)>=0 && recTemp!=wubiDictHead->prev){ 
  882. if(!strcmp(AutoWuBiWord,recTemp->strHZ)){
  883. HaveAutoCandList=0;
  884. goto NoAddAutoMakeWord;//二次清除
  885. }
  886. recTemp=recTemp->next;
  887. }
  888. }
  889. _tcscpy(YJMMessage,_T("(自动造词:)"));//提示
  890. _tcscpy(GETLPCANDSTR(lpCandList,2+lpCandList->dwCount),AutoWuBiWord);
  891. lpCandList->dwCount +=1;
  892. }
  893. NoAddAutoMakeWord:
  894. CodeHintTextBegin=lpCandList->dwCount;
  895. if(wConversionSet1 & C_SET1_CODE_HINT){
  896. for(i=0;i<lpCandList->dwCount;i++)
  897. _tcscpy(CodeHintText[i],"");
  898. recTemp=wubiDictCurrent;
  899. while(lpCandList->dwCount<CAND_PAGESIZE && recTemp != wubiDictHead->prev){
  900. _tcscpy(GETLPCANDSTR(lpCandList,2+lpCandList->dwCount),recTemp->strHZ);
  901. _tcscpy(CodeHintText[lpCandList->dwCount],recTemp->strCode);
  902. recTemp = recTemp->next;
  903. lpCandList->dwCount +=1;
  904. }
  905. }
  906. ComXResult=(int)CompareWBCodeX(lpStr,wubiDictCurrent->strCode);
  907. ComXResult-=MaxCompareWBCodeX-wStrLen;
  908. if(!HaveAutoCandList && wStrLen>2&& 
  909. wubiDictCurrent!=wubiDictHead->prev){
  910. if((lpCandList->dwCount ==1)&&
  911. ComXResult>0 &&
  912. (wConversionSet1 & C_SET1_AUTO_INPUT)){//单个选项自动上屏
  913. SpaceSelect(hIMC,wParam);
  914. goto yjmwubidisplay;
  915. }
  916. }
  917. }
  918. //以上接收键盘输入a-z
  919. //翻页功能
  920. else if( wParam == _T('=') || wParam == _T('>')) {//wParam == _T('.') || //与符号推字冲突
  921. //SelectForwardFromCand(hIMC,lpCandList);
  922. UINT i;
  923. if(wConversionSet1 & C_SET1_CODE_HINT)
  924. for(i=0;i<CAND_PAGESIZE && wubiDictCurrentRecord!=wubiDictHead->prev;i++){
  925. wubiDictCurrentRecord=wubiDictCurrentRecord->next;
  926. }
  927. else wubiDictCurrentRecord=wubiDictCurrent;
  928. wParam=*(lpStr+wStrLen-1);
  929. *(lpStr+wStrLen-1)=_T('');
  930. CodeForward=0;
  931. ImmUnlockIMCC(lpIMC->hCompStr);
  932. ImmUnlockIMC(hIMC);
  933. CharHandleWuBi(hIMC,wParam,0);
  934. }
  935. else if( wParam == _T('-') || wParam == _T('<')) {//wParam == _T(',') || 
  936. //SelectBackwardFromCand(hIMC,lpCandList);
  937. UINT i;
  938. for(i=0;i<CAND_PAGESIZE && wubiDictCurrentRecord!=wubiDictHead->next;i++){
  939. wubiDictCurrentRecord=wubiDictCurrentRecord->prev;
  940. }
  941. wParam=*(lpStr+wStrLen-1);
  942. *(lpStr+wStrLen-1)=_T('');
  943. CodeForward=0;
  944. ImmUnlockIMCC(lpIMC->hCompStr);
  945. ImmUnlockIMC(hIMC);
  946. CharHandleWuBi(hIMC,wParam,0);
  947. }
  948. //选择功能1234567890
  949. else if( wParam >= _T('0') && wParam <= _T('9') ){
  950. if( !IsCompStr(hIMC)) return FALSE;//如果首键是数字,放行。
  951. SelectCandFromCandlist(hIMC, wParam);
  952. }
  953. //选用第二候选词的方便键
  954. else if((wParam == _T(';')||(wConversionSet1 & C_SET1_FIRSTCODEPUNCT && wParam == _T('[')))&&lpCandList->dwCount >=2){
  955. SelectCandFromCandlist(hIMC, _T('2'));
  956. }
  957. //选用第三候选词的方便键
  958. else if((wParam == _T(''')||(wConversionSet1 & C_SET1_FIRSTCODEPUNCT && wParam == _T(']')))&&lpCandList->dwCount >=3){
  959. SelectCandFromCandlist(hIMC, _T('3'));
  960. }
  961. //符号推字上屏
  962. else if( wParam == _T('!')||wParam == _T('@')||wParam == _T('#')||wParam == _T('$')||
  963. wParam == _T('%')||wParam == _T('^')||wParam == _T('&')||wParam == _T('*')||
  964. wParam == _T('(')||wParam == _T(')')||wParam == _T(',')||wParam == _T('.')||
  965. wParam == _T(';')||wParam == _T(''')||wParam == _T('\')||wParam == _T('/')||
  966. wParam == _T(':')||wParam == _T('"')||wParam == _T('?')||
  967. wParam == _T('[')||wParam == _T(']')||wParam == _T('{')||wParam == _T('}')){
  968. PunctPushWordFlag=1;
  969. SelectCandFromCandlist( hIMC, _T('1'));
  970. PunctPushWordFlag=0;
  971. GeneratePunct(hIMC,wParam);
  972. return TRUE;
  973. }
  974. else {
  975. ImmUnlockIMCC(lpIMC->hCompStr);
  976. ImmUnlockIMCC(lpIMC->hCandInfo);
  977. ImmUnlockIMC(hIMC);
  978. return FALSE;
  979. }
  980. //显示
  981. yjmwubidisplay:
  982. lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  983. _tcscpy(lpStr1,lpStr);
  984. ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret=_tcslen(lpStr1);
  985. if(wConversionSet & CONVERSION_SET_WBSPEED) _tcscat(lpStr1,SpeedMessage);//显示提示YJMMessage
  986. _tcscat(lpStr1,YJMMessage);
  987. GnMsg.msg = WM_IME_COMPOSITION;
  988. GnMsg.wParam = 0;
  989. GnMsg.lParam = GCS_COMPSTR;
  990. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  991. //yjmwubiexit:
  992. ImmUnlockIMCC(lpIMC->hCompStr);
  993. ImmUnlockIMCC(lpIMC->hCandInfo);
  994. ImmUnlockIMC(hIMC);
  995. return TRUE;
  996. }
  997. UINT ReturnHaveAutoCandList(LPTSTR lpStr,LPTSTR lpNoStr)
  998. WORD i,AutoWuBiBeginNum;
  999. char TempAutoWubi[1024];
  1000. WordHistoryStrLen=_tcslen(WordHistoryStr);
  1001. for(i=4;i<=MAXAUTOWUBINUM && i<=WordHistoryStrLen;i+=2){
  1002. AutoWuBiBeginNum=WordHistoryStrLen-i;
  1003. if(*(HistoryTwoCodes+AutoWuBiBeginNum)==*lpStr){//首码相同
  1004. //双字词
  1005. if(*(HistoryTwoCodes+AutoWuBiBeginNum+1)==*(lpStr+1)&&
  1006. *(HistoryTwoCodes+AutoWuBiBeginNum+2)==*(lpStr+2)&&
  1007. *(HistoryTwoCodes+AutoWuBiBeginNum+3)==*(lpStr+3)){
  1008. _tcscpy(AutoWuBiCode,lpStr);
  1009. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1010. //取得两汉字串
  1011. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1012. TempAutoWubi[4]='';
  1013. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1014. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1015. return 1;
  1016. }
  1017. //多于三字词
  1018. if(i>=6){//二、三码相同
  1019. if(*(HistoryTwoCodes+AutoWuBiBeginNum+2)==*(lpStr+1)&&
  1020. *(HistoryTwoCodes+AutoWuBiBeginNum+4)==*(lpStr+2)){
  1021. //三字词
  1022. if(*(HistoryTwoCodes+AutoWuBiBeginNum+5)==*(lpStr+3)){
  1023. _tcscpy(AutoWuBiCode,lpStr);
  1024. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1025. //取得三汉字串
  1026. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1027. TempAutoWubi[6]='';
  1028. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1029. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1030. return 1;
  1031. }
  1032. //四字词
  1033. if(i>=8){
  1034. if(*(HistoryTwoCodes+AutoWuBiBeginNum+6)==*(lpStr+3)){
  1035. _tcscpy(AutoWuBiCode,lpStr);
  1036. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1037. //取得四汉字串
  1038. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1039. TempAutoWubi[8]='';
  1040. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1041. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1042. return 1;
  1043. }
  1044. }
  1045. //五字词
  1046. if(i>=10){
  1047. if(*(HistoryTwoCodes+AutoWuBiBeginNum+8)==*(lpStr+3)){
  1048. _tcscpy(AutoWuBiCode,lpStr);
  1049. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1050. //取得五汉字串
  1051. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1052. TempAutoWubi[10]='';
  1053. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1054. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1055. return 1;
  1056. }
  1057. }
  1058. //六字词
  1059. if(i>=12){
  1060. if(*(HistoryTwoCodes+AutoWuBiBeginNum+10)==*(lpStr+3)){
  1061. _tcscpy(AutoWuBiCode,lpStr);
  1062. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1063. //取得六汉字串
  1064. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1065. TempAutoWubi[12]='';
  1066. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1067. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1068. return 1;
  1069. }
  1070. }
  1071. //七字词
  1072. if(i>=14){
  1073. if(*(HistoryTwoCodes+AutoWuBiBeginNum+12)==*(lpStr+3)){
  1074. _tcscpy(AutoWuBiCode,lpStr);
  1075. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1076. //取得七汉字串
  1077. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1078. TempAutoWubi[14]='';
  1079. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1080. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1081. return 1;
  1082. }
  1083. }
  1084. //八字词
  1085. if(i>=16){
  1086. if(*(HistoryTwoCodes+AutoWuBiBeginNum+14)==*(lpStr+3)){
  1087. _tcscpy(AutoWuBiCode,lpStr);
  1088. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1089. //取得八汉字串
  1090. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1091. TempAutoWubi[16]='';
  1092. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1093. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1094. return 1;
  1095. }
  1096. }
  1097. }//二、三码相同
  1098. }
  1099. }//首码相同
  1100. }
  1101. return 0;
  1102. }
  1103. UINT ReturnHaveAutoCandListErbi(LPTSTR lpStr,LPTSTR lpNoStr)
  1104. WORD i,AutoWuBiBeginNum;
  1105. char TempAutoWubi[1024];
  1106. WordHistoryStrLen=_tcslen(WordHistoryStr);
  1107. for(i=4;i<=MAXAUTOWUBINUM && i<=WordHistoryStrLen;i+=2){
  1108. AutoWuBiBeginNum=WordHistoryStrLen-i;
  1109. if(*(HistoryTwoCodes+AutoWuBiBeginNum)==*lpStr){//首码相同
  1110. //二,三字词
  1111. if(*(HistoryTwoCodes+AutoWuBiBeginNum+1)==*(lpStr+1)&&
  1112.    *(HistoryTwoCodes+AutoWuBiBeginNum+2)==*(lpStr+2)){//次码三码相同
  1113. //二字词
  1114.    if(*(HistoryTwoCodes+AutoWuBiBeginNum+3)==*(lpStr+3)){//四码相同
  1115. _tcscpy(AutoWuBiCode,lpStr);
  1116. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1117. //取得两汉字串
  1118. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1119. TempAutoWubi[4]='';
  1120. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1121. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1122. return 1;
  1123. }
  1124. //三字词
  1125. if(i>=6){//四码相同
  1126. if(*(HistoryTwoCodes+AutoWuBiBeginNum+4)==*(lpStr+3)){
  1127. _tcscpy(AutoWuBiCode,lpStr);
  1128. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1129. //取得三汉字串
  1130. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1131. TempAutoWubi[6]='';
  1132. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1133. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1134. return 1;
  1135. }
  1136. }
  1137. }
  1138. //多于四字词
  1139. if(i>=8){//二、三码相同
  1140. if(*(HistoryTwoCodes+AutoWuBiBeginNum+2)==*(lpStr+1)&&
  1141.    *(HistoryTwoCodes+AutoWuBiBeginNum+4)==*(lpStr+2)){
  1142. //四字词
  1143. if(i>=8){
  1144. if(*(HistoryTwoCodes+AutoWuBiBeginNum+6)==*(lpStr+3)){
  1145. _tcscpy(AutoWuBiCode,lpStr);
  1146. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1147. //取得四汉字串
  1148. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1149. TempAutoWubi[8]='';
  1150. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1151. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1152. return 1;
  1153. }
  1154. }
  1155. //五字词
  1156. if(i>=10){
  1157. if(*(HistoryTwoCodes+AutoWuBiBeginNum+8)==*(lpStr+3)){
  1158. _tcscpy(AutoWuBiCode,lpStr);
  1159. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1160. //取得五汉字串
  1161. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1162. TempAutoWubi[10]='';
  1163. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1164. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1165. return 1;
  1166. }
  1167. }
  1168. //六字词
  1169. if(i>=12){
  1170. if(*(HistoryTwoCodes+AutoWuBiBeginNum+10)==*(lpStr+3)){
  1171. _tcscpy(AutoWuBiCode,lpStr);
  1172. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1173. //取得六汉字串
  1174. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1175. TempAutoWubi[12]='';
  1176. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1177. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1178. return 1;
  1179. }
  1180. }
  1181. //七字词
  1182. if(i>=14){
  1183. if(*(HistoryTwoCodes+AutoWuBiBeginNum+12)==*(lpStr+3)){
  1184. _tcscpy(AutoWuBiCode,lpStr);
  1185. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1186. //取得七汉字串
  1187. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1188. TempAutoWubi[14]='';
  1189. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1190. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1191. return 1;
  1192. }
  1193. }
  1194. //八字词
  1195. if(i>=16){
  1196. if(*(HistoryTwoCodes+AutoWuBiBeginNum+14)==*(lpStr+3)){
  1197. _tcscpy(AutoWuBiCode,lpStr);
  1198. _tcscpy(AutoWuBiCode1,AutoWuBiCode);
  1199. //取得八汉字串
  1200. _tcscpy(TempAutoWubi,WordHistoryStr+AutoWuBiBeginNum);
  1201. TempAutoWubi[16]='';
  1202. _tcscpy(AutoWuBiWord,TempAutoWubi);
  1203. if(_tcscmp(AutoWuBiWord,lpNoStr)!=0)
  1204. return 1;
  1205. }
  1206. }
  1207. }//二、三码相同
  1208. }
  1209. }//首码相同
  1210. }
  1211. return 0;
  1212. }
  1213. int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
  1214. {
  1215.     TCHAR   szBuffer [1024] ;
  1216.     va_list pArgList ;
  1217.     // The va_start macro (defined in STDARG.H) is usually equivalent to:
  1218.     // pArgList = (char *) &szFormat + sizeof (szFormat) ;
  1219.     va_start (pArgList, szFormat) ;
  1220.     // The last argument to wvsprintf points to the arguments
  1221.     _vsntprintf ( szBuffer, sizeof (szBuffer) / sizeof (TCHAR),szFormat, pArgList) ;
  1222.     // The va_end macro just zeroes out pArgList for no good reason
  1223.     va_end (pArgList) ;
  1224.     return MessageBox (NULL, szBuffer, szCaption, 0);
  1225. }