Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1002 lines
40 KiB

  1. /*************************************************
  2. * userdic.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. #include "prop.h"
  8. #include <stdlib.h>
  9. /*****************************************************************************
  10. FUNCTION: UserDicDialogProc(HWND, UINT, WPARAM, LPARAM)
  11. PURPOSE: Processes messages for "UserDic" property sheet.
  12. PARAMETERS:
  13. hdlg - window handle of the property sheet
  14. wMessage - type of message
  15. wparam - message-specific information
  16. lparam - message-specific information
  17. RETURN VALUE:
  18. TRUE - message handled
  19. FALSE - message not handled
  20. HISTORY:
  21. 04-18-95 Yehfew Tie Created.
  22. ****************************************************************************/
  23. INT_PTR CALLBACK UserDicDialogProc(HWND hdlg,
  24. UINT uMessage,
  25. WPARAM wparam,
  26. LPARAM lparam)
  27. {
  28. LPNMHDR lpnmhdr;
  29. static TCHAR DestFile[MAX_PATH];
  30. static TCHAR SrcFile [MAX_PATH];
  31. static TCHAR SysPath [MAX_PATH];
  32. static DWORD dwUserWord;
  33. static LPEMB_Head EMB_Table;
  34. TCHAR wai_code[MAXCODELEN +1],cCharStr[USER_WORD_SIZE+1];
  35. TCHAR szStr[MAX_PATH], FileName[128];
  36. int nCnt, nSel, nInsWords;
  37. int len,i;
  38. int SelItem[1000];
  39. static BOOL bModify;
  40. static int OldSel;
  41. //FARPROC lpCrtDlg;
  42. LPIMEKEY lpImeKeyData;
  43. static DESCRIPTION Descript;
  44. HANDLE HmemEMBTmp_Table;
  45. switch (uMessage)
  46. {
  47. case WM_INITDIALOG:
  48. SetUDMDisable(hdlg);
  49. len = GetSystemDirectory(SysPath,MAX_PATH);
  50. StringCchCat(SysPath,ARRAYSIZE(SysPath),TEXT(Slope));
  51. hImeKeyData = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,
  52. sizeof(IMEKEY)*100);
  53. FillObjectIme(hdlg,hImeKeyData);
  54. lpImeKeyData = GlobalLock(hImeKeyData);
  55. GetImeTxtName(lpImeKeyData[0].ImeKey, FileName);
  56. GlobalUnlock(hImeKeyData);
  57. StringCchCopy(DestFile, ARRAYSIZE(DestFile),SysPath);
  58. StringCchCat(DestFile, ARRAYSIZE(DestFile),FileName);
  59. len = lstrlen(DestFile);
  60. DestFile[len-4]=0;
  61. StringCchCopy(szStr, ARRAYSIZE(szStr), DestFile);
  62. StringCchCat(DestFile, ARRAYSIZE(DestFile),TEXT(EmbExt));
  63. StringCchCat(szStr, ARRAYSIZE(szStr), TEXT(MbExt));
  64. ReadDescript(szStr,&Descript,FILE_SHARE_READ);
  65. if (Descript.wNumRules == 0)
  66. EnableWindow(GetDlgItem(hdlg,IDC_AUTOCODE),FALSE);
  67. else
  68. EnableWindow(GetDlgItem(hdlg,IDC_AUTOCODE),TRUE);
  69. SendDlgItemMessage(hdlg,IDC_COMBO1,CB_SETCURSEL,0,0L);
  70. bModify = FALSE;
  71. OldSel = 0;
  72. break;
  73. case WM_NOTIFY:
  74. lpnmhdr = (NMHDR FAR *)lparam;
  75. switch (lpnmhdr->code)
  76. {
  77. case PSN_SETACTIVE:
  78. hEncode = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,
  79. NUMENCODEAREA*sizeof(ENCODEAREA));
  80. if(!hEncode)
  81. ProcessError(ERR_OUTOFMEMORY,hdlg,ERR);
  82. if ( hEncode )
  83. ConvInitEncode(hEncode);
  84. break;
  85. case PSN_APPLY:
  86. if(bModify) {
  87. LoadString(NULL,
  88. IDS_FILEMODIFY,
  89. FileName,
  90. sizeof(FileName)/sizeof(TCHAR));
  91. #ifdef UNICODE
  92. {
  93. TCHAR UniTmp[] = {0x6279, 0x91CF, 0x9020, 0x8BCD,
  94. 0x9875, 0x9762, 0x4E2D, 0x0000};
  95. StringCchPrintf(szStr,ARRAYSIZE(szStr),TEXT("%ws\n\'%ws\'\n%ws"),
  96. UniTmp,SrcFile,FileName);
  97. }
  98. #else
  99. StringCchPrintf(szStr,ARRAYSIZE(szStr),"��������ҳ����\n\'%s\'\n%s"
  100. ,SrcFile,FileName);
  101. #endif
  102. if (ErrMessage(hdlg,szStr))
  103. SendMessage(hdlg,WM_COMMAND,IDC_SAVE,0L);
  104. }
  105. break;
  106. case PSN_RESET:
  107. break;
  108. case PSN_QUERYCANCEL:
  109. break;
  110. case PSN_KILLACTIVE:
  111. if (hEncode)
  112. GlobalFree(hEncode);
  113. break;
  114. case PSN_HELP:
  115. break;
  116. default:
  117. break;
  118. }
  119. break;
  120. case WM_COMMAND:
  121. switch (LOWORD(wparam))
  122. {
  123. case ID_FILEOPEN:
  124. {
  125. #ifdef UNICODE
  126. static TCHAR szTitle[] = {0x6253, 0x5F00,0x0000};
  127. #else
  128. TCHAR szTitle[MAX_PATH];
  129. lstrcpy(szTitle,"����");
  130. #endif
  131. if(!TxtFileOpenDlg(hdlg,szStr,szTitle))
  132. break;
  133. }
  134. lstrcpy(SrcFile,szStr);
  135. ReadUserWord(hdlg,SrcFile,&dwUserWord,Descript.wMaxCodes);
  136. SetUDMEnable(hdlg);
  137. EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE);
  138. fnsplit(SrcFile, szStr);
  139. SetDlgItemText(hdlg,IDC_SRCNAME,szStr);
  140. break;
  141. case IDC_COMBO1:
  142. nSel = (INT)SendDlgItemMessage(hdlg,
  143. IDC_COMBO1,
  144. CB_GETCURSEL,
  145. (WPARAM)0,
  146. (LPARAM)0);
  147. if(nSel == CB_ERR || nSel == OldSel) break;
  148. OldSel = nSel;
  149. lpImeKeyData = GlobalLock(hImeKeyData);
  150. GetImeTxtName(lpImeKeyData[nSel].ImeKey, FileName);
  151. GlobalUnlock(hImeKeyData);
  152. StringCchCopy(DestFile,ARRAYSIZE(DestFile), SysPath);
  153. StringCchCat(DestFile, ARRAYSIZE(DestFile), FileName);
  154. len = lstrlen(DestFile);
  155. DestFile[len-4]=0;
  156. StringCchCat(DestFile, ARRAYSIZE(DestFile),TEXT(EmbExt));
  157. SendMessage(hdlg,WM_COMMAND,IDC_GETMBFILE,(LPARAM)szStr);
  158. if(ReadDescript(szStr,&Descript,FILE_SHARE_READ) != TRUE)
  159. Descript.wNumRules = 0;
  160. if(Descript.wNumRules == 0)
  161. EnableWindow(GetDlgItem(hdlg,IDC_AUTOCODE),FALSE);
  162. else
  163. EnableWindow(GetDlgItem(hdlg,IDC_AUTOCODE),TRUE);
  164. break;
  165. case IDC_INSUSERDIC:
  166. if(lstrlen(DestFile)==0) {
  167. MessageBeep((UINT)-1);
  168. MessageBeep((UINT)-1);
  169. break;
  170. }
  171. nCnt=(INT)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETSELCOUNT,0,0L);
  172. if(nCnt>1000) nCnt=1000;
  173. SendDlgItemMessage(hdlg,
  174. IDC_LIST,
  175. LB_GETSELITEMS,
  176. nCnt,
  177. (LPARAM)SelItem);
  178. if(nCnt == 0) {
  179. MessageBeep((UINT)-1);
  180. MessageBeep((UINT)-1);
  181. break;
  182. }
  183. SendMessage(hdlg,WM_COMMAND,IDC_GETMBFILE,(LPARAM)szStr);
  184. if(ReadDescript(szStr,&Descript,FILE_SHARE_READ) != TRUE)
  185. break;
  186. if(!ReadEMBFromFile(DestFile,EMB_Table))
  187. {
  188. GlobalUnlock(HmemEMB_Table);
  189. GlobalFree(HmemEMB_Table);
  190. break;
  191. }
  192. HmemEMBTmp_Table = GlobalReAlloc(HmemEMB_Table,
  193. 1000*sizeof(EMB_Head),
  194. GMEM_MOVEABLE);
  195. if (HmemEMBTmp_Table == NULL)
  196. {
  197. GlobalFree(HmemEMB_Table);
  198. break;
  199. }
  200. HmemEMB_Table = HmemEMBTmp_Table;
  201. EMB_Table = GlobalLock(HmemEMB_Table);
  202. nInsWords = 0;
  203. SetCursor (LoadCursor (NULL, IDC_WAIT));
  204. while((--nCnt) >= 0) {
  205. len = (INT)SendDlgItemMessage(hdlg,
  206. IDC_LIST,
  207. LB_GETTEXT,
  208. SelItem[nCnt],
  209. (LPARAM)szStr);
  210. szStr[len]=0;
  211. dwLineNo = SelItem[nCnt] + 1;
  212. #ifdef UNICODE
  213. for(i=0;i<len;i++)
  214. if(szStr[i] < 0x100) break;
  215. #else
  216. for(i=0;i<len;i += 2)
  217. if(szStr[i] > 0) break;
  218. #endif
  219. lstrncpy(wai_code,MAXCODELEN,&szStr[i]);
  220. szStr[i]=0;
  221. lstrncpy(cCharStr,USER_WORD_SIZE,szStr);
  222. if(CheckCodeLegal(hdlg,cCharStr,NULL,wai_code,&Descript))
  223. {
  224. if(AddZCItem(DestFile,EMB_Table,wai_code,cCharStr))
  225. nInsWords ++;
  226. }
  227. else
  228. {
  229. GlobalUnlock(HmemEMB_Table);
  230. GlobalFree(HmemEMB_Table);
  231. break;
  232. }
  233. }
  234. LoadString(NULL,IDS_INSWORDS,szStr,ARRAYSIZE(szStr));
  235. #ifdef UNICODE
  236. _itow(nInsWords,FileName,10);
  237. #else
  238. _itoa(nInsWords,FileName,10);
  239. #endif
  240. StringCchCat(szStr, ARRAYSIZE(szStr), FileName);
  241. InfoMessage(hdlg,szStr);
  242. GlobalUnlock(HmemEMB_Table);
  243. GlobalFree(HmemEMB_Table);
  244. SetCursor (LoadCursor (NULL, IDC_ARROW));
  245. break;
  246. case IDC_FULLSELECT:
  247. nCnt=(INT)SendDlgItemMessage(hdlg,
  248. IDC_LIST,
  249. LB_GETCOUNT,
  250. (WPARAM)0,
  251. (LPARAM)0);
  252. SendDlgItemMessage(hdlg,
  253. IDC_LIST,
  254. LB_SELITEMRANGE,
  255. TRUE,MAKELPARAM(1,nCnt));
  256. break;
  257. case IDC_AUTOCODE:
  258. nCnt = (INT)SendDlgItemMessage(hdlg,
  259. IDC_LIST,
  260. LB_GETSELCOUNT,
  261. (WPARAM)0,
  262. (LPARAM)0);
  263. if(nCnt > 1000) nCnt = 1000;
  264. if(nCnt == 0) {
  265. MessageBeep((UINT)-1);
  266. break;
  267. }
  268. SendDlgItemMessage(hdlg,
  269. IDC_LIST,
  270. LB_GETSELITEMS,
  271. nCnt,
  272. (LPARAM)SelItem);
  273. SendMessage(hdlg,WM_COMMAND,IDC_GETMBFILE,(LPARAM)szStr);
  274. if(ReadDescript(szStr,&Descript,FILE_SHARE_READ) != TRUE)
  275. Descript.wNumRules = 0;
  276. if(Descript.wNumRules == 0) {
  277. ProcessError(ERR_NORULE,hdlg,ERR);
  278. break;
  279. }
  280. SetCursor (LoadCursor (NULL, IDC_WAIT));
  281. nInsWords = nCnt;
  282. while((--nCnt) >= 0)
  283. {
  284. len = (INT)SendDlgItemMessage(hdlg,
  285. IDC_LIST,
  286. LB_GETTEXT,
  287. SelItem[nCnt],
  288. (LPARAM)FileName);
  289. FileName[len]=0;
  290. #ifdef UNICODE
  291. for(i=0;i<len;i++)
  292. if(FileName[i] < 0x100) break;
  293. #else
  294. for(i=0;i<len;i += 2)
  295. if(FileName[i] > 0) break;
  296. #endif
  297. lstrncpy(wai_code,MAXCODELEN,&FileName[i]);
  298. FileName[i]=0;
  299. lstrncpy(cCharStr,USER_WORD_SIZE,FileName);
  300. lstrncpy(wai_code,
  301. MAXCODELEN,
  302. ConvCreateWord(hdlg,szStr,cCharStr));
  303. StringCchCat(FileName, ARRAYSIZE(FileName), wai_code);
  304. SendDlgItemMessage(hdlg,
  305. IDC_LIST,
  306. LB_DELETESTRING,
  307. SelItem[nCnt],
  308. (LPARAM)0);
  309. SendDlgItemMessage(hdlg,
  310. IDC_LIST,
  311. LB_INSERTSTRING,
  312. SelItem[nCnt],
  313. (LPARAM)FileName);
  314. }
  315. EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE);
  316. bModify = TRUE;
  317. for(i=0; i< nInsWords; i++)
  318. SendDlgItemMessage(hdlg,
  319. IDC_LIST,
  320. LB_SETSEL,
  321. TRUE,
  322. SelItem[i]);
  323. SetCursor(LoadCursor(NULL, IDC_ARROW));
  324. break;
  325. case IDC_ADD:
  326. //lpCrtDlg = MakeProcInstance((FARPROC)AddWordDlg, hInst);
  327. //DialogBox(hInst,
  328. // MAKEINTRESOURCE(IDD_ADDWORD),
  329. // hdlg,
  330. // (DLGPROC)lpCrtDlg);
  331. //FreeProcInstance(lpCrtDlg);
  332. DialogBox(hInst,
  333. MAKEINTRESOURCE(IDD_ADDWORD),
  334. hdlg,
  335. AddWordDlg);
  336. nCnt=(INT)SendDlgItemMessage(hdlg,
  337. IDC_LIST,
  338. LB_GETCOUNT,
  339. (WPARAM)0,
  340. (LPARAM)0);
  341. if(nCnt != 0)
  342. SetUDMEnable(hdlg);
  343. break;
  344. case IDC_ADDSTR:
  345. SendDlgItemMessage(hdlg,IDC_LIST,LB_ADDSTRING,0,lparam);
  346. EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE);
  347. bModify = TRUE;
  348. break;
  349. case IDC_GETMBFILE:
  350. nSel=(INT)SendDlgItemMessage(hdlg,
  351. IDC_COMBO1,
  352. CB_GETCURSEL,
  353. (WPARAM)0,
  354. (LPARAM)0);
  355. if(nSel==CB_ERR) break;
  356. lpImeKeyData = GlobalLock(hImeKeyData);
  357. GetImeTxtName(lpImeKeyData[nSel].ImeKey, FileName);
  358. GlobalUnlock(hImeKeyData);
  359. StringCchCopy(szStr, ARRAYSIZE(szStr), SysPath);
  360. StringCchCat(szStr, ARRAYSIZE(szStr), FileName);
  361. len = lstrlen(szStr);
  362. szStr[len-4] = 0;
  363. StringCchCat(szStr,ARRAYSIZE(szStr), TEXT(MbExt));
  364. lstrcpy((LPTSTR)lparam,szStr);
  365. break;
  366. case IDC_GETUSERWORD:
  367. nCnt = (INT)SendDlgItemMessage(hdlg,
  368. IDC_LIST,
  369. LB_GETCURSEL,
  370. (WPARAM)0,
  371. (LPARAM)0);
  372. len = (INT)SendDlgItemMessage(hdlg,
  373. IDC_LIST,
  374. LB_GETTEXT,
  375. nCnt,
  376. (LPARAM)szStr);
  377. szStr[len] = 0;
  378. lstrcpy((LPTSTR)lparam,szStr);
  379. break;
  380. case IDC_CHGDATA:
  381. nCnt=(INT)SendDlgItemMessage(hdlg,
  382. IDC_LIST,
  383. LB_GETCURSEL,
  384. (WPARAM)0,
  385. (LPARAM)0);
  386. SendDlgItemMessage(hdlg,
  387. IDC_LIST,
  388. LB_DELETESTRING,
  389. nCnt,
  390. (LPARAM)0);
  391. SendDlgItemMessage(hdlg,
  392. IDC_LIST,
  393. LB_INSERTSTRING,
  394. nCnt,
  395. lparam);
  396. EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE);
  397. bModify = TRUE;
  398. break;
  399. case IDC_MODIFY:
  400. nCnt = (INT)SendDlgItemMessage(hdlg,
  401. IDC_LIST,
  402. LB_GETSELCOUNT,
  403. (WPARAM)0,
  404. (LPARAM)0);
  405. if(nCnt!=1) {
  406. MessageBeep((UINT)-1);
  407. break;
  408. }
  409. SendDlgItemMessage(hdlg,
  410. IDC_LIST,
  411. LB_GETSELITEMS,
  412. nCnt,
  413. (LPARAM)SelItem);
  414. //lpCrtDlg = MakeProcInstance((FARPROC)ModiWordDlg, hInst);
  415. //DialogBox(hInst,
  416. // MAKEINTRESOURCE(IDD_MODIWORD),
  417. // hdlg,
  418. // (DLGPROC)lpCrtDlg);
  419. //FreeProcInstance(lpCrtDlg);
  420. DialogBox(hInst,
  421. MAKEINTRESOURCE(IDD_MODIWORD),
  422. hdlg,
  423. ModiWordDlg);
  424. break;
  425. case IDC_DEL:
  426. nCnt=(INT)SendDlgItemMessage(hdlg,
  427. IDC_LIST,
  428. LB_GETSELCOUNT,
  429. (WPARAM)0,
  430. (LPARAM)0);
  431. if (nCnt > 1000) nCnt = 1000;
  432. if (nCnt==0) {
  433. MessageBeep((UINT)-1);
  434. break;
  435. }
  436. SendDlgItemMessage(hdlg,
  437. IDC_LIST,
  438. LB_GETSELITEMS,
  439. nCnt,
  440. (LPARAM)SelItem);
  441. SetCursor(LoadCursor(NULL, IDC_WAIT));
  442. for (i=nCnt-1; i>=0; i--)
  443. SendDlgItemMessage(hdlg,
  444. IDC_LIST,
  445. LB_DELETESTRING,
  446. SelItem[i],
  447. (LPARAM)0);
  448. EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE);
  449. SetFocus(GetDlgItem(hdlg,IDC_LIST));
  450. bModify = TRUE;
  451. SetCursor (LoadCursor (NULL, IDC_ARROW));
  452. break;
  453. case IDC_SAVE:
  454. nCnt=(INT)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCOUNT,0,0L);
  455. if(nCnt==0) {
  456. MessageBeep((UINT)-1);
  457. break;
  458. }
  459. if(SaveTxtFileAs(hdlg,SrcFile)) {
  460. EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE);
  461. bModify = FALSE;
  462. }
  463. break;
  464. default:
  465. break;
  466. }
  467. break;
  468. default:
  469. break;
  470. }
  471. return FALSE;
  472. }
  473. INT_PTR CALLBACK AddWordDlg(
  474. HWND hDlg,
  475. UINT message,
  476. WPARAM wParam,
  477. LPARAM lParam)
  478. {
  479. static TCHAR szDBCS[128];
  480. static TCHAR szCode[13];
  481. static TCHAR szStr[128];
  482. static TCHAR szMbName[128];
  483. switch (message) {
  484. case WM_INITDIALOG:
  485. SendDlgItemMessage(hDlg,IDC_INPUTWORD,EM_LIMITTEXT,USER_WORD_SIZE,0L);
  486. SendDlgItemMessage(hDlg,IDC_INPUTCODE,EM_LIMITTEXT,MAXCODELEN,0L);
  487. return (TRUE);
  488. case WM_COMMAND:
  489. switch(LOWORD(wParam)) {
  490. case IDOK:
  491. GetDlgItemText(hDlg,IDC_INPUTWORD,szDBCS,sizeof(szDBCS)/sizeof(TCHAR));
  492. GetDlgItemText(hDlg,IDC_INPUTCODE,szCode,sizeof(szCode)/sizeof(TCHAR));
  493. if(lstrlen(szDBCS)<2||lstrlen(szCode) == 0){
  494. MessageBeep((UINT)-1);
  495. break;
  496. }
  497. StringCchCopy(szStr, ARRAYSIZE(szStr), szDBCS);
  498. StringCchCat(szStr, ARRAYSIZE(szStr), szCode);
  499. SendMessage(GetParent(hDlg),WM_COMMAND,IDC_ADDSTR,(LPARAM)szStr);
  500. EndDialog(hDlg, TRUE);
  501. return (TRUE);
  502. case IDC_INPUTWORD:
  503. GetDlgItemText(hDlg,IDC_INPUTWORD,szDBCS,sizeof(szDBCS)/sizeof(TCHAR));
  504. if(SendDlgItemMessage(hDlg,IDC_INPUTWORD,EM_GETMODIFY,0,0L)) {
  505. if(!CheckUserDBCS(hDlg,szDBCS)) {
  506. SetDlgItemText(hDlg,IDC_INPUTWORD, szDBCS);
  507. SendDlgItemMessage(hDlg,IDC_INPUTWORD,EM_SETMODIFY,FALSE,0L);
  508. }
  509. if(lstrlen(szDBCS)<4/sizeof(TCHAR)) {
  510. szStr[0]=0;
  511. SetDlgItemText(hDlg,IDC_INPUTCODE,szStr);
  512. break;
  513. }
  514. SendMessage(GetParent(hDlg),WM_COMMAND,IDC_GETMBFILE,(LPARAM)szMbName);
  515. if(lstrlen(szMbName) != 0) {
  516. lstrncpy(szStr,MAXCODELEN,ConvCreateWord(hDlg,szMbName,szDBCS));
  517. szStr[MAXCODELEN]=0;
  518. if(lstrlen(szStr)!=0)
  519. lstrcpy(szCode,szStr);
  520. SetDlgItemText(hDlg,IDC_INPUTCODE, szCode);
  521. }
  522. SendDlgItemMessage(hDlg,IDC_INPUTWORD,EM_SETMODIFY,FALSE,0L);
  523. }
  524. break;
  525. case IDC_INPUTCODE:
  526. GetDlgItemText(hDlg,IDC_INPUTWORD,szDBCS,sizeof(szDBCS)/sizeof(TCHAR));
  527. GetDlgItemText(hDlg,IDC_INPUTCODE,szCode,sizeof(szCode)/sizeof(TCHAR));
  528. if(lstrlen(szDBCS) == 0) {
  529. MessageBeep((UINT)-1);
  530. SetFocus(GetDlgItem(hDlg,IDC_INPUTWORD));
  531. break;
  532. }
  533. break;
  534. case IDCANCEL:
  535. EndDialog(hDlg, TRUE);
  536. break;
  537. case WM_CLOSE:
  538. EndDialog(hDlg, TRUE);
  539. break;
  540. default:
  541. break;
  542. }
  543. break;
  544. }
  545. return (FALSE);
  546. UNREFERENCED_PARAMETER(lParam);
  547. }
  548. INT_PTR CALLBACK ModiWordDlg(
  549. HWND hDlg,
  550. UINT message,
  551. WPARAM wParam,
  552. LPARAM lParam)
  553. {
  554. static TCHAR szDBCS[128];
  555. static TCHAR szCode[13];
  556. static TCHAR szStr[128];
  557. static TCHAR szMbName[128];
  558. int len,i;
  559. switch (message) {
  560. case WM_INITDIALOG:
  561. SendDlgItemMessage(hDlg,IDC_INPUTWORD,EM_LIMITTEXT,
  562. USER_WORD_SIZE,0L);
  563. SendDlgItemMessage(hDlg,IDC_INPUTCODE,EM_LIMITTEXT,MAXCODELEN,0L);
  564. SendMessage(GetParent(hDlg),WM_COMMAND,IDC_GETUSERWORD,
  565. (LPARAM)szStr);
  566. len=lstrlen(szStr);
  567. for(i=0;i<len;i++)
  568. if(szStr[i] > 0) break;
  569. lstrncpy(szCode,MAXCODELEN,&szStr[i]);
  570. szStr[i]=0;
  571. lstrncpy(szDBCS,USER_WORD_SIZE,szStr);
  572. SetDlgItemText(hDlg,IDC_INPUTWORD,szDBCS);
  573. SetDlgItemText(hDlg,IDC_INPUTCODE,szCode);
  574. return (TRUE);
  575. case WM_COMMAND:
  576. switch(LOWORD(wParam)) {
  577. case IDOK:
  578. GetDlgItemText(hDlg,IDC_INPUTWORD,szDBCS,
  579. sizeof(szDBCS)/sizeof(TCHAR));
  580. GetDlgItemText(hDlg,IDC_INPUTCODE,szCode,
  581. sizeof(szCode)/sizeof(TCHAR));
  582. if(lstrlen(szDBCS)<2||lstrlen(szCode) == 0){
  583. MessageBeep((UINT)-1);
  584. break;
  585. }
  586. StringCchCopy(szStr,ARRAYSIZE(szStr), szDBCS);
  587. StringCchCat(szStr, ARRAYSIZE(szStr), szCode);
  588. SendMessage(GetParent(hDlg),WM_COMMAND,IDC_CHGDATA,0L);
  589. EndDialog(hDlg, TRUE);
  590. return (TRUE);
  591. case IDC_INPUTWORD:
  592. GetDlgItemText(hDlg,IDC_INPUTWORD,szDBCS,
  593. sizeof(szDBCS)/sizeof(TCHAR));
  594. if(SendDlgItemMessage(hDlg,IDC_INPUTWORD,EM_GETMODIFY,0,0L))
  595. {
  596. if(!CheckUserDBCS(hDlg,szDBCS)) {
  597. SetDlgItemText(hDlg,IDC_INPUTWORD, szDBCS);
  598. SendDlgItemMessage(hDlg,IDC_INPUTWORD,EM_SETMODIFY,
  599. FALSE,0L);
  600. }
  601. if(lstrlen(szDBCS)<4/sizeof(TCHAR)) {
  602. szStr[0]=0;
  603. SetDlgItemText(hDlg,IDC_INPUTCODE,szStr );
  604. break;
  605. }
  606. SendMessage(GetParent(hDlg),WM_COMMAND,IDC_GETMBFILE,
  607. (LPARAM)szMbName);
  608. lstrncpy(szStr,MAXCODELEN,
  609. ConvCreateWord(hDlg,szMbName,szDBCS));
  610. szStr[MAXCODELEN]=0;
  611. if(lstrlen(szStr)!=0)
  612. lstrcpy(szCode,szStr);
  613. SetDlgItemText(hDlg,IDC_INPUTCODE, szCode);
  614. SendDlgItemMessage(hDlg,IDC_INPUTWORD,EM_SETMODIFY,
  615. FALSE,0L);
  616. }
  617. break;
  618. case IDC_INPUTCODE:
  619. GetDlgItemText(hDlg,IDC_INPUTWORD,szDBCS,
  620. sizeof(szDBCS)/sizeof(TCHAR));
  621. GetDlgItemText(hDlg,IDC_INPUTCODE,szCode,
  622. sizeof(szCode)/sizeof(TCHAR));
  623. if(lstrlen(szDBCS) == 0) {
  624. MessageBeep((UINT)-1);
  625. SetFocus(GetDlgItem(hDlg,IDC_INPUTWORD));
  626. break;
  627. }
  628. break;
  629. case IDCANCEL:
  630. EndDialog(hDlg, TRUE);
  631. break;
  632. case WM_CLOSE:
  633. EndDialog(hDlg, TRUE);
  634. break;
  635. default:
  636. break;
  637. }
  638. break;
  639. }
  640. return (FALSE);
  641. UNREFERENCED_PARAMETER(lParam);
  642. }
  643. void SetUDMDisable(HWND hDlg)
  644. {
  645. EnableWindow(GetDlgItem(hDlg,IDC_INSUSERDIC),FALSE);
  646. EnableWindow(GetDlgItem(hDlg,IDC_FULLSELECT),FALSE);
  647. EnableWindow(GetDlgItem(hDlg,IDC_AUTOCODE),FALSE);
  648. EnableWindow(GetDlgItem(hDlg,IDC_DEL) ,FALSE);
  649. EnableWindow(GetDlgItem(hDlg,IDC_SAVE) ,FALSE);
  650. EnableWindow(GetDlgItem(hDlg,IDC_LIST) ,FALSE);
  651. EnableWindow(GetDlgItem(hDlg,IDC_STATIC1) ,FALSE);
  652. }
  653. void SetUDMEnable(HWND hDlg)
  654. {
  655. EnableWindow(GetDlgItem(hDlg,IDC_INSUSERDIC),TRUE);
  656. EnableWindow(GetDlgItem(hDlg,IDC_FULLSELECT),TRUE);
  657. EnableWindow(GetDlgItem(hDlg,IDC_DEL) ,TRUE);
  658. EnableWindow(GetDlgItem(hDlg,IDC_SAVE) ,TRUE);
  659. EnableWindow(GetDlgItem(hDlg,IDC_LIST) ,TRUE);
  660. EnableWindow(GetDlgItem(hDlg,IDC_STATIC1) ,TRUE);
  661. }
  662. void FillObjectIme(HWND hDlg, HANDLE hImeKeyData)
  663. {
  664. HKEY hImeKey=NULL,hPreImeKey=NULL,hkResult=NULL;
  665. WORD wNumIme = 0;
  666. TCHAR KeyName[10], LayoutName[10];
  667. TCHAR LayoutText[128], FileName[MAX_PATH],SysPath[MAX_PATH];
  668. int i, len, retCode;
  669. DWORD DataType;
  670. LPIMEKEY ImeKeyData;
  671. DESCRIPTION Descript;
  672. DWORD dwKeyName, dwLayoutName;
  673. if(RegCreateKey(HKEY_CURRENT_USER,TEXT(PreImeKey),&hPreImeKey))
  674. return;
  675. if(RegCreateKey(HKEY_LOCAL_MACHINE,TEXT(ImeSubKey),&hImeKey))
  676. return;
  677. SetCursor (LoadCursor (NULL, IDC_WAIT));
  678. ImeKeyData = GlobalLock(hImeKeyData);
  679. for (i = 0, retCode = ERROR_SUCCESS; retCode == ERROR_SUCCESS; i++) {
  680. dwKeyName = sizeof(KeyName)/sizeof(TCHAR);
  681. dwLayoutName = sizeof(LayoutName);
  682. retCode = RegEnumValue(hPreImeKey,
  683. i,
  684. KeyName,
  685. &dwKeyName,
  686. NULL,&DataType,
  687. (LPBYTE)LayoutName,
  688. &dwLayoutName);
  689. if (retCode == (DWORD)ERROR_SUCCESS) {
  690. LayoutName[dwLayoutName] = TEXT('\0');
  691. if ( hkResult != NULL )
  692. RegCloseKey(hkResult);
  693. if(LayoutName[0] != TEXT('E') && LayoutName[0] != TEXT('e'))
  694. continue;
  695. if(RegOpenKey(hImeKey,LayoutName,&hkResult))
  696. continue;
  697. len = sizeof(LayoutText);
  698. len = RegQueryValueEx(hkResult,
  699. TEXT(LayoutTextKey),
  700. NULL,
  701. &DataType,
  702. (LPBYTE)LayoutText,
  703. &len);
  704. RegCloseKey(hkResult);
  705. if(len != ERROR_SUCCESS)
  706. continue;
  707. GetImeTxtName(LayoutName, FileName);
  708. len = lstrlen(FileName);
  709. FileName[len-4] = 0;
  710. lstrcat(FileName,TEXT(MbExt));
  711. GetSystemDirectory(SysPath,MAX_PATH);
  712. StringCchCat(SysPath, ARRAYSIZE(SysPath), TEXT(Slope));
  713. StringCchCat(SysPath, ARRAYSIZE(SysPath), FileName);
  714. if(ReadDescript(SysPath,&Descript,FILE_SHARE_READ) != TRUE)
  715. continue;
  716. SendDlgItemMessage(hDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)LayoutText);
  717. lstrcpy(ImeKeyData[wNumIme].ImeKey, LayoutName);
  718. wNumIme++;
  719. }
  720. }
  721. RegCloseKey(hPreImeKey);
  722. RegCloseKey(hImeKey);
  723. GlobalUnlock(hImeKeyData);
  724. SetCursor (LoadCursor (NULL, IDC_ARROW));
  725. }
  726. void GetImeTxtName(LPCTSTR ImeKeyName, LPTSTR FileName)
  727. {
  728. HKEY hImeKey,hkResult;
  729. int len;
  730. DWORD DataType;
  731. FileName[0] = 0;
  732. if(RegCreateKey(HKEY_LOCAL_MACHINE,TEXT(ImeSubKey),&hImeKey))
  733. return;
  734. if(RegOpenKey(hImeKey,ImeKeyName,&hkResult))
  735. return ;
  736. len = 128;
  737. len = RegQueryValueEx(hkResult,TEXT(MbName),NULL,&DataType,(LPBYTE)FileName,&len);
  738. RegCloseKey(hkResult);
  739. RegCloseKey(hImeKey);
  740. }
  741. BOOL SaveTxtFile(HWND hWnd,LPTSTR SrcFile)
  742. {
  743. HANDLE hFile;
  744. TCHAR szStr[256];
  745. int i,nCount;
  746. DWORD dwBytes;
  747. nCount=(INT)SendDlgItemMessage(hWnd,IDC_LIST,LB_GETCOUNT,0,0L);
  748. if(nCount==0) {
  749. MessageBeep((UINT)-1);
  750. return FALSE;
  751. }
  752. hFile = CreateFile(SrcFile,
  753. GENERIC_WRITE,
  754. FILE_SHARE_READ,
  755. NULL,
  756. CREATE_ALWAYS,
  757. 0,
  758. NULL);
  759. if (hFile == (HANDLE)-1)
  760. return FALSE;
  761. SetCursor (LoadCursor (NULL, IDC_WAIT));
  762. for(i=0;i<nCount;i++) {
  763. SendDlgItemMessage(hWnd,IDC_LIST,LB_GETTEXT,i,(LPARAM)szStr);
  764. StringCchCat(szStr, ARRAYSIZE(szStr), TEXT("\r\n"));
  765. WriteFile(hFile,szStr,lstrlen(szStr),&dwBytes,NULL);
  766. }
  767. SetCursor (LoadCursor (NULL, IDC_ARROW));
  768. CloseHandle(hFile);
  769. return TRUE;
  770. }
  771. BOOL SaveEmb(HWND hWnd,LPCTSTR SrcFile)
  772. {
  773. int i,j,len;
  774. WORD nCount;
  775. TCHAR szStr[256];
  776. HANDLE hFile;
  777. DWORD dwBytes;
  778. EMB_Head EmbHead;
  779. nCount=(WORD)SendDlgItemMessage(hWnd,IDC_LIST,LB_GETCOUNT,0,0L);
  780. if(nCount==0) {
  781. MessageBeep((UINT)-1);
  782. return FALSE;
  783. }
  784. hFile = CreateFile(SrcFile,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
  785. if(hFile==INVALID_HANDLE_VALUE) {
  786. ProcessError(ERR_IMEUSE, GetFocus(), ERR);
  787. return FALSE;
  788. }
  789. SetCursor (LoadCursor (NULL, IDC_WAIT));
  790. WriteFile(hFile,&nCount,2,&dwBytes,NULL);
  791. for(i=0;i<nCount;i++) {
  792. len=(INT)SendDlgItemMessage(hWnd,IDC_LIST,LB_GETTEXT,i,(LPARAM)szStr);
  793. szStr[len]=0;
  794. for(j=0;j<len;j++)
  795. if(szStr[j] > 0) break;
  796. lstrncpy(EmbHead.W_Code,MAXCODELEN,&szStr[j]);
  797. szStr[j]=0;
  798. lstrncpy(EmbHead.C_Char,USER_WORD_SIZE,szStr);
  799. WriteFile(hFile,&EmbHead,sizeof(EMB_Head),&dwBytes,NULL);
  800. }
  801. CloseHandle(hFile);
  802. SetCursor (LoadCursor (NULL, IDC_ARROW));
  803. return TRUE;
  804. }
  805. BOOL CheckMbUsed(HKEY hKey,HWND hWnd,LPTSTR KeyName)
  806. {
  807. int len;
  808. HKEY hkResult;
  809. HANDLE hFile;
  810. DWORD DataType;
  811. TCHAR SysPath[MAX_PATH],FileName[MAX_PATH];
  812. if(RegOpenKey(hKey,KeyName,&hkResult))
  813. return FALSE;
  814. len = sizeof(FileName);
  815. len = RegQueryValueEx(hkResult,TEXT(MbName),NULL,&DataType,(LPBYTE)FileName,&len);
  816. RegCloseKey(hkResult);
  817. if(len) return FALSE;
  818. len = lstrlen(FileName);
  819. if(len < 5) return FALSE;
  820. FileName[len-4] = 0;
  821. StringCchCat(FileName, ARRAYSIZE(FileName), TEXT(MbExt));
  822. GetSystemDirectory(SysPath,MAX_PATH);
  823. StringCchCat(SysPath, ARRAYSIZE(SysPath), TEXT(Slope));
  824. StringCchCat(SysPath, ARRAYSIZE(SysPath), FileName);
  825. #ifdef UNICODE
  826. if(_waccess(SysPath,0)==0) {
  827. #else
  828. if(_access(SysPath,0)==0) {
  829. #endif
  830. hFile = CreateFile(SysPath,GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
  831. if(hFile==INVALID_HANDLE_VALUE) {
  832. ProcessError(ERR_IMEUSE,hWnd,ERR);
  833. return FALSE;
  834. }
  835. else
  836. CloseHandle(hFile);
  837. }
  838. return TRUE;
  839. }
  840. INT_PTR CALLBACK UDMEditProc(HWND hWnd,
  841. UINT wMsgID,
  842. WPARAM wParam,
  843. LPARAM lParam)
  844. {
  845. switch(wMsgID) {
  846. case WM_LBUTTONDBLCLK:
  847. SendMessage(GetParent(hWnd),WM_COMMAND,IDC_MODIFY,0L);
  848. break;
  849. case WM_KEYDOWN:
  850. switch(wParam) {
  851. case VK_DELETE:
  852. SendMessage(GetParent(hWnd),WM_COMMAND,IDC_DEL,0L);
  853. break;
  854. }
  855. default:
  856. return CallWindowProc((WNDPROC)lpUDMProc,hWnd,wMsgID,wParam,lParam);
  857. }
  858. return FALSE;
  859. }
  860. void InstallUDMSubClass(HWND hWnd)
  861. {
  862. FARPROC lpNewProc;
  863. lpNewProc = MakeProcInstance(UDMEditProc,hInstance);
  864. lpUDMProc = (FARPROC)GetWindowLongPtr(hWnd,GWLP_WNDPROC);
  865. SetWindowLongPtr(hWnd,GWLP_WNDPROC,(LONG_PTR)lpNewProc);
  866. FreeProcInstance(lpNewProc);
  867. }