Source code of Windows XP (NT5)
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.

892 lines
27 KiB

  1. #include "StdAfx.h"
  2. //
  3. // Handlers for Windows messages
  4. //
  5. BOOL MainHandleInitDialog(HWND hWnd, HWND hwndFocus, LPARAM lParam);
  6. void MainHandleClose(HWND hWnd);
  7. void MainHandleDestroy(HWND hWnd);
  8. void MainHandleCommand(HWND hWnd, int id, HWND hWndControl, UINT codeNotify);
  9. //
  10. // Other local functions
  11. //
  12. BOOL CallOpenFileDialog( HWND hWnd, LPSTR szFileName );
  13. bool ReadLine();
  14. void DisplayValues( HWND hWnd );
  15. HRESULT ConvertReadableToUnicode( const char *szReadable, WCHAR *szwUnicode );
  16. // Global variables - needed to be able to read from file...
  17. using namespace std;
  18. typedef vector<char*> STRINGVECTOR;
  19. STRINGVECTOR fileVector;
  20. int fileIndex;
  21. FILE *fStream, *fSkip, *fDelete, *fTemp;
  22. TCHAR szAFileName[256], tempFileName[257];
  23. BOOL bGotFile = FALSE;
  24. TCHAR sOrth[30], sPos1A[10], sPos1B[10], sPos1C[10], sPos1D[10], sIpa1[40];
  25. TCHAR sPos2A[10], sPos2B[10], sPos2C[10], sPos2D[10], sIpa2[40], sComments[200];
  26. TCHAR sCurline[100], sPrevline[100];
  27. LPARAM CALLBACK DlgProcMain(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  28. {
  29. // Call the appropriate message handler
  30. switch(uMsg)
  31. {
  32. HANDLE_MSG( hwnd, WM_INITDIALOG, MainHandleInitDialog );
  33. HANDLE_MSG( hwnd, WM_CLOSE, MainHandleClose );
  34. HANDLE_MSG( hwnd, WM_DESTROY, MainHandleDestroy );
  35. HANDLE_MSG( hwnd, WM_COMMAND, MainHandleCommand );
  36. }
  37. // Call the default message handler.
  38. // NOTE: Only do this on this main dialog proc. For any other dialogs,
  39. // return TRUE, or the dialog will pop up, and not ever give up
  40. // focus.
  41. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  42. }
  43. /////////////////////////////////////////////////////////////////
  44. void MainHandleCommand(HWND hWnd, int id, HWND hWndControl, UINT codeNotify)
  45. /////////////////////////////////////////////////////////////////
  46. //
  47. // Handle each of the WM_COMMAND messages that come in, and hand them
  48. // off to the correct function.
  49. //
  50. {
  51. char *temp, buffer[100];
  52. switch(id)
  53. {
  54. case IDC_BUTTON_OPEN:
  55. // if file already open, close it before opening a new one...
  56. if (bGotFile) {
  57. fclose(fSkip);
  58. fclose(fDelete);
  59. fileVector.clear();
  60. }
  61. // Do the Open File Dialog...
  62. bGotFile = CallOpenFileDialog( hWnd, szAFileName );
  63. if (bGotFile) {
  64. // DO SOME REGISTRY STUFF TO LOAD THE FIRST UNEDITED WORD...
  65. LONG lRetVal;
  66. HKEY hkResult;
  67. char szPosition[4] = "0";
  68. DWORD size = 4;
  69. lRetVal = RegCreateKeyEx( HKEY_CLASSES_ROOT, _T("LexiconFilePosition"), 0, NULL, 0,
  70. KEY_ALL_ACCESS, NULL, &hkResult, NULL );
  71. if( lRetVal == ERROR_SUCCESS )
  72. {
  73. RegQueryValueEx( hkResult, _T(szAFileName), NULL, NULL, (PBYTE)szPosition, &size );
  74. RegCloseKey( hkResult );
  75. }
  76. fileIndex = atoi(szPosition);
  77. strcpy(tempFileName, szAFileName);
  78. strcpy((tempFileName + strlen(tempFileName)), "~");
  79. SetDlgItemText( hWnd, IDC_EDIT_ORTH, tempFileName );
  80. // OPEN THE FILE, AND READ IT IN TO fileVector... (also copy it into a temporary file)
  81. if( (fStream = fopen( szAFileName, "r" )) != NULL &&
  82. (fTemp = fopen( tempFileName, "w" )) != NULL)
  83. {
  84. int i = 0;
  85. temp = new char[100];
  86. while (fgets(temp, 100, fStream) != NULL) {
  87. fileVector.push_back(temp);
  88. fputs(temp, fTemp);
  89. temp = new char[100];
  90. }
  91. fclose(fTemp);
  92. fclose(fStream);
  93. delete [] temp;
  94. // DISPLAY THE FIRST UNEDITED WORD...
  95. if ( ReadLine() )
  96. DisplayValues(hWnd);
  97. else {
  98. strcpy(sOrth, "NO WORDS!");
  99. DisplayValues(hWnd);
  100. }
  101. }
  102. char fSkipFileName[100] = "";
  103. char fDeleteFileName[100] = "";
  104. strcat(fSkipFileName, szAFileName);
  105. strcat(fSkipFileName, "skip");
  106. strcat(fDeleteFileName, szAFileName);
  107. strcat(fDeleteFileName, "delete");
  108. fSkip = fopen(fSkipFileName, "a+");
  109. fDelete = fopen(fDeleteFileName, "a+");
  110. }
  111. break;
  112. case IDC_BUTTON_DONE:
  113. if (bGotFile) {
  114. // Check word values against their initial values...
  115. char sCurPos1A[10], sCurPos1B[10], sCurPos1C[10], sCurPos1D[10], sCurIpa1[40];
  116. char sCurPos2A[10], sCurPos2B[10], sCurPos2C[10], sCurPos2D[10], sCurIpa2[40], sCurComments[200];
  117. GetDlgItemText( hWnd, IDC_EDIT_POS1A, sCurPos1A, 10 );
  118. GetDlgItemText( hWnd, IDC_EDIT_POS1B, sCurPos1B, 10 );
  119. GetDlgItemText( hWnd, IDC_EDIT_POS1C, sCurPos1C, 10 );
  120. GetDlgItemText( hWnd, IDC_EDIT_POS1D, sCurPos1D, 10 );
  121. GetDlgItemText( hWnd, IDC_EDIT_IPA1, sCurIpa1, 40 );
  122. GetDlgItemText( hWnd, IDC_EDIT_POS2A, sCurPos2A, 10 );
  123. GetDlgItemText( hWnd, IDC_EDIT_POS2B, sCurPos2B, 10 );
  124. GetDlgItemText( hWnd, IDC_EDIT_POS2C, sCurPos2C, 10 );
  125. GetDlgItemText( hWnd, IDC_EDIT_POS2D, sCurPos2D, 10 );
  126. GetDlgItemText( hWnd, IDC_EDIT_IPA2, sCurIpa2, 40 );
  127. GetDlgItemText( hWnd, IDC_EDIT_COMMENTS, sCurComments, 200 );
  128. if ((strcmp(sPos1A, sCurPos1A) != 0) ||
  129. (strcmp(sPos1B, sCurPos1B) != 0) ||
  130. (strcmp(sPos1C, sCurPos1C) != 0) ||
  131. (strcmp(sPos1D, sCurPos1D) != 0) ||
  132. (strcmp(sIpa1, sCurIpa1) != 0) ||
  133. (strcmp(sPos2A, sCurPos2A) != 0) ||
  134. (strcmp(sPos2B, sCurPos2B) != 0) ||
  135. (strcmp(sPos2C, sCurPos2C) != 0) ||
  136. (strcmp(sPos2D, sCurPos2D) != 0) ||
  137. (strcmp(sIpa2, sCurIpa2) != 0) ||
  138. (strcmp(sComments, sCurComments) != 0)) {
  139. // LINE WAS EDITED
  140. strcpy(buffer, "");
  141. strcat(buffer, sOrth);
  142. strcat(buffer, ",");
  143. strcat(buffer, sCurPos1A);
  144. strcat(buffer, ",");
  145. strcat(buffer, sCurPos1B);
  146. strcat(buffer, ",");
  147. strcat(buffer, sCurPos1C);
  148. strcat(buffer, ",");
  149. strcat(buffer, sCurPos1D);
  150. strcat(buffer, ",");
  151. strcat(buffer, sCurIpa1);
  152. strcat(buffer, ",");
  153. strcat(buffer, sCurPos2A);
  154. strcat(buffer, ",");
  155. strcat(buffer, sCurPos2B);
  156. strcat(buffer, ",");
  157. strcat(buffer, sCurPos2C);
  158. strcat(buffer, ",");
  159. strcat(buffer, sCurPos2D);
  160. strcat(buffer, ",");
  161. strcat(buffer, sCurIpa2);
  162. strcat(buffer, ",");
  163. strcat(buffer, sCurComments);
  164. strcat(buffer, "\n");
  165. char *temp = fileVector.at(fileIndex - 1);
  166. strcpy(temp, buffer);
  167. } else {
  168. // LINE WAS NOT EDITED
  169. }
  170. // Display next word...
  171. // First get rid of the previous word values...
  172. strcpy(sPos1A, "");
  173. strcpy(sPos1B, "");
  174. strcpy(sPos1C, "");
  175. strcpy(sPos1D, "");
  176. strcpy(sIpa1, "");
  177. strcpy(sPos2A, "");
  178. strcpy(sPos2B, "");
  179. strcpy(sPos2C, "");
  180. strcpy(sPos2D, "");
  181. strcpy(sIpa2, "");
  182. strcpy(sComments, "");
  183. if ( ReadLine() )
  184. DisplayValues(hWnd);
  185. else {
  186. strcpy(sOrth, "NO WORDS LEFT!");
  187. DisplayValues(hWnd);
  188. }
  189. }
  190. break;
  191. case IDC_BUTTON_RESET:
  192. DisplayValues(hWnd);
  193. break;
  194. case IDC_BUTTON_PREVIOUS:
  195. // First get rid of the previous word values...
  196. strcpy(sPos1A, "");
  197. strcpy(sPos1B, "");
  198. strcpy(sPos1C, "");
  199. strcpy(sPos1D, "");
  200. strcpy(sIpa1, "");
  201. strcpy(sPos2A, "");
  202. strcpy(sPos2B, "");
  203. strcpy(sPos2C, "");
  204. strcpy(sPos2D, "");
  205. strcpy(sIpa2, "");
  206. strcpy(sComments, "");
  207. fileIndex -= 2;
  208. ReadLine();
  209. DisplayValues(hWnd);
  210. break;
  211. case IDC_BUTTON_PLAY1:
  212. WCHAR sWIpa1[40];
  213. char sCurIpa1[40];
  214. GetDlgItemText( hWnd, IDC_EDIT_IPA1, sCurIpa1, 40 );
  215. wcscpy(sWIpa1, L"<PRON IPA=\"");
  216. ConvertReadableToUnicode(sCurIpa1, sWIpa1+11);
  217. wcscpy((sWIpa1 + wcslen(sWIpa1)), L"\"/>a</PRON>");
  218. cpVoice->Speak( sWIpa1, SPF_USEGLOBALDOC, NULL );
  219. break;
  220. case IDC_BUTTON_PLAY2:
  221. WCHAR sWIpa2[40];
  222. char sCurIpa2[40];
  223. GetDlgItemText( hWnd, IDC_EDIT_IPA2, sCurIpa2, 40 );
  224. wcscpy(sWIpa2, L"<PRON IPA=\"");
  225. ConvertReadableToUnicode(sCurIpa2, sWIpa2+11);
  226. wcscpy((sWIpa2 + wcslen(sWIpa2)), L"\"/>a</PRON>");
  227. cpVoice->Speak( sWIpa2, SPF_USEGLOBALDOC, NULL );
  228. break;
  229. case IDC_BUTTON_SKIP:
  230. GetDlgItemText( hWnd, IDC_EDIT_COMMENTS, sComments, 200 );
  231. strcpy(buffer, "");
  232. strcat(buffer, sOrth);
  233. strcat(buffer, ",");
  234. strcat(buffer, sPos1A);
  235. strcat(buffer, ",");
  236. strcat(buffer, sPos1B);
  237. strcat(buffer, ",");
  238. strcat(buffer, sPos1C);
  239. strcat(buffer, ",");
  240. strcat(buffer, sPos1D);
  241. strcat(buffer, ",");
  242. strcat(buffer, sIpa1);
  243. strcat(buffer, ",");
  244. strcat(buffer, sPos2A);
  245. strcat(buffer, ",");
  246. strcat(buffer, sPos2B);
  247. strcat(buffer, ",");
  248. strcat(buffer, sPos2C);
  249. strcat(buffer, ",");
  250. strcat(buffer, sPos2D);
  251. strcat(buffer, ",");
  252. strcat(buffer, sIpa2);
  253. strcat(buffer, ",");
  254. strcat(buffer, sComments);
  255. strcat(buffer, "\n");
  256. fputs(buffer, fSkip);
  257. // Display next word...
  258. // First get rid of the previous word values...
  259. strcpy(sPos1A, "");
  260. strcpy(sPos1B, "");
  261. strcpy(sPos1C, "");
  262. strcpy(sPos1D, "");
  263. strcpy(sIpa1, "");
  264. strcpy(sPos2A, "");
  265. strcpy(sPos2B, "");
  266. strcpy(sPos2C, "");
  267. strcpy(sPos2D, "");
  268. strcpy(sIpa2, "");
  269. strcpy(sComments, "");
  270. if ( ReadLine() )
  271. DisplayValues(hWnd);
  272. else {
  273. strcpy(sOrth, "NO WORDS LEFT!");
  274. DisplayValues(hWnd);
  275. }
  276. break;
  277. case IDC_BUTTON_DELETE:
  278. GetDlgItemText( hWnd, IDC_EDIT_COMMENTS, sComments, 200 );
  279. strcpy(buffer, "");
  280. strcat(buffer, sOrth);
  281. strcat(buffer, ",");
  282. strcat(buffer, sPos1A);
  283. strcat(buffer, ",");
  284. strcat(buffer, sPos1B);
  285. strcat(buffer, ",");
  286. strcat(buffer, sPos1C);
  287. strcat(buffer, ",");
  288. strcat(buffer, sPos1D);
  289. strcat(buffer, ",");
  290. strcat(buffer, sIpa1);
  291. strcat(buffer, ",");
  292. strcat(buffer, sPos2A);
  293. strcat(buffer, ",");
  294. strcat(buffer, sPos2B);
  295. strcat(buffer, ",");
  296. strcat(buffer, sPos2C);
  297. strcat(buffer, ",");
  298. strcat(buffer, sPos2D);
  299. strcat(buffer, ",");
  300. strcat(buffer, sIpa2);
  301. strcat(buffer, ",");
  302. strcat(buffer, sComments);
  303. strcat(buffer, "\n");
  304. fputs(buffer, fDelete);
  305. // Display next word...
  306. // First get rid of the previous word values...
  307. strcpy(sPos1A, "");
  308. strcpy(sPos1B, "");
  309. strcpy(sPos1C, "");
  310. strcpy(sPos1D, "");
  311. strcpy(sIpa1, "");
  312. strcpy(sPos2A, "");
  313. strcpy(sPos2B, "");
  314. strcpy(sPos2C, "");
  315. strcpy(sPos2D, "");
  316. strcpy(sIpa2, "");
  317. strcpy(sComments, "");
  318. if ( ReadLine() )
  319. DisplayValues(hWnd);
  320. else {
  321. strcpy(sOrth, "NO WORDS LEFT!");
  322. DisplayValues(hWnd);
  323. }
  324. break;
  325. }
  326. return;
  327. }
  328. ///////////////////////
  329. void DisplayValues(HWND hWnd)
  330. ///////////////////////
  331. {
  332. SetDlgItemText( hWnd, IDC_EDIT_ORTH, sOrth );
  333. SetDlgItemText( hWnd, IDC_EDIT_POS1A, sPos1A );
  334. SetDlgItemText( hWnd, IDC_EDIT_POS1B, sPos1B );
  335. SetDlgItemText( hWnd, IDC_EDIT_POS1C, sPos1C );
  336. SetDlgItemText( hWnd, IDC_EDIT_POS1D, sPos1D );
  337. SetDlgItemText( hWnd, IDC_EDIT_POS2A, sPos2A );
  338. SetDlgItemText( hWnd, IDC_EDIT_POS2B, sPos2B );
  339. SetDlgItemText( hWnd, IDC_EDIT_POS2C, sPos2C );
  340. SetDlgItemText( hWnd, IDC_EDIT_POS2D, sPos2D );
  341. SetDlgItemText( hWnd, IDC_EDIT_IPA1, sIpa1 );
  342. SetDlgItemText( hWnd, IDC_EDIT_IPA2, sIpa2 );
  343. SetDlgItemText( hWnd, IDC_EDIT_COMMENTS, sComments );
  344. }
  345. ////////////////////////////////
  346. bool ReadLine()
  347. ////////////////////////////////
  348. {
  349. char *linePtr, sLine[100], temp[100];
  350. linePtr = fileVector.at(fileIndex);
  351. strcpy(sLine, linePtr);
  352. fileIndex++;
  353. // Get Orthography...
  354. sscanf(sLine, "%[^,],%s", sOrth, sLine);
  355. // Get Pos1A
  356. sscanf(sLine, "%[^,],%s", sPos1A, temp);
  357. if (strcmp(sPos1A, "") == 0)
  358. sscanf(sLine, ",%s", sLine);
  359. else
  360. strcpy(sLine, temp);
  361. // Get Pos1B
  362. sscanf(sLine, "%[^,],%s", sPos1B, temp);
  363. if (strcmp(sPos1B, "") == 0)
  364. sscanf(sLine, ",%s", sLine);
  365. else
  366. strcpy(sLine, temp);
  367. // Get Pos1C
  368. sscanf(sLine, "%[^,],%s", sPos1C, temp);
  369. if (strcmp(sPos1C, "") == 0)
  370. sscanf(sLine, ",%s", sLine);
  371. else
  372. strcpy(sLine, temp);
  373. // Get Pos1D
  374. sscanf(sLine, "%[^,],%s", sPos1D, temp);
  375. if (strcmp(sPos1D, "") == 0)
  376. sscanf(sLine, ",%s", sLine);
  377. else
  378. strcpy(sLine, temp);
  379. // Get Ipa1
  380. sscanf(sLine, "%[^,],%s", sIpa1, temp);
  381. if (strcmp(sIpa1, "") == 0)
  382. sscanf(sLine, ",%s", sLine);
  383. else
  384. strcpy(sLine, temp);
  385. // Get Pos2A
  386. sscanf(sLine, "%[^,],%s", sPos2A, temp);
  387. if (strcmp(sPos2A, "") == 0)
  388. sscanf(sLine, ",%s", sLine);
  389. else
  390. strcpy(sLine, temp);
  391. // Get Pos2B
  392. sscanf(sLine, "%[^,],%s", sPos2B, temp);
  393. if (strcmp(sPos2B, "") == 0)
  394. sscanf(sLine, ",%s", sLine);
  395. else
  396. strcpy(sLine, temp);
  397. // Get Pos2C
  398. sscanf(sLine, "%[^,],%s", sPos2C, temp);
  399. if (strcmp(sPos2C, "") == 0)
  400. sscanf(sLine, ",%s", sLine);
  401. else
  402. strcpy(sLine, temp);
  403. // Get Pos2D
  404. sscanf(sLine, "%[^,],%s", sPos2D, temp);
  405. if (strcmp(sPos2D, "") == 0)
  406. sscanf(sLine, ",%s", sLine);
  407. else
  408. strcpy(sLine, temp);
  409. // Get Ipa2
  410. sscanf(sLine, "%[^,],%s", sIpa2, temp);
  411. if (strcmp(sIpa2, "") == 0)
  412. sscanf(sLine, ",%s", sLine);
  413. else
  414. strcpy(sLine, temp);
  415. sscanf(sLine, "%[^,],%s", sComments, temp);
  416. return true;
  417. }
  418. //////////////////////////////////////////////////////////////////////
  419. HRESULT ConvertReadableToUnicode( const char *szReadable, WCHAR *szwUnicode )
  420. //////////////////////////////////////////////////////////////////////
  421. {
  422. char cFirst, cSecond;
  423. int iRIndex = 0, iUIndex = 0;
  424. if ( szReadable == NULL )
  425. return E_INVALIDARG;
  426. if ( szwUnicode == NULL )
  427. return E_POINTER;
  428. cFirst = szReadable[iRIndex];
  429. while (cFirst) {
  430. if (('a' <= cFirst) && (cFirst <= 'z')) {
  431. switch (cFirst)
  432. {
  433. case 'b':
  434. szwUnicode[iUIndex] = 0x62;
  435. break;
  436. case 'p':
  437. szwUnicode[iUIndex] = 0x70;
  438. break;
  439. case 'd':
  440. szwUnicode[iUIndex] = 0x64;
  441. break;
  442. case 't':
  443. szwUnicode[iUIndex] = 0x74;
  444. break;
  445. case 'g':
  446. szwUnicode[iUIndex] = 0x261;
  447. break;
  448. case 'k':
  449. szwUnicode[iUIndex] = 0x6b;
  450. break;
  451. case 'f':
  452. szwUnicode[iUIndex] = 0x66;
  453. break;
  454. case 'v':
  455. szwUnicode[iUIndex] = 0x76;
  456. break;
  457. case 's':
  458. szwUnicode[iUIndex] = 0x73;
  459. break;
  460. case 'z':
  461. szwUnicode[iUIndex] = 0x7a;
  462. break;
  463. case 'l':
  464. szwUnicode[iUIndex] = 0x6c;
  465. break;
  466. case 'r':
  467. szwUnicode[iUIndex] = 0x27b;
  468. break;
  469. case 'y':
  470. szwUnicode[iUIndex] = 0x6a;
  471. break;
  472. case 'w':
  473. szwUnicode[iUIndex] = 0x77;
  474. break;
  475. case 'h':
  476. szwUnicode[iUIndex] = 0x266;
  477. break;
  478. case 'm':
  479. szwUnicode[iUIndex] = 0x6d;
  480. break;
  481. case 'n':
  482. szwUnicode[iUIndex] = 0x6e;
  483. break;
  484. case 'j':
  485. szwUnicode[iUIndex] = 0x2a3;
  486. break;
  487. default:
  488. return E_FAIL;
  489. }
  490. iRIndex++;
  491. iUIndex++;
  492. } else if (('A' <= cFirst) && (cFirst <= 'Z')) {
  493. cSecond = szReadable[++iRIndex];
  494. switch (cFirst)
  495. {
  496. case 'A':
  497. switch (cSecond)
  498. {
  499. case 'A':
  500. szwUnicode[iUIndex] = 0x61;
  501. break;
  502. case 'E':
  503. szwUnicode[iUIndex] = 0xe6;
  504. break;
  505. case 'O':
  506. szwUnicode[iUIndex] = 0x254;
  507. break;
  508. case 'X':
  509. szwUnicode[iUIndex] = 0x259;
  510. break;
  511. case 'Y':
  512. szwUnicode[iUIndex] = 0x61;
  513. szwUnicode[++iUIndex] = 0x26a;
  514. break;
  515. case 'W':
  516. szwUnicode[iUIndex] = 0x61;
  517. szwUnicode[++iUIndex] = 0x28a;
  518. break;
  519. default:
  520. return E_FAIL;
  521. }
  522. break;
  523. case 'E':
  524. switch (cSecond)
  525. {
  526. case 'H':
  527. szwUnicode[iUIndex] = 0x25b;
  528. break;
  529. case 'R':
  530. szwUnicode[iUIndex] = 0x25a;
  531. break;
  532. case 'Y':
  533. szwUnicode[iUIndex] = 0x65;
  534. break;
  535. default:
  536. return E_FAIL;
  537. }
  538. break;
  539. case 'I':
  540. switch (cSecond)
  541. {
  542. case 'H':
  543. szwUnicode[iUIndex] = 0x26a;
  544. break;
  545. case 'Y':
  546. szwUnicode[iUIndex] = 0x69;
  547. break;
  548. case 'X':
  549. szwUnicode[iUIndex] = 0x268;
  550. break;
  551. default:
  552. return E_FAIL;
  553. }
  554. break;
  555. case 'U':
  556. switch (cSecond)
  557. {
  558. case 'H':
  559. szwUnicode[iUIndex] = 0x28a;
  560. break;
  561. case 'W':
  562. szwUnicode[iUIndex] = 0x75;
  563. break;
  564. case 'X':
  565. szwUnicode[iUIndex] = 0x28c;
  566. break;
  567. default:
  568. return E_FAIL;
  569. }
  570. break;
  571. case 'O':
  572. switch (cSecond)
  573. {
  574. case 'Y':
  575. szwUnicode[iUIndex] = 0x254;
  576. szwUnicode[++iUIndex] = 0x26a;
  577. break;
  578. case 'W':
  579. szwUnicode[iUIndex] = 0x6f;
  580. szwUnicode[++iUIndex] = 0x28a;
  581. break;
  582. default:
  583. return E_FAIL;
  584. }
  585. break;
  586. case 'D':
  587. switch (cSecond)
  588. {
  589. case 'H':
  590. szwUnicode[iUIndex] = 0xf0;
  591. break;
  592. case 'X':
  593. szwUnicode[iUIndex] = 0x74;
  594. break;
  595. default:
  596. return E_FAIL;
  597. }
  598. break;
  599. case 'T':
  600. if (cSecond == 'H') {
  601. szwUnicode[iUIndex] = 0x3b8;
  602. break;
  603. } else {
  604. return E_FAIL;
  605. }
  606. case 'S':
  607. if (cSecond == 'H') {
  608. szwUnicode[iUIndex] = 0x283;
  609. break;
  610. } else {
  611. return E_FAIL;
  612. }
  613. case 'Z':
  614. if (cSecond == 'H') {
  615. szwUnicode[iUIndex] = 0x292;
  616. break;
  617. } else {
  618. return E_FAIL;
  619. }
  620. case 'C':
  621. if (cSecond == 'H') {
  622. szwUnicode[iUIndex] = 0x2a7;
  623. break;
  624. } else {
  625. return E_FAIL;
  626. }
  627. default:
  628. return E_FAIL;
  629. }
  630. iRIndex++;
  631. iUIndex++;
  632. } else {
  633. switch (cFirst)
  634. {
  635. case '1':
  636. szwUnicode[iUIndex] = 0x2c8;
  637. break;
  638. case '2':
  639. szwUnicode[iUIndex] = 0x2cc;
  640. break;
  641. case '-':
  642. szwUnicode[iUIndex] = 0x2d;
  643. break;
  644. default:
  645. return E_FAIL;
  646. }
  647. iRIndex++;
  648. iUIndex++;
  649. }
  650. cFirst = szReadable[iRIndex];
  651. }
  652. szwUnicode[iUIndex] = 0;
  653. return S_OK;
  654. }
  655. /////////////////////////////////////////////////////////////////
  656. BOOL CallOpenFileDialog( HWND hWnd, LPSTR szFileName )
  657. /////////////////////////////////////////////////////////////////
  658. {
  659. OPENFILENAME ofn;
  660. BOOL bRetVal = TRUE;
  661. LONG lRetVal;
  662. HKEY hkResult;
  663. TCHAR szPath[256] = _T("");
  664. DWORD size = 256;
  665. // Open the last directory used by this app (stored in registry)
  666. lRetVal = RegCreateKeyEx( HKEY_CLASSES_ROOT, _T("PathTTSDataFiles"), 0, NULL, 0,
  667. KEY_ALL_ACCESS, NULL, &hkResult, NULL );
  668. if( lRetVal == ERROR_SUCCESS )
  669. {
  670. RegQueryValueEx( hkResult, _T("TTSFiles"), NULL, NULL, (PBYTE)szPath, &size );
  671. RegCloseKey( hkResult );
  672. }
  673. ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
  674. ofn.hwndOwner = hWnd;
  675. ofn.lpstrFilter = "TXT (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
  676. ofn.lpstrCustomFilter = NULL;
  677. ofn.nFilterIndex = 1;
  678. ofn.lpstrInitialDir = szPath;
  679. ofn.lpstrFile = szFileName;
  680. ofn.nMaxFile = 256;
  681. ofn.lpstrTitle = NULL;
  682. ofn.lpstrFileTitle = NULL;
  683. ofn.lpstrDefExt = NULL;
  684. ofn.Flags = OFN_FILEMUSTEXIST | OFN_READONLY | OFN_PATHMUSTEXIST;
  685. // Pop the dialog
  686. bRetVal = GetOpenFileName( &ofn );
  687. // Write the directory path you're in to the registry
  688. TCHAR pathstr[256] = _T("");
  689. strcpy( pathstr, szFileName );
  690. int i=0;
  691. while( pathstr[i] != NULL )
  692. {
  693. i++;
  694. }
  695. while( pathstr[i] != '\\' )
  696. {
  697. i --;
  698. }
  699. pathstr[i] = NULL;
  700. // Now write the string to the registry
  701. lRetVal = RegCreateKeyEx( HKEY_CLASSES_ROOT, _T("PathTTSDataFiles"), 0, NULL, 0,
  702. KEY_ALL_ACCESS, NULL, &hkResult, NULL );
  703. if( lRetVal == ERROR_SUCCESS )
  704. {
  705. RegSetValueEx( hkResult, _T("TTSFiles"), NULL, REG_EXPAND_SZ, (PBYTE)pathstr, strlen(pathstr)+1 );
  706. RegCloseKey( hkResult );
  707. }
  708. return bRetVal;
  709. }
  710. /////////////////////////////////////////////////////////////////
  711. BOOL MainHandleInitDialog(HWND hWnd, HWND hwndFocus, LPARAM lParam)
  712. /////////////////////////////////////////////////////////////////
  713. {
  714. // Store this as the "Main Dialog"
  715. g_hDlg = hWnd;
  716. strcpy(sCurline, "");
  717. return TRUE;
  718. }
  719. /////////////////////////////////////////////////////////////////
  720. void MainHandleClose(HWND hWnd)
  721. /////////////////////////////////////////////////////////////////
  722. {
  723. LONG lRetVal;
  724. HKEY hkResult;
  725. char buffer[10], *temp;
  726. itoa(fileIndex, buffer, 10);
  727. lRetVal = RegCreateKeyEx( HKEY_CLASSES_ROOT, _T("LexiconFilePosition"), 0, NULL, 0,
  728. KEY_ALL_ACCESS, NULL, &hkResult, NULL );
  729. if( lRetVal == ERROR_SUCCESS )
  730. {
  731. RegSetValueEx( hkResult, _T(szAFileName), NULL, REG_EXPAND_SZ, (PBYTE)buffer, strlen(buffer)+1 );
  732. RegCloseKey( hkResult );
  733. }
  734. if (bGotFile) {
  735. // Save new information back to file in a SAFE manner...
  736. if ((fStream = fopen( szAFileName, "w" )) != NULL) {
  737. int i = 0;
  738. while (i < fileVector.size()) {
  739. temp = fileVector.at(i);
  740. fputs(temp, fStream);
  741. i++;
  742. }
  743. fclose(fStream);
  744. DeleteFile(tempFileName);
  745. }
  746. fclose(fDelete);
  747. fclose(fSkip);
  748. }
  749. // Terminate the app
  750. PostQuitMessage(0);
  751. // Return success
  752. return;
  753. }
  754. /////////////////////////////////////////////////////////////////
  755. void MainHandleDestroy(HWND hWnd)
  756. /////////////////////////////////////////////////////////////////
  757. {
  758. LONG lRetVal;
  759. HKEY hkResult;
  760. char buffer[10];
  761. itoa(fileIndex, buffer, 10);
  762. lRetVal = RegCreateKeyEx( HKEY_CLASSES_ROOT, _T("LexiconFilePosition"), 0, NULL, 0,
  763. KEY_ALL_ACCESS, NULL, &hkResult, NULL );
  764. if( lRetVal == ERROR_SUCCESS )
  765. {
  766. RegSetValueEx( hkResult, _T(szAFileName), NULL, REG_EXPAND_SZ, (PBYTE)buffer, strlen(buffer)+1 );
  767. RegCloseKey( hkResult );
  768. }
  769. // Return success
  770. return;
  771. }