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

输入法编程

开发平台:

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. /**********************************************************************/
  8. /*                                                                    */
  9. /* IMEKeyupHandler()                                                  */
  10. /*                                                                    */
  11. /* A function which handles WM_IMEKEYUP                               */
  12. /*                                                                    */
  13. /**********************************************************************/
  14. BOOL IMEKeyupHandler(
  15. HIMC hIMC,
  16. WPARAM wParam,
  17. LPARAM lParam,
  18. LPBYTE lpbKeyState)
  19. {
  20.     return FALSE;
  21. }
  22. /**********************************************************************/
  23. /*                                                                    */
  24. /* IMEKeydownHandler()                                                */
  25. /*                                                                    */
  26. /* A function which handles WM_IMEKEYDOWN                             */
  27. /*                                                                    */
  28. /**********************************************************************/
  29. BOOL IMEKeydownHandler(
  30. HIMC hIMC,
  31. WPARAM wParam,
  32. LPARAM lParam,
  33. LPBYTE lpbKeyState)
  34. {
  35. if(HotKeyPressed){
  36. HotKeyPressed=0;
  37. return TRUE;
  38. }
  39. if(!HaveInitDictionary) return TRUE;
  40. if(wConversionMode == CONVERSION_MODE_WUBI||
  41. wConversionMode == CONVERSION_MODE_HISTORYREUSE)
  42. YJMIMEKeydownHandlerWubi( hIMC, wParam, lParam, lpbKeyState );
  43. else if(wConversionMode == CONVERSION_MODE_WUBIATTACHLIB)
  44. YJMIMEKeydownHandlerWbAtt( hIMC, wParam, lParam, lpbKeyState );
  45. else if(wConversionMode == CONVERSION_MODE_ATTACHLIB||
  46. wConversionMode == CONVERSION_MODE_TEMPATTACHLIB)
  47. YJMIMEKeydownHandlerAttachLib( hIMC, wParam, lParam, lpbKeyState );
  48. else
  49. YJMIMEKeydownHandler( hIMC, wParam, lParam, lpbKeyState );
  50.     return TRUE;
  51. }
  52. BOOL YJMIMEKeydownHandlerWbAtt(
  53. HIMC hIMC,
  54. WPARAM wParam,
  55. LPARAM lParam,
  56. LPBYTE lpbKeyState)
  57. {
  58.     WORD wVKey;
  59.     if( wVKey=(wParam & 0x00FF)){
  60. if( !KeydownHandlerWbAtt( hIMC, wVKey, lParam, lpbKeyState ) ) {
  61. #ifdef _UNICODE
  62. CharHandlerWbAtt( hIMC,  HIWORD(wParam), lParam );
  63. #else
  64. CharHandlerWbAtt( hIMC,(WORD)((BYTE)HIBYTE(wParam)),lParam );
  65. #endif
  66. }
  67.     }
  68.     return TRUE;
  69. }
  70. BOOL YJMIMEKeydownHandlerAttachLib(
  71. HIMC hIMC,
  72. WPARAM wParam,
  73. LPARAM lParam,
  74. LPBYTE lpbKeyState)
  75. {
  76.     WORD wVKey;
  77.     if( wVKey=(wParam & 0x00FF)){
  78. if( !KeydownHandlerAttachLib( hIMC, wVKey, lParam, lpbKeyState ) ) {
  79. #ifdef _UNICODE
  80. CharHandlerAttachLib( hIMC,  HIWORD(wParam), lParam );
  81. #else
  82. CharHandlerAttachLib( hIMC,(WORD)((BYTE)HIBYTE(wParam)),lParam );
  83. #endif
  84. }
  85.     }
  86.     return TRUE;
  87. }
  88. BOOL YJMIMEKeydownHandlerWubi(
  89. HIMC hIMC,
  90. WPARAM wParam,
  91. LPARAM lParam,
  92. LPBYTE lpbKeyState)
  93. {
  94.     WORD wVKey;
  95.     if( wVKey=(wParam & 0x00FF)){
  96. if( !KeydownHandlerWubi( hIMC, wVKey, lParam, lpbKeyState ) ) {
  97. #ifdef _UNICODE
  98. CharHandlerWubi( hIMC,  HIWORD(wParam), lParam );
  99. #else
  100. CharHandlerWubi( hIMC,(WORD)((BYTE)HIBYTE(wParam)),lParam );
  101. #endif
  102. }
  103.     }
  104.     return TRUE;
  105. }
  106. BOOL YJMIMEKeydownHandler(
  107. HIMC hIMC,
  108. WPARAM wParam,
  109. LPARAM lParam,
  110. LPBYTE lpbKeyState)
  111. {
  112.     WORD wVKey;
  113.     if( wVKey=(wParam & 0x00FF)){
  114. if( !KeydownHandler( hIMC, wVKey, lParam, lpbKeyState ) ) {
  115. #ifdef _UNICODE
  116. CharHandler( hIMC,  HIWORD(wParam), lParam );
  117. #else
  118. CharHandler( hIMC,(WORD)((BYTE)HIBYTE(wParam)),lParam );
  119. #endif
  120. }
  121.     }
  122.     return TRUE;
  123. }
  124. /**********************************************************************/
  125. /*                                                                    */
  126. /* KeydownHandler()                                                */
  127. /*                                                                    */
  128. /* WM_KEYDOWN handler for dictionary routine                          */
  129. /*                                                                    */
  130. /* wParam                                                             */
  131. /* virtual key                                                        */
  132. /*                                                                    */
  133. /* lParam                                                             */
  134. /* differ depending on wParam                                         */
  135. /*                                                                    */
  136. /**********************************************************************/
  137. BOOL KeydownHandlerAttachLib(
  138. HIMC hIMC,
  139. WORD wParam,
  140. LONG lParam,
  141. LPBYTE lpbKeyState)
  142. {
  143. LPINPUTCONTEXT lpIMC;
  144. LPCOMPOSITIONSTRING lpCompStr;
  145. GENEMSG GnMsg;
  146. SHORT *lpwEditCaret;
  147. SHORT wUnConvPos;
  148. LPTSTR lpStr;
  149. TCHAR YjmPressKey[2];
  150. YjmPressKey[0]=(char)wParam;
  151. YjmPressKey[1]='';
  152. lpIMC = ImmLockIMC(hIMC);
  153. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  154. lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
  155. wUnConvPos = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos;
  156. lpStr = GETLPCOMPSTR(lpCompStr);
  157.     switch( wParam ) 
  158.     {
  159.         case VK_ESCAPE:
  160.             MakeResultString(hIMC,FALSE); //清空所有字符
  161.             break;
  162. case VK_RETURN: // 清空所有字符
  163. MakeResultString(hIMC,FALSE);
  164. break;
  165.         //俞建明添加
  166.         case VK_BACK://退格键
  167.             DeleteCharBackward(hIMC,wParam); 
  168.             break;
  169.         case VK_DELETE://delete键?
  170. //DeleteCharForward(hIMC,wParam);
  171. break;
  172. case VK_HOME://home键
  173. if( *lpwEditCaret > 0 ) {
  174. if( wUnConvPos ){
  175. *lpwEditCaret = wUnConvPos;
  176. }
  177. else {
  178. *lpwEditCaret = 0;
  179. }
  180. GnMsg.msg = WM_IME_NOTIFY;
  181. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  182. GnMsg.lParam = 0;
  183. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  184. }
  185. else MessageBeep(0xFFFFFFFF );
  186. break;
  187. case VK_END://end键
  188. if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
  189. *lpwEditCaret = (SHORT)_tcslen(lpStr);
  190. GnMsg.msg = WM_IME_NOTIFY;
  191. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  192. GnMsg.lParam = 0;
  193. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  194. }
  195. else MessageBeep(0xFFFFFFFF );
  196. break;
  197. case VK_UP:
  198. case VK_LEFT://左向键
  199. if( *lpwEditCaret > 0 ) {
  200. if( *lpwEditCaret == wUnConvPos) AddChar(hIMC,wParam,EDIT_BACK);
  201. else {
  202. *lpwEditCaret -= 1;
  203. GnMsg.msg = WM_IME_NOTIFY;
  204. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  205. GnMsg.lParam = 0;
  206. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  207. }
  208. }
  209. else MessageBeep(0xFFFFFFFF );
  210. break;
  211. case VK_DOWN:
  212. case VK_RIGHT://右向键
  213. if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
  214. *lpwEditCaret += 1;
  215. GnMsg.msg = WM_IME_NOTIFY;
  216. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  217. GnMsg.lParam = 0;
  218. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  219. }
  220. else MessageBeep(0xFFFFFFFF );
  221. break;
  222.         case VK_SPACE://空格键
  223. //SpaceSelect(hIMC,wParam); //或者
  224. SelectCandFromCandlist( hIMC, _T('1'));
  225. /*
  226. GnMsg.msg = WM_IME_COMPOSITION;
  227. GnMsg.wParam = 0;
  228. GnMsg.lParam = GCS_COMPSTR;
  229. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  230. */
  231.             break;
  232.         default:
  233.             break;
  234.     }
  235. ImmUnlockIMCC(lpIMC->hCompStr);
  236. ImmUnlockIMC(hIMC);
  237.     if (( VK_0 <= wParam && VK_9 >= wParam ) ||
  238.         ( VK_A <= wParam && VK_Z >= wParam ) ||
  239. ( VK_NUMPAD0 <= wParam && VK_NUMPAD9 >= wParam ) ||
  240.         ( VK_OEM_1 <= wParam && VK_OEM_9 >= wParam ) ||
  241.         ( VK_MULTIPLY <= wParam && VK_DIVIDE >= wParam )||
  242. (_tcsstr(AttUsedcodes,YjmPressKey)))
  243.     {
  244.         return( FALSE );//以上按键被许可继续执行CharHandlerAttachLib
  245.     }
  246.     else
  247.         return( TRUE );//其它按键被忽略
  248. }
  249. BOOL KeydownHandlerWubi(
  250. HIMC hIMC,
  251. WORD wParam,
  252. LONG lParam,
  253. LPBYTE lpbKeyState)
  254. {
  255. LPINPUTCONTEXT lpIMC;
  256. LPCOMPOSITIONSTRING lpCompStr;
  257. GENEMSG GnMsg;
  258. SHORT *lpwEditCaret;
  259. SHORT wUnConvPos;
  260. LPTSTR lpStr;
  261. TCHAR YjmPressKey[2];
  262. YjmPressKey[0]=(char)wParam;
  263. YjmPressKey[1]='';
  264. lpIMC = ImmLockIMC(hIMC);
  265. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  266. lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
  267. wUnConvPos = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos;
  268. lpStr = GETLPCOMPSTR(lpCompStr);
  269.     switch( wParam ) 
  270.     {
  271.         case VK_ESCAPE:
  272. MakeResultString(hIMC,FALSE); //清空所有字符
  273.             break;
  274. case VK_RETURN:
  275. if(wConversionSet1 & C_SET1_RETURN_ENGLISH){
  276. wPreConversionMode=wConversionMode;
  277. fTempState=1;
  278. wConversionMode=CONVERSION_MODE_ENGLISH;
  279. MakeResultString(hIMC,TRUE);
  280. //TurnIntoPinyinMode(hIMC);
  281. }
  282. else 
  283.             MakeResultString(hIMC,FALSE); //清空所有字符
  284. break;
  285.         case VK_BACK:
  286.             DeleteCharBackward(hIMC,wParam);//退格键 
  287.             break;
  288.         case VK_DELETE:
  289. //DeleteCharForward(hIMC,wParam);//delete键?
  290. break;
  291. case VK_HOME://home键
  292. if( *lpwEditCaret > 0 ) {
  293. if( wUnConvPos ){
  294. *lpwEditCaret = wUnConvPos;
  295. }
  296. else {
  297. *lpwEditCaret = 0;
  298. }
  299. GnMsg.msg = WM_IME_NOTIFY;
  300. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  301. GnMsg.lParam = 0;
  302. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  303. }
  304. else MessageBeep(0xFFFFFFFF );
  305. break;
  306. case VK_END://end键
  307. if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
  308. *lpwEditCaret = (SHORT)_tcslen(lpStr);
  309. GnMsg.msg = WM_IME_NOTIFY;
  310. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  311. GnMsg.lParam = 0;
  312. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  313. }
  314. else MessageBeep(0xFFFFFFFF );
  315. break;
  316. case VK_UP:
  317. case VK_LEFT://左向键
  318. if( *lpwEditCaret > 0 ) {
  319. if( *lpwEditCaret == wUnConvPos) AddChar(hIMC,wParam,EDIT_BACK);
  320. else {
  321. *lpwEditCaret -= 1;
  322. GnMsg.msg = WM_IME_NOTIFY;
  323. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  324. GnMsg.lParam = 0;
  325. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  326. }
  327. }
  328. else MessageBeep(0xFFFFFFFF );
  329. break;
  330.         case VK_DOWN:
  331. case VK_RIGHT://右向键
  332. if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
  333. *lpwEditCaret += 1;
  334. GnMsg.msg = WM_IME_NOTIFY;
  335. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  336. GnMsg.lParam = 0;
  337. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  338. }
  339. else MessageBeep(0xFFFFFFFF );
  340. break;
  341.         case VK_SPACE://空格键
  342. _tcscpy(szPreResultCode,lpStr);
  343. SpaceSelect(hIMC,wParam);
  344. GnMsg.msg = WM_IME_COMPOSITION;
  345. GnMsg.wParam = 0;
  346. GnMsg.lParam = GCS_COMPSTR;
  347. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  348.             break;
  349.         default:
  350.             break;
  351.     }
  352. ImmUnlockIMCC(lpIMC->hCompStr);
  353. ImmUnlockIMC(hIMC);
  354.     if (( VK_0 <= wParam && VK_9 >= wParam ) ||
  355.         ( VK_A <= wParam && VK_Z >= wParam ) ||
  356. ( VK_NUMPAD0 <= wParam && VK_NUMPAD9 >= wParam ) ||
  357.         ( VK_OEM_1 <= wParam && VK_OEM_9 >= wParam ) ||
  358.         ( VK_MULTIPLY <= wParam && VK_DIVIDE >= wParam )||
  359. (_tcsstr(WbUsedcodes,YjmPressKey)))
  360.     {
  361.         return( FALSE );//以上按键被许可继续执行CharHandlerWubi
  362.     }
  363.     else
  364.         return( TRUE );//其它按键被忽略
  365. }
  366. BOOL KeydownHandlerWbAtt(
  367. HIMC hIMC,
  368. WORD wParam,
  369. LONG lParam,
  370. LPBYTE lpbKeyState)
  371. {
  372. LPINPUTCONTEXT lpIMC;
  373. LPCOMPOSITIONSTRING lpCompStr;
  374. GENEMSG GnMsg;
  375. SHORT *lpwEditCaret;
  376. SHORT wUnConvPos;
  377. LPTSTR lpStr;
  378. TCHAR YjmPressKey[2];
  379. YjmPressKey[0]=(char)wParam;
  380. YjmPressKey[1]='';
  381. lpIMC = ImmLockIMC(hIMC);
  382. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  383. lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
  384. wUnConvPos = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos;
  385. lpStr = GETLPCOMPSTR(lpCompStr);
  386.     switch( wParam ) 
  387.     {
  388.         case VK_ESCAPE:
  389. MakeResultString(hIMC,FALSE); //清空所有字符
  390.             break;
  391. case VK_RETURN:
  392.             MakeResultString(hIMC,FALSE); //清空所有字符
  393. break;
  394.         case VK_BACK:
  395.             DeleteCharBackward(hIMC,wParam);//退格键 
  396.             break;
  397.         case VK_DELETE:
  398. //DeleteCharForward(hIMC,wParam);//delete键?
  399. break;
  400. case VK_HOME://home键
  401. if( *lpwEditCaret > 0 ) {
  402. if( wUnConvPos ){
  403. *lpwEditCaret = wUnConvPos;
  404. }
  405. else {
  406. *lpwEditCaret = 0;
  407. }
  408. GnMsg.msg = WM_IME_NOTIFY;
  409. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  410. GnMsg.lParam = 0;
  411. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  412. }
  413. else MessageBeep(0xFFFFFFFF );
  414. break;
  415. case VK_END://end键
  416. if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
  417. *lpwEditCaret = (SHORT)_tcslen(lpStr);
  418. GnMsg.msg = WM_IME_NOTIFY;
  419. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  420. GnMsg.lParam = 0;
  421. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  422. }
  423. else MessageBeep(0xFFFFFFFF );
  424. break;
  425. case VK_UP:
  426. case VK_LEFT://左向键
  427. if( *lpwEditCaret > 0 ) {
  428. if( *lpwEditCaret == wUnConvPos) AddChar(hIMC,wParam,EDIT_BACK);
  429. else {
  430. *lpwEditCaret -= 1;
  431. GnMsg.msg = WM_IME_NOTIFY;
  432. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  433. GnMsg.lParam = 0;
  434. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  435. }
  436. }
  437. else MessageBeep(0xFFFFFFFF );
  438. break;
  439.         case VK_DOWN:
  440. case VK_RIGHT://右向键
  441. if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
  442. *lpwEditCaret += 1;
  443. GnMsg.msg = WM_IME_NOTIFY;
  444. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  445. GnMsg.lParam = 0;
  446. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  447. }
  448. else MessageBeep(0xFFFFFFFF );
  449. break;
  450.         case VK_SPACE://空格键
  451. _tcscpy(szPreResultCode,lpStr);
  452. SpaceSelect(hIMC,wParam);
  453. /*
  454. GnMsg.msg = WM_IME_COMPOSITION;
  455. GnMsg.wParam = 0;
  456. GnMsg.lParam = GCS_COMPSTR;
  457. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  458. */
  459.             break;
  460.         default:
  461.             break;
  462.     }
  463. ImmUnlockIMCC(lpIMC->hCompStr);
  464. ImmUnlockIMC(hIMC);
  465.     if (( VK_0 <= wParam && VK_9 >= wParam ) ||
  466.         ( VK_A <= wParam && VK_Z >= wParam ) ||
  467. ( VK_NUMPAD0 <= wParam && VK_NUMPAD9 >= wParam ) ||
  468.         ( VK_OEM_1 <= wParam && VK_OEM_9 >= wParam ) ||
  469.         ( VK_MULTIPLY <= wParam && VK_DIVIDE >= wParam )||
  470. (_tcsstr(WbUsedcodes,YjmPressKey))||
  471. (_tcsstr(AttUsedcodes,YjmPressKey)))
  472.     {
  473.         return( FALSE );//以上按键被许可继续执行CharHandlerWubi
  474.     }
  475.     else
  476.         return( TRUE );//其它按键被忽略
  477. }
  478. BOOL KeydownHandler(
  479. HIMC hIMC,
  480. WORD wParam,
  481. LONG lParam,
  482. LPBYTE lpbKeyState)
  483. {
  484. LPINPUTCONTEXT lpIMC;
  485. LPCOMPOSITIONSTRING lpCompStr;
  486. GENEMSG GnMsg;
  487. SHORT *lpwEditCaret;
  488. SHORT wUnConvPos;
  489. LPTSTR lpStr;
  490. /*/
  491. TCHAR szStr[100];
  492. _stprintf(szStr,"wParam:  %d",wParam);
  493. MessageBox(NULL,szStr,_T("提示"),MB_OK);
  494. return( TRUE );
  495. /*/
  496. lpIMC = ImmLockIMC(hIMC);
  497. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  498. lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
  499. wUnConvPos = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos;
  500. lpStr = GETLPCOMPSTR(lpCompStr);
  501.     switch( wParam ) 
  502.     {//五种需要稳定状态:拼音,五笔,区位,自定义,时间
  503. //三种不需要稳定状态:以词定字,五笔半自动加码,五笔手工加码
  504.         case VK_ESCAPE:
  505. if(wConversionMode == CONVERSION_MODE_WUBIADD||wConversionMode == CONVERSION_MODE_WUBIADDSELF)
  506. wConversionMode = CONVERSION_MODE_WUBI;
  507. //if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR)
  508. // wConversionMode =wPreConversionMode;
  509.             MakeResultString(hIMC,FALSE); //清空所有字符
  510.             break;
  511.         //俞建明添加
  512. case VK_RETURN: //以词定字 
  513. {
  514. LPCANDIDATEINFO lpCandInfo;
  515. LPCANDIDATELIST lpCandList;
  516. LPTSTR lpPaintStr;
  517. /*if(wConversionMode == CONVERSION_MODE_WUBI){
  518. MakeResultString(hIMC,FALSE);
  519. break;
  520. }
  521. else */
  522. if( wConversionMode == CONVERSION_MODE_WUBIADD) {
  523. if((wConversionSet1 & C_SET1_ERBIMAKEWORD)?
  524. AutoGetWordErbiCode (AutoWuBiWord,1):
  525. AutoGetWordWubiCode (AutoWuBiWord,1)) {
  526. /*LPTSTR lpStr1;
  527. _tcscpy(lpStr,AutoWuBiCode);
  528. _tcscpy(YJMMessage,_T("(编码结果):"));
  529. lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  530. _tcscpy(lpStr1,WUBIMODELADD);//显示标志
  531. _tcscat(lpStr1,YJMMessage);//显示提示
  532. _tcscat(lpStr1,lpStr);
  533. GnMsg.msg = WM_IME_COMPOSITION;
  534. GnMsg.wParam = 0;
  535. GnMsg.lParam = GCS_COMPSTR;
  536. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);*/
  537. MessageBox(NULL,AutoWuBiCode,AutoWuBiWord,MB_OK);
  538. wConversionMode = CONVERSION_MODE_WUBI;
  539. MakeResultString(hIMC,FALSE);
  540. break;
  541. }
  542. }
  543. else if( wConversionMode == CONVERSION_MODE_WUBIADDSELF) {
  544. if(InsertPhrase (lpStr, AutoWuBiWord))
  545. MessageBox(NULL,lpStr,"手工造词失败",MB_OK);
  546. MakeResultString(hIMC,FALSE);
  547. wConversionMode = CONVERSION_MODE_WUBI;
  548. break;
  549. }
  550. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  551. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  552. if( lpCandList->dwCount ){
  553. //从其它模式进入,先保存一下原先模式参数
  554. if(wConversionMode != CONVERSION_MODE_PHRASETOCHAR)
  555. wPreConversionMode =wConversionMode;
  556. //
  557. wConversionMode = CONVERSION_MODE_PHRASETOCHAR;
  558. //
  559. lpPaintStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  560. _tcscpy(lpPaintStr,PHTOCHMODEL);
  561. GnMsg.msg = WM_IME_COMPOSITION;
  562. GnMsg.wParam = 0;
  563. GnMsg.lParam = GCS_COMPSTR;
  564. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  565. }
  566. ImmUnlockIMCC(lpIMC->hCandInfo);
  567. break;
  568. }
  569.         case VK_BACK://退格键
  570. if( wConversionMode == CONVERSION_MODE_WUBIADDSELF) {
  571. LPTSTR lpStr1;
  572. WORD wStrLen = _tcslen(lpStr);
  573. if(wStrLen>=1) *(lpStr + wStrLen-1) =  _T('');
  574. lpStr1 = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  575. _tcscpy(lpStr1,WUBIMODELADDSELF);//显示标志
  576. _tcscat(lpStr1,YJMMessage);//显示提示
  577. _tcscat(lpStr1,lpStr);
  578. GnMsg.msg = WM_IME_COMPOSITION;
  579. GnMsg.wParam = 0;
  580. GnMsg.lParam = GCS_COMPSTR;
  581. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  582. break;
  583. }
  584.             DeleteCharBackward(hIMC,wParam); 
  585.             break;
  586.         case VK_DELETE://delete键
  587. DeleteCharForward(hIMC,wParam);
  588. break;
  589. case VK_HOME://home键
  590. if( *lpwEditCaret > 0 ) {
  591. if( wUnConvPos ){
  592. *lpwEditCaret = wUnConvPos;
  593. }
  594. else {
  595. *lpwEditCaret = 0;
  596. }
  597. GnMsg.msg = WM_IME_NOTIFY;
  598. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  599. GnMsg.lParam = 0;
  600. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  601. }
  602. else MessageBeep(0xFFFFFFFF );
  603. break;
  604. case VK_END://end键
  605. if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
  606. *lpwEditCaret = (SHORT)_tcslen(lpStr);
  607. GnMsg.msg = WM_IME_NOTIFY;
  608. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  609. GnMsg.lParam = 0;
  610. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  611. }
  612. else MessageBeep(0xFFFFFFFF );
  613. break;
  614.         case VK_UP:
  615. case VK_LEFT://左向键
  616. if( *lpwEditCaret > 0 ) {
  617. if( *lpwEditCaret == wUnConvPos) AddChar(hIMC,wParam,EDIT_BACK);
  618. else {
  619. *lpwEditCaret -= 1;
  620. GnMsg.msg = WM_IME_NOTIFY;
  621. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  622. GnMsg.lParam = 0;
  623. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  624. }
  625. }
  626. else MessageBeep(0xFFFFFFFF );
  627. break;
  628.         case VK_DOWN:
  629. case VK_RIGHT://右向键
  630. if( *lpwEditCaret < (SHORT)_tcslen(lpStr) ) {
  631. *lpwEditCaret += 1;
  632. GnMsg.msg = WM_IME_NOTIFY;
  633. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  634. GnMsg.lParam = 0;
  635. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  636. }
  637. else MessageBeep(0xFFFFFFFF );
  638. break;
  639.         case VK_SPACE://空格键
  640. SpaceSelect(hIMC,wParam);
  641. /*
  642. GnMsg.msg = WM_IME_COMPOSITION;
  643. GnMsg.wParam = 0;
  644. GnMsg.lParam = GCS_COMPSTR;
  645. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  646. */
  647.             break;
  648.         default:
  649.             break;
  650.     }
  651. ImmUnlockIMCC(lpIMC->hCompStr);
  652. ImmUnlockIMC(hIMC);
  653. //DebugLog(2,(DebugLogFile,"入口wParam: %d        ",wParam));
  654.     if (( VK_0 <= wParam && VK_9 >= wParam ) ||
  655.         ( VK_A <= wParam && VK_Z >= wParam ) ||
  656. ( VK_NUMPAD0 <= wParam && VK_NUMPAD9 >= wParam ) ||
  657.         ( VK_OEM_1 <= wParam && VK_OEM_9 >= wParam ) ||
  658.         ( VK_MULTIPLY <= wParam && VK_DIVIDE >= wParam ))
  659.     {
  660.         return( FALSE );//以上按键被许可继续执行CharHandler
  661.     }
  662.     else
  663.         return( TRUE );//其它按键被忽略
  664. }
  665. BOOL CharHandlerAttachLib(
  666. HIMC hIMC,
  667. WORD wParam,
  668. LONG lParam)
  669. {
  670.     LPINPUTCONTEXT lpIMC;
  671.     LPCOMPOSITIONSTRING lpCompStr;
  672. LPCANDIDATEINFO lpCandInfo;
  673.     DWORD dwStrLen;
  674.     GENEMSG GnMsg;
  675. TCHAR YjmPressKey[2];
  676. YjmPressKey[0]=(char)wParam;
  677. YjmPressKey[1]='';
  678.     lpIMC = ImmLockIMC(hIMC);
  679. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  680.     dwStrLen = lpCompStr->dwCompStrLen;
  681.     if (!dwStrLen)//首键进入此
  682.     {
  683. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  684. ClearCompStr(lpCompStr);
  685. ClearCandidate(lpCandInfo);
  686. ImmUnlockIMCC(lpIMC->hCandInfo);
  687. //
  688.         GnMsg.msg = WM_IME_STARTCOMPOSITION;
  689.         GnMsg.wParam = 0;
  690.         GnMsg.lParam = 0;
  691.         GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  692. if( (wParam < _T('a') || wParam > _T('z')) &&
  693. (wParam < _T('A') || wParam > _T('Z')) &&
  694. (wParam < _T('0') || wParam > _T('9')) &&
  695. (!_tcsstr(AttUsedcodes,YjmPressKey))){
  696. ImmUnlockIMCC(lpIMC->hCompStr);
  697.     ImmUnlockIMC(hIMC);
  698. return GeneratePunct(hIMC,wParam);//首键非数字字母键,止步于此。
  699. }
  700. }
  701. if( CharHandleAttachLib(hIMC,wParam,lParam)) goto my_exit;
  702. //当返回为1时,跳过如下半角符号转化为全角的部分
  703. FullHalfShapeHandler(hIMC,lpCompStr,wParam);
  704. my_exit:
  705. ImmUnlockIMCC(lpIMC->hCompStr);
  706.     ImmUnlockIMC(hIMC);
  707. return TRUE;
  708. }
  709. void FullHalfShapeHandler(HIMC hIMC,LPCOMPOSITIONSTRING lpCompStr,WPARAM wParam)
  710. {
  711. LPTSTR lpConvStr;
  712. if( wParam >= _T('!') && wParam <= _T('~') && lpCompStr->dwCompStrLen == 0) {
  713. lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
  714. if(wConversionSet & CONVERSION_SET_FULLSHAPE) {
  715. BYTE bChar[4];
  716. bChar[0] = 0xA3;
  717. bChar[1] = (BYTE)wParam + 0x80;
  718. bChar[2] = 0;
  719. bChar[3] = 0;
  720. memcpy((LPBYTE)lpConvStr,bChar,4);
  721. }
  722. else{
  723. *lpConvStr = (TCHAR)wParam;
  724. *(lpConvStr+1) = _T('');
  725. }
  726. MakeResultString(hIMC,TRUE);
  727. }
  728. }
  729. BOOL CharHandlerWubi(
  730. HIMC hIMC,
  731. WORD wParam,
  732. LONG lParam)
  733. {
  734.     LPINPUTCONTEXT lpIMC;
  735.     LPCOMPOSITIONSTRING lpCompStr;
  736. LPCANDIDATEINFO lpCandInfo;
  737.     DWORD dwStrLen;
  738.     GENEMSG GnMsg;
  739.   LPTSTR lpStr;
  740. TCHAR YjmPressKey[2];
  741. YjmPressKey[0]=(char)wParam;
  742. YjmPressKey[1]='';
  743.     lpIMC = ImmLockIMC(hIMC);
  744. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  745.     dwStrLen = lpCompStr->dwCompStrLen;
  746.     if (!dwStrLen)//首键进入此
  747.     {
  748. //历史复用
  749. if((wConversionSet & CONVERSION_SET_HISTORYREUSE) &&
  750. (wConversionMode == CONVERSION_MODE_WUBI) && 
  751. (wParam == _T('\'))&&_tcslen(YJMMessage)>1){
  752. wPreConversionMode=wConversionMode;
  753. fTempState=1;
  754. wConversionMode=CONVERSION_MODE_HISTORYREUSE;
  755. lpCompStr->dwCompStrLen=1;
  756. lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  757. _tcscpy(lpStr,_T("历史复用(0-9):"));
  758. GnMsg.msg = WM_IME_COMPOSITION;
  759. GnMsg.wParam = 0;
  760. GnMsg.lParam = GCS_COMPSTR;
  761. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  762. goto my_exit;
  763. }
  764. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  765. ClearCompStr(lpCompStr);
  766. ClearCandidate(lpCandInfo);
  767. ImmUnlockIMCC(lpIMC->hCandInfo);
  768.         GnMsg.msg = WM_IME_STARTCOMPOSITION;
  769.         GnMsg.wParam = 0;
  770.         GnMsg.lParam = 0;
  771.         GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  772. //转入临时拼音状态
  773. if(wConversionSet & CONVERSION_SET_TEMPPINYIN && wParam == _T('/')){
  774. wPreConversionMode=wConversionMode;
  775. fTempState=1;
  776. TurnIntoPinyinMode(hIMC);
  777. wConversionMode=CONVERSION_MODE_TEMPPINYIN;
  778. goto my_exit;
  779. }
  780. //转入附加词库状态
  781. else if((wConversionSet & CONVERSION_SET_ATTACHLIB) && (wParam == _T('/'))){
  782. wPreConversionMode=wConversionMode;
  783. fTempState=1;
  784. TurnIntoAttachLibMode(hIMC);
  785. wConversionMode=CONVERSION_MODE_TEMPATTACHLIB;
  786. goto my_exit;
  787. }
  788. else if((wParam < _T('a') || wParam > _T('z')) &&
  789. (wParam < _T('A') || wParam > _T('Z')) &&
  790. (wParam < _T('0') || wParam > _T('9')) &&
  791. (wConversionSet1 & C_SET1_FIRSTCODEPUNCT?1:!_tcsstr(WbUsedcodes,YjmPressKey))){
  792. ImmUnlockIMCC(lpIMC->hCompStr);
  793.     ImmUnlockIMC(hIMC);
  794. return GeneratePunct(hIMC,wParam);//首键非数字字母键,止步于此。
  795. }
  796. }
  797. //if(wConversionMode == CONVERSION_MODE_WUBIATTACHLIB)
  798. //if( CharHandleWuBiAttachLib(hIMC,wParam,lParam) ) goto my_exit;
  799. if(wConversionMode == CONVERSION_MODE_WUBI){
  800. //if(wConversionSet1 & C_SET1_WUBI_MODE2){
  801. //if(CharHandleWuBi2(hIMC,wParam,lParam)) goto my_exit;
  802. //}
  803. //else 
  804. if(CharHandleWuBi(hIMC,wParam,lParam) ) goto my_exit;
  805. }
  806. if(wConversionMode == CONVERSION_MODE_HISTORYREUSE) 
  807. if( CharHandleHistoryReuse(hIMC,wParam,lParam) ) goto my_exit;
  808. //当返回为1时,跳过如下半角符号转化为全角的部分
  809. FullHalfShapeHandler(hIMC,lpCompStr,wParam);
  810. my_exit:
  811. ImmUnlockIMCC(lpIMC->hCompStr);
  812.     ImmUnlockIMC(hIMC);
  813. return TRUE;
  814. }
  815. BOOL CharHandlerWbAtt(
  816. HIMC hIMC,
  817. WORD wParam,
  818. LONG lParam)
  819. {
  820.     LPINPUTCONTEXT lpIMC;
  821.     LPCOMPOSITIONSTRING lpCompStr;
  822. LPCANDIDATEINFO lpCandInfo;
  823.     DWORD dwStrLen;
  824.     GENEMSG GnMsg;
  825.   LPTSTR lpStr;
  826. TCHAR YjmPressKey[2];
  827. YjmPressKey[0]=(char)wParam;
  828. YjmPressKey[1]='';
  829.     lpIMC = ImmLockIMC(hIMC);
  830. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  831.     dwStrLen = lpCompStr->dwCompStrLen;
  832.     if (!dwStrLen)//首键进入此
  833.     {
  834. //历史复用
  835. if((wConversionSet & CONVERSION_SET_HISTORYREUSE) &&
  836. (wConversionMode == CONVERSION_MODE_WUBI) && 
  837. (wParam == _T('\'))&&_tcslen(YJMMessage)>1){
  838. wPreConversionMode=wConversionMode;
  839. fTempState=1;
  840. wConversionMode=CONVERSION_MODE_HISTORYREUSE;
  841. lpCompStr->dwCompStrLen=1;
  842. lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  843. _tcscpy(lpStr,_T("历史复用(0-9):"));
  844. GnMsg.msg = WM_IME_COMPOSITION;
  845. GnMsg.wParam = 0;
  846. GnMsg.lParam = GCS_COMPSTR;
  847. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  848. goto my_exit;
  849. }
  850. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  851. ClearCompStr(lpCompStr);
  852. ClearCandidate(lpCandInfo);
  853. ImmUnlockIMCC(lpIMC->hCandInfo);
  854.         GnMsg.msg = WM_IME_STARTCOMPOSITION;
  855.         GnMsg.wParam = 0;
  856.         GnMsg.lParam = 0;
  857.         GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  858. //转入临时拼音状态
  859. if(wConversionSet & CONVERSION_SET_TEMPPINYIN && wParam == _T('/')){
  860. wPreConversionMode=wConversionMode;
  861. fTempState=1;
  862. TurnIntoPinyinMode(hIMC);
  863. wConversionMode=CONVERSION_MODE_TEMPPINYIN;
  864. goto my_exit;
  865. }
  866. //转入附加词库状态
  867. else if((wConversionSet & CONVERSION_SET_ATTACHLIB) && (wParam == _T('/'))){
  868. wPreConversionMode=wConversionMode;
  869. fTempState=1;
  870. TurnIntoAttachLibMode(hIMC);
  871. wConversionMode=CONVERSION_MODE_TEMPATTACHLIB;
  872. goto my_exit;
  873. }
  874. else if((wParam < _T('a') || wParam > _T('z')) &&
  875. (wParam < _T('A') || wParam > _T('Z')) &&
  876. (wParam < _T('0') || wParam > _T('9')) &&
  877. (!_tcsstr(WbUsedcodes,YjmPressKey))&&
  878. (!_tcsstr(AttUsedcodes,YjmPressKey))){
  879. ImmUnlockIMCC(lpIMC->hCompStr);
  880.     ImmUnlockIMC(hIMC);
  881. return GeneratePunct(hIMC,wParam);//首键非数字字母键,止步于此。
  882. }
  883. }
  884. //if(wConversionMode == CONVERSION_MODE_WUBIATTACHLIB)
  885. if( CharHandleWuBiAttachLib(hIMC,wParam,lParam) ) goto my_exit;
  886. /*if(wConversionMode == CONVERSION_MODE_WUBI)
  887. if( CharHandleWuBi(hIMC,wParam,lParam) ) goto my_exit;
  888. if(wConversionMode == CONVERSION_MODE_HISTORYREUSE) 
  889. if( CharHandleHistoryReuse(hIMC,wParam,lParam) ) goto my_exit;*/
  890. //当返回为1时,跳过如下半角符号转化为全角的部分
  891. FullHalfShapeHandler(hIMC,lpCompStr,wParam);
  892. my_exit:
  893. ImmUnlockIMCC(lpIMC->hCompStr);
  894.     ImmUnlockIMC(hIMC);
  895. return TRUE;
  896. }
  897. BOOL CharHandler(
  898. HIMC hIMC,
  899. WORD wParam,
  900. LONG lParam)
  901. {
  902.     LPINPUTCONTEXT lpIMC;
  903.     LPCOMPOSITIONSTRING lpCompStr;
  904. LPCANDIDATEINFO lpCandInfo;
  905.     DWORD dwStrLen;
  906.     GENEMSG GnMsg;
  907. //LPTSTR lpConvStr;
  908.     lpIMC = ImmLockIMC(hIMC);
  909. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  910.     dwStrLen = lpCompStr->dwCompStrLen;
  911.     if (!dwStrLen)//首键进入此
  912.     {
  913. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  914. ClearCompStr(lpCompStr);
  915. ClearCandidate(lpCandInfo);
  916. ImmUnlockIMCC(lpIMC->hCandInfo);
  917.         GnMsg.msg = WM_IME_STARTCOMPOSITION;
  918.         GnMsg.wParam = 0;
  919.         GnMsg.lParam = 0;
  920.         GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  921. //重复输入最后一次的输入结果
  922. if(wParam == _T('#')&& wConversionMode != CONVERSION_MODE_WUBI) {
  923. ImmUnlockIMCC(lpIMC->hCompStr);
  924.     ImmUnlockIMC(hIMC);
  925. return RepeatPreResult(hIMC);
  926. }
  927. else if( (wParam < _T('a') || wParam > _T('z')) &&
  928. (wParam < _T('A') || wParam > _T('Z')) &&
  929. (wParam < _T('0') || wParam > _T('9')) ){
  930. ImmUnlockIMCC(lpIMC->hCompStr);
  931.     ImmUnlockIMC(hIMC);
  932. return GeneratePunct(hIMC,wParam);//首键非数字字母键,止步于此。
  933. }
  934. if(wConversionSet & CONVERSION_SET_NO_IUV){
  935. if( wParam == _T('i') ) {
  936. LPTSTR lpStr;
  937. wPreConversionMode=wConversionMode;
  938. fTempState=1;
  939. wConversionMode = CONVERSION_MODE_I;
  940. lpStr = GETLPCOMPSTR(lpCompStr);
  941. *lpStr = (TCHAR)wParam;
  942. *(lpStr+1) = _T('');
  943. lpCompStr->dwCompStrLen = _tcslen(lpStr);
  944. lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  945. _tcscpy(lpStr,IMODEL);
  946. GnMsg.msg = WM_IME_COMPOSITION;
  947. GnMsg.wParam = 0;
  948. GnMsg.lParam = GCS_COMPSTR;
  949. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  950. goto my_exit;
  951. }
  952. if( wParam == _T('u') ) {
  953. LPTSTR lpStr;
  954. wPreConversionMode=wConversionMode;
  955. fTempState=1;
  956. wConversionMode = CONVERSION_MODE_U;
  957. lpStr = GETLPCOMPSTR(lpCompStr);
  958. *lpStr = (TCHAR)wParam;
  959. *(lpStr+1) = _T('');
  960. lpCompStr->dwCompStrLen = _tcslen(lpStr);
  961. lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  962. _tcscpy(lpStr,UMODEL);
  963. GnMsg.msg = WM_IME_COMPOSITION;
  964. GnMsg.wParam = 0;
  965. GnMsg.lParam = GCS_COMPSTR;
  966. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  967. goto my_exit;
  968. }
  969. if( wParam == _T('v') ) {
  970. LPTSTR lpStr;
  971. wPreConversionMode=wConversionMode;
  972. fTempState=1;
  973. wConversionMode = CONVERSION_MODE_V;
  974. lpStr = GETLPCOMPSTR(lpCompStr);
  975. *lpStr = (TCHAR)wParam;
  976. *(lpStr+1) = _T('');
  977. lpCompStr->dwCompStrLen = _tcslen(lpStr);
  978. lpCompStr->dwCompStrLen=1;
  979. lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  980. _tcscpy(lpStr,VMODEL);
  981. GnMsg.msg = WM_IME_COMPOSITION;
  982. GnMsg.wParam = 0;
  983. GnMsg.lParam = GCS_COMPSTR;
  984. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  985. goto my_exit;
  986. }
  987. }
  988. }
  989. if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR) {
  990. if( CharHandlePhToCh(hIMC,wParam,lParam) ) goto my_exit;
  991. }
  992. else if(wConversionMode == CONVERSION_MODE_I) {
  993. if( CharHandleI(hIMC,wParam,lParam) ) goto my_exit;
  994. }
  995. else if(wConversionMode == CONVERSION_MODE_U) {
  996. if( CharHandleU(hIMC,wParam,lParam) ) goto my_exit;
  997. }
  998. else if(wConversionMode == CONVERSION_MODE_V) {
  999. if( CharHandleV(hIMC,wParam,lParam) ) goto my_exit;
  1000. }
  1001. else if(wConversionMode == CONVERSION_MODE_WUBIADD) {
  1002. if( CharHandleWuBiAdd(hIMC,wParam,lParam) ) goto my_exit;
  1003. }
  1004. else if(wConversionMode == CONVERSION_MODE_WUBIADDSELF) {
  1005. if( CharHandleWuBiAddSelf(hIMC,wParam,lParam) ) goto my_exit;
  1006. }
  1007. else{
  1008. if( CharHandleNormal(hIMC,wParam,lParam) ) goto my_exit;
  1009. }
  1010. //当返回为1时,跳过如下半角符号转化为全角的部分
  1011. FullHalfShapeHandler(hIMC,lpCompStr,wParam);
  1012. my_exit:
  1013. ImmUnlockIMCC(lpIMC->hCompStr);
  1014.     ImmUnlockIMC(hIMC);
  1015. return TRUE;
  1016. }
  1017. void ViewSharedMemoryCondition()
  1018. {
  1019. TCHAR szStr[1000],szStr1[200];
  1020. _stprintf(szStr,"%s词库尾:%dn%s词库尾:%dn记录汉字符数:%dn%s单字库尾:%dn",
  1021. StatusDisplay[CONVERSION_MODE_WUBI],dwWubiMapFileOffset,
  1022. StatusDisplay[CONVERSION_MODE_ATTACHLIB],dwAttachLibMapFileOffset,strlen(HistoryTwoCodes)/2,
  1023. StatusDisplay[CONVERSION_MODE_PINYIN],dwHistoryMapFileOffset);
  1024. _stprintf(szStr1,"%s系统词库尾:%dn%s用户词库尾:%dn",StatusDisplay[CONVERSION_MODE_PINYIN],
  1025. dwMapFileOffset,StatusDisplay[CONVERSION_MODE_PINYIN],dwMapFileUsrOffset);
  1026. _tcscat(szStr,szStr1);
  1027. if(wConversionSet &CONVERSION_SET_USEWB){
  1028. _stprintf(szStr1,"%s全部码元:n%sn%s系统词库码元:n%sn%s用户词库码元:n%sn",
  1029. StatusDisplay[CONVERSION_MODE_WUBI],WbUsedcodes,StatusDisplay[CONVERSION_MODE_WUBI],WbSysUsedcodes,
  1030. StatusDisplay[CONVERSION_MODE_WUBI],WbUsrUsedcodes);
  1031. _tcscat(szStr,szStr1);
  1032. _stprintf(szStr1,"%s库末:%sn",StatusDisplay[CONVERSION_MODE_WUBI],(char *)wubiDictHead->prev->strHZ);
  1033. _tcscat(szStr,szStr1);
  1034. }
  1035. if(wConversionSet &CONVERSION_SET_USEATTACH){
  1036. _stprintf(szStr1,"%s词库全部码元:n%sn",StatusDisplay[CONVERSION_MODE_ATTACHLIB],AttUsedcodes);
  1037. _tcscat(szStr,szStr1);
  1038. _stprintf(szStr1,"%s库末:%sn",StatusDisplay[CONVERSION_MODE_ATTACHLIB],(char *)AttachLibDictHead->prev->strHZ);
  1039. _tcscat(szStr,szStr1);
  1040. }
  1041. if(wConversionSet &CONVERSION_SET_USEWB){
  1042. LPWBRecord recTemp=wubiDictHead->next;
  1043. int uTotal=0,uSame=0;
  1044. while(recTemp!=wubiDictHead->prev){
  1045. uTotal++;
  1046. if(!_tcscmp(recTemp->strCode,recTemp->next->strCode)) uSame++;
  1047. recTemp=recTemp->next;
  1048. }
  1049. _stprintf(szStr1,"%s词条总数:%dn%s重码数:%dn%s重码率:%d%%n",
  1050. StatusDisplay[CONVERSION_MODE_WUBI],uTotal,StatusDisplay[CONVERSION_MODE_WUBI],uSame,
  1051. StatusDisplay[CONVERSION_MODE_WUBI],uSame*100/uTotal);
  1052. _tcscat(szStr,szStr1);
  1053. }
  1054. if(wConversionSet &CONVERSION_SET_USEATTACH){
  1055. LPAttachLibRecord recTemp=AttachLibDictHead->next;
  1056. int uTotal=0,uSame=0;
  1057. while(recTemp!=AttachLibDictHead->prev){
  1058. uTotal++;
  1059. if(!_tcscmp(recTemp->strCode,recTemp->next->strCode)) uSame++;
  1060. recTemp=recTemp->next;
  1061. }
  1062. _stprintf(szStr1,"%s词条总数:%dn%s重码数:%dn%s重码率:%d%%n",
  1063. StatusDisplay[CONVERSION_MODE_ATTACHLIB],uTotal,StatusDisplay[CONVERSION_MODE_ATTACHLIB],uSame,
  1064. StatusDisplay[CONVERSION_MODE_ATTACHLIB],uSame*100/uTotal);
  1065. _tcscat(szStr,szStr1);
  1066. }
  1067. MessageBox(NULL,szStr,_T("共享内存情况报告:"),MB_OK);
  1068. }
  1069. void DeleteSamePhrase()
  1070. {
  1071. if(SaySorry()) return;
  1072. if (MessageBox(NULL, _T("你要自动删除相同的词条吗?"), _T("删除相同词条,提高词库效能"), MB_YESNO) == IDYES){
  1073. AutoDelSamePhrase ();
  1074. MessageBox(NULL,_T("已经完成整理工作"),_T("自动删除相同词条"),MB_OK);
  1075. }
  1076. }
  1077. int SaySorry()
  1078. {
  1079. if(wConversionMode != CONVERSION_MODE_WUBI){
  1080. MessageBoxPrintf(_T("对不起"),_T("本功能仅适用五笔模式。"));
  1081. return 1;
  1082. }
  1083. else return 0;
  1084. }
  1085. void MakeWordFromClipboard(HIMC hIMC)
  1086. {
  1087.     LPINPUTCONTEXT lpIMC;
  1088.     lpIMC = ImmLockIMC(hIMC);
  1089. if(SaySorry()) return;
  1090. if(OpenClipboard(NULL))
  1091. {
  1092. TCHAR szStr[200],szStr1[2000];
  1093. HANDLE hData = GetClipboardData(CF_TEXT);
  1094. char * lpStr = (char*)GlobalLock(hData);
  1095. int nLen,i=0;
  1096. if(lpStr==NULL){
  1097. MessageBox(NULL,_T("剪贴板取词失败!"),_T("出错"),MB_OK);
  1098. return ;
  1099. //goto my_exit;
  1100. }
  1101. _tcscpy(szStr1,lpStr);
  1102. GlobalUnlock(hData);
  1103. CloseClipboard();
  1104. nLen=_tcslen(szStr1);
  1105. if(nLen>MAXSTRHZLENGTH-2){
  1106. MessageBox(NULL, _T("字数至多35个。"), _T("字数太多了。"), MB_OK);
  1107. return;
  1108. }
  1109. if(nLen%2){
  1110. MessageBox(NULL, _T("不能包含半角符号。"), _T("含有半角符号"), MB_OK);
  1111. return;
  1112. }
  1113. if(nLen<=2){
  1114. MessageBox(NULL, _T("汉字数至少两个。"), _T("汉字数至少两个。"), MB_OK);
  1115. return;
  1116. }
  1117. while (i<nLen ) {
  1118. if (IsDBCSLeadByte((BYTE)*(szStr1+i))) {
  1119. i+=2;
  1120. continue;
  1121. }
  1122. else {
  1123. MessageBox(NULL, _T("不能含非gbk字符。"), _T("含非gbk字符"), MB_OK);
  1124. return;
  1125. }
  1126. }
  1127. if((wConversionSet1 & C_SET1_ERBIMAKEWORD)?
  1128. AutoGetWordErbiCode (szStr1,0):
  1129. AutoGetWordWubiCode (szStr1,0)) {
  1130. _stprintf(szStr,"%s:%sn要加入自动编码吗?n",szStr1,AutoWuBiCode);
  1131. if (MessageBox(NULL, szStr, _T("自动加码提示:手工录码请选否。"), MB_YESNO) == IDYES){
  1132. if(wConversionSet1 & C_SET1_ERBIMAKEWORD) AutoGetWordErbiCode (szStr1,1);
  1133. else AutoGetWordWubiCode (szStr1,1);
  1134. }
  1135. else {
  1136. _stprintf(szStr,"要手工录入编码吗?n%sn",szStr1);
  1137. if(MessageBox(NULL,szStr,_T("请选择:"),MB_YESNO) == IDYES){
  1138. //加入手工加码部分
  1139. _tcscpy(AutoWuBiWord,szStr1);
  1140. MakeResultString(hIMC,FALSE);
  1141. lpIMC->fOpen=FALSE;
  1142. DialogBox( hInst,MAKEINTRESOURCE(DIALOGADDCODE),NULL,AddDialogProc);
  1143. InsertPhrase(AutoWuBiCode,AutoWuBiWord);
  1144. lpIMC->fOpen=TRUE;
  1145. }
  1146. else MessageBox(NULL,_T("放弃了手工录码!"),_T("无为退出"),MB_OK);
  1147. }
  1148. }
  1149. else {
  1150. MessageBox(NULL,_T("对剪贴板中的词自动编码换失败!"),_T("出错信息"),MB_OK);
  1151. }
  1152. }
  1153. else MessageBox(NULL,_T("剪贴板打开失败!"),_T("出错"),MB_OK);
  1154. }
  1155. void TurnUserWordIntoSys()
  1156. { WORD UserWordNum=0;
  1157. TCHAR szStr[256];
  1158. if(SaySorry()) return;
  1159. wubiDictCurrent = wubiDictHead->next;
  1160. while (wubiDictCurrent != wubiDictHead->prev) {
  1161. if (wubiDictCurrent->BeUser) 
  1162. UserWordNum++;
  1163. wubiDictCurrent = wubiDictCurrent->next;
  1164. }//计数
  1165. _stprintf(szStr,"当前用户词库的词组个数%d个。",UserWordNum);
  1166. if (MessageBox(NULL, szStr,_T("要将用户词导入系统词库吗?"), 
  1167.             MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) == IDYES) {
  1168. wubiDictCurrent = wubiDictHead->next;
  1169. while (wubiDictCurrent != wubiDictHead->prev) {
  1170. if (wubiDictCurrent->BeUser) wubiDictCurrent->BeUser=0;
  1171. wubiDictCurrent = wubiDictCurrent->next;
  1172. }
  1173. MessageBox(NULL,_T("谢谢使用。"),_T("您已经升格了所有的用户词到系统词库中。"),MB_OK);
  1174. }
  1175. else MessageBoxPrintf(_T("建议:请经常将用户词升格到系统词库。"),_T("您已经放弃升格用户词到系统词库。"));
  1176. if (MessageBox(NULL,_T("要立即保存系统词库吗?"),_T("建议:立即保存系统词库,除非你已经选择了保存系统词库的选项。"), 
  1177.             MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) == IDYES) {
  1178. SaveWubiSysDict();
  1179. }
  1180. }
  1181. void TurnToNextWordLib(BOOL CurrentDir)
  1182. {
  1183. static int j=0;
  1184. TCHAR   TempTableDir[MAX_PATH];
  1185. if(!CurrentDir){
  1186. j++;
  1187. if(_tcslen(RelativeTableDirList[j])==0)  j=0;
  1188. sprintf(TempTableDir,"%smb\%s\",InstallFromDir,RelativeTableDirList[j]);
  1189. if(!_tcscmp(CurrentTableDir,TempTableDir)){
  1190. j++;
  1191. if(_tcslen(RelativeTableDirList[j])==0)  j=0;
  1192. }
  1193. }
  1194. TurnToNextWordLib1(j);
  1195. }
  1196. void TurnToNextWordLib1(UINT j)
  1197. {
  1198. TCHAR   TempTableDir[MAX_PATH];
  1199. if(j>=MAX_LIBDIRNUM)return;
  1200. if(strlen(RelativeTableDirList[j])==0) return;
  1201. SwitchUserPath=1;
  1202. SwitchUserPathGT++;
  1203. SwitchUserPathGT%=100;
  1204. DestroyDictionary();//清除所有共享内存
  1205. ClearPunct();
  1206. LoadHZDictionary("",1);
  1207. _tcscpy(StatusDisplay[CONVERSION_MODE_WUBI],_T("五笔"));
  1208. sprintf(TempTableDir,"%smb\%s\",InstallFromDir,RelativeTableDirList[j]);
  1209. MessageBoxPrintf(_T("码表目录切换"),_T("从%sn到%sn"),CurrentTableDir,TempTableDir);
  1210. _tcscpy(CurrentTableDir,TempTableDir);
  1211. //记录下CurrentTableDir
  1212. WriteGlobalIni();
  1213. //读入个性化数据
  1214. ReadUserIni();
  1215. InitDictionary();//重新载入所有文件至共享内存
  1216. SwitchUserPath=0;
  1217. }
  1218. void ShowSystemTime()
  1219. {
  1220. SYSTEMTIME tm;
  1221. TCHAR szStr[50];
  1222. GetLocalTime(&tm);
  1223. _stprintf(szStr,"%d时%d分%d秒",tm.wHour,tm.wMinute,tm.wSecond);
  1224. MessageBox(NULL,szStr,_T("系统时间"),MB_OK);
  1225. }
  1226. void AbsorbZhongyiTable()
  1227. {
  1228. TCHAR szStr[200];
  1229. _stprintf(szStr,"如果要吸收中易输入法生成器逆转换生成的码表,n请先将之保存为winwbx.txt。n你要加入winwb86格式的词条吗?n");
  1230. if (MessageBox(NULL, szStr, _T("吸收中易输入法生成器逆转换生成的码表:"), MB_YESNO) == IDYES){
  1231. LoadWinImegenTable();
  1232. MessageBoxPrintf(_T("自动加入词条"),_T("已经完成加入词条工作"));
  1233. }
  1234. else{
  1235. _stprintf(szStr,"提示:将中易输入法生成器逆转换生成的的词条加入。n可以让你继续使用的原来自造的特殊词汇。n");
  1236. MessageBoxPrintf(_T("放弃加入词条"),szStr);
  1237. }
  1238. }
  1239. void DeleteHistoryRecord()
  1240. {
  1241. if (MessageBox(NULL, _T("要将要清除输入历史吗?"),_T("若为快速造词,请保留输入历史。"), 
  1242.             MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON1) == IDYES) {
  1243. ClearWordHistory ();
  1244. MessageBox(NULL,_T("谢谢使用。"),_T("您已经清除了输入历史。"),MB_OK);
  1245. }
  1246. else MessageBox(NULL,_T("建议:为安全起见,请清除输入历史。"),
  1247. _T("您已经放弃清除输入历史。"),MB_OK);
  1248. }
  1249. void TurnIntoAttachLibMode(HIMC hIMC)
  1250. {
  1251. if(!(wConversionSet &CONVERSION_SET_USEATTACH)) return;
  1252. wConversionMode = CONVERSION_MODE_ATTACHLIB;
  1253. UpdateStatusByMessage(hIMC);
  1254. if(!fTempState)WriteUserIni();
  1255. }
  1256. void TurnIntoWubiAttachLibMode(HIMC hIMC)
  1257. {
  1258. if(!(wConversionSet &CONVERSION_SET_USEWB)) return;
  1259. if(!(wConversionSet &CONVERSION_SET_USEATTACH)) return;
  1260. wConversionMode = CONVERSION_MODE_WUBIATTACHLIB;
  1261. UpdateStatusByMessage(hIMC);
  1262. WriteUserIni();
  1263. }
  1264. void TurnIntoWubiMode(HIMC hIMC)
  1265. {
  1266. if(!(wConversionSet &CONVERSION_SET_USEWB)) return;
  1267. wConversionMode = CONVERSION_MODE_WUBI;
  1268. UpdateStatusByMessage(hIMC);
  1269. WriteUserIni();
  1270. }
  1271. void TurnIntoWubiModeAdd(HIMC hIMC)
  1272. {
  1273.     LPINPUTCONTEXT lpIMC;
  1274. LPCOMPOSITIONSTRING lpCompStr;
  1275.     GENEMSG GnMsg;
  1276. LPTSTR lpStr;
  1277. lpIMC = ImmLockIMC(hIMC);
  1278. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  1279. wConversionMode = CONVERSION_MODE_WUBIADD;
  1280. lpCompStr->dwCompStrLen=1;
  1281. lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  1282. _tcscpy(lpStr,WUBIMODELADD);
  1283. GnMsg.msg = WM_IME_COMPOSITION;
  1284. GnMsg.wParam = 0;
  1285. GnMsg.lParam = GCS_COMPSTR;
  1286. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  1287. }
  1288. void TurnIntoPinyinMode(HIMC hIMC)
  1289. {
  1290. if(!(wConversionSet &CONVERSION_SET_USEPY)) return;
  1291. wConversionMode = CONVERSION_MODE_PINYIN;
  1292. UpdateStatusByMessage(hIMC);
  1293. if(!fTempState)WriteUserIni();
  1294. }
  1295. void TurnIntoQuickMode(HIMC hIMC)
  1296. {
  1297. wConversionMode = CONVERSION_MODE_QUICK;
  1298. UpdateStatusByMessage(hIMC);
  1299. WriteUserIni();
  1300. }
  1301. void TurnIntoMode_U(HIMC hIMC)
  1302. {
  1303. wConversionMode = CONVERSION_MODE_U;
  1304. WriteUserIni();
  1305. UpdateStatusByMessage(hIMC);
  1306. }
  1307. void TurnIntoMode_I(HIMC hIMC)
  1308. {
  1309. wConversionMode = CONVERSION_MODE_I;
  1310. WriteUserIni();
  1311. UpdateStatusByMessage(hIMC);
  1312. }
  1313. void TurnIntoMode_V(HIMC hIMC)
  1314. {
  1315. wConversionMode = CONVERSION_MODE_V;
  1316. WriteUserIni();
  1317. UpdateStatusByMessage(hIMC);
  1318. }
  1319. void ToggleConversionMode(HIMC hIMC)
  1320. {
  1321. if(wConversionMode == CONVERSION_MODE_WUBI)
  1322. TurnIntoPinyinMode(hIMC);
  1323. else 
  1324. TurnIntoWubiMode(hIMC);
  1325. }
  1326. void ToggleConversionMode1()
  1327. {
  1328. if(wConversionMode == CONVERSION_MODE_WUBI){
  1329. if(!(wConversionSet &CONVERSION_SET_USEPY)) return;
  1330. wConversionMode = CONVERSION_MODE_PINYIN;
  1331. }
  1332. else {
  1333. if(!(wConversionSet &CONVERSION_SET_USEWB)) return;
  1334. wConversionMode = CONVERSION_MODE_WUBI;
  1335. }
  1336. }
  1337. void ToggleConversionSet(DWORD Conversion_Set_Value)
  1338. {
  1339. if(wConversionSet & Conversion_Set_Value)
  1340. wConversionSet &= ~Conversion_Set_Value;
  1341. else
  1342. wConversionSet |= Conversion_Set_Value;
  1343. WriteUserIni();
  1344. }
  1345. void UpdateStatusByMessage(HIMC hIMC)
  1346. {
  1347.     GENEMSG GnMsg;
  1348. GnMsg.msg = WM_IME_NOTIFY;
  1349. GnMsg.wParam = IMN_SETCONVERSIONMODE;
  1350. GnMsg.lParam = 0;
  1351. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  1352. }
  1353. void CreateStatusByMessage(HIMC hIMC)
  1354. {
  1355.     GENEMSG GnMsg;
  1356. GnMsg.msg = WM_IME_NOTIFY;
  1357. GnMsg.wParam = IMN_OPENSTATUSWINDOW;
  1358. GnMsg.lParam = 0;
  1359. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  1360. }