Debian Codegraph @

wince/flowm_main.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2008-2009 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author: Alan W Black ([email protected]) */
34 /* Date: January 2009 */
35 /*************************************************************************/
36 /* */
37 /* Flowm: Flite on Windows Mobile (pronounced flume) */
38 /* 0.5 */
39 /* */
40 /* A simple file reader */
41 /* */
42 /* Thanks to Programming Microsoft Windows CE by Douglas Boling which */
43 /* taught me a lot about how to program in WinCE */
44 /* */
45 /*************************************************************************/
46
47 #include <windows.h>
48 #include <windowsx.h>
49 #include <commctrl.h>
50 #include <aygshell.h>
51
52 /* Apparently from pwingdi.h -- but I don't have that .h file */
53 /* For DisplayOff */
54 #define SETPOWERMANAGEMENT 6147
55 #define VideoPowerOff 4
56 typedef struct _VIDEO_POWER_MANAGEMENT {
57 ULONG Length;
58 ULONG DPMSVersion;
59 ULONG PowerState;
60 } VIDEO_POWER_MANAGEMENT;
61
62 #include "flowm.h"
63
64 #define AppName L"Flown"
65 HINSTANCE hInst;
66
67 int flowm_play_status = FLOWM_STOP;
68 TCHAR fl_filename[257];
69 int flowm_file_pos = 0;
70 int flowm_file_size = 0;
71 /* To hold position of previous utterances for backskipping */
72 int flowm_utt_pos_pos=0;
73 int flowm_prev_utt_pos[FLOWM_NUM_UTT_POS];
74 int flowm_selected_voice = 0;
75 int flowm_selected_relation = 0;
76 float flowm_duration = 0.0;
77
78 #define FL_BENCH_TEXT L"A whole joy was reaping, but they've gone south, you should fetch azure mike."
79
80 HWND hmbar = 0;
81 HWND TTSWindow = 0;
82 TCHAR fl_tts_msg[FL_MAX_MSG_CHARS];
83 TCHAR fl_fp_msg[FL_MAX_MSG_CHARS];
84 SHACTIVATEINFO sai;
85
86 HANDLE tts_thread = INVALID_HANDLE_VALUE;
87
88 const MsgDispatch MainDispatchers[] =
89 {
90 { WM_CREATE, DoCreateMain },
91 { WM_SIZE, DoSizeMain },
92 { WM_COMMAND, DoCommandMain },
93 { WM_NOTIFY, DoNotifyMain },
94 { WM_SETTINGCHANGE, DoSettingChangeMain },
95 { WM_HIBERNATE, DoHibernateMain },
96 { WM_ACTIVATE, DoActivateMain },
97 { WM_DESTROY, DoDestroyMain },
98 { 0, NULL }
99 };
100
101 const CMDDispatch MainCommandItems[] = {
102 { FL_EXIT, DoMainCommandExit },
103 { FL_PLAY, DoMainCommandPlay },
104 { FL_FILE, DoMainCommandFile },
105 { FL_ABOUT, DoMainCommandAbout },
106 { 0, NULL }
107 };
108
109 /*********************************************************************/
110 /*********************************************************************/
111
112 LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
113 {
114 int i;
115
116 for (i=0; MainDispatchers[i].Code != 0; i++)
117 {
118 if (msg == MainDispatchers[i].Code)
119 return (MainDispatchers[i].Fxn)(hwnd,msg,wParam,lParam);
120 }
121 return DefWindowProc(hwnd,msg,wParam,lParam);
122 }
123
124 LRESULT DoCreateMain(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
125 {
126 SHMENUBARINFO mbi;
127
128 ZeroMemory(&mbi,sizeof(mbi));
129 mbi.cbSize = sizeof(SHMENUBARINFO);
130 mbi.hwndParent = hwnd;
131 mbi.nToolBarId = FL_TOOLBAR1;
132 mbi.hInstRes = hInst;
133
134 SHCreateMenuBar(&mbi);
135 hmbar=mbi.hwndMB;
136
137 if (!hmbar)
138 {
139 MessageBox(hwnd, L"Couldn't create toolbar",AppName, MB_OK);
140 DestroyWindow(hwnd);
141 return 0;
142 }
143
144 fl_filename[0] = '\0';
145
146 return 0;
147 }
148
149 LRESULT DoSizeMain(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
150 {
151 return 0;
152 }
153
154 LRESULT DoCommandMain(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
155 {
156 WORD idItem, wNotifyCode;
157 HWND hwndCtl;
158 int i;
159
160 idItem = (WORD)LOWORD(wParam);
161 wNotifyCode = (WORD)HIWORD(wParam);
162 hwndCtl = (HWND)lParam;
163
164 for (i=0; MainCommandItems[i].Code; i++)
165 {
166 if (idItem == MainCommandItems[i].Code)
167 return MainCommandItems[i].Fxn(hwnd,idItem,hwndCtl,wNotifyCode);
168 }
169
170 return 0;
171 }
172
173 LRESULT DoNotifyMain (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
174 {
175 return 0;
176 }
177
178 LRESULT DoSettingChangeMain(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
179 {
180 SHHandleWMSettingChange(hwnd, wParam, lParam, &sai);
181 return 0;
182 }
183
184 LRESULT DoHibernateMain(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
185 {
186 return 0;
187 }
188
189 LRESULT DoActivateMain(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
190 {
191 SHHandleWMActivate(hwnd, wParam, lParam, &sai, 0);
192 return 0;
193 }
194
195 LRESULT DoDestroyMain(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
196 {
197 PostQuitMessage(0);
198 return 0;
199 }
200
201 /* Command handler routines */
202 LPARAM DoMainCommandExit(HWND hwnd, WORD idItem, HWND hwndCtl, WORD wNotifyCode)
203 {
204 SendMessage(hwnd, WM_CLOSE, 0, 0);
205 return 0;
206 }
207
208 LPARAM DoMainCommandAbout(HWND hwnd, WORD idItem,
209 HWND hwndCtl, WORD wNotifyCode)
210 {
211 DialogBox(hInst, L"aboutbox", hwnd, AboutDlgProc);
212 return 0;
213 }
214
215 BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
216 {
217 SHINITDLGINFO idi;
218
219 switch (msg)
220 {
221 case WM_INITDIALOG:
222 idi.dwMask = SHIDIM_FLAGS;
223 idi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN |
224 SHIDIF_SIPDOWN;
225 idi.hDlg = hwnd;
226 SHInitDialog (&idi);
227 return TRUE;
228 case WM_COMMAND:
229 switch (LOWORD(wParam))
230 {
231 case IDOK:
232 case IDCANCEL:
233 EndDialog(hwnd,0);
234 return TRUE;
235 }
236 break;
237 }
238 return FALSE;
239 }
240
241 LPARAM DoMainCommandPlay(HWND hwnd, WORD idItem,
242 HWND hwndCtl, WORD wNotifyCode)
243 {
244 DialogBox(hInst, L"playbox", hwnd, PlayDlgProc);
245 return 0;
246 }
247
248 BOOL CALLBACK PlayDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
249 {
250 OPENFILENAME sf;
251 const LPTSTR pszSaveFilter = L"Waveforms (*.wav)\0*.wav\0\0";
252 SHINITDLGINFO idi;
253 TCHAR text[FL_MAX_TEXTLEN];
254 TCHAR szFilePos[FL_MAX_TEXTLEN];
255 TCHAR *x;
256 int i, looptimes;
257 SYSTEMTIME StartTime, EndTime;
258 float elapsedtime;
259
260 switch (msg)
261 {
262 case WM_INITDIALOG:
263 idi.dwMask = SHIDIM_FLAGS;
264 idi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN;
265 idi.hDlg = hwnd;
266 SHInitDialog (&idi);
267
268 for (i=0; flowm_voice_name(i); i++)
269 { /* Add regestered voices to the voice dropdown */
270 SendDlgItemMessage(hwnd, FL_VOXLIST, CB_ADDSTRING,
271 0, (LPARAM)flowm_voice_name(i));
272 }
273 /* Position cursor at start, selecting first voice */
274 SendDlgItemMessage(hwnd, FL_VOXLIST, CB_SETCURSEL, 0, 0);
275
276 /* Add Relation types to the selection box */
277 SendDlgItemMessage(hwnd,FL_RELLIST,CB_ADDSTRING,0,(LPARAM)L"Token");
278 SendDlgItemMessage(hwnd,FL_RELLIST,CB_ADDSTRING,0,(LPARAM)L"Word");
279 SendDlgItemMessage(hwnd,FL_RELLIST,CB_ADDSTRING,0,(LPARAM)L"Segment");
280 SendDlgItemMessage(hwnd,FL_RELLIST,CB_SETCURSEL,0,0);
281
282 TTSWindow = 0; /* just in case there is a race condition */
283
284 return TRUE;
285 case WM_COMMAND:
286 switch (LOWORD(wParam))
287 {
288 case FL_PUSHPLAY:
289 /* Synthesis the text with selection voice */
290 /* Output items in selected relation at end */
291 GetDlgItemText(hwnd, FL_TEXT, text, FL_MAX_TEXTLEN);
292
293 flowm_selected_voice =
294 ComboBox_GetCurSel(GetDlgItem(hwnd,FL_VOXLIST));
295 flowm_selected_relation =
296 ComboBox_GetCurSel(GetDlgItem(hwnd,FL_RELLIST));
297 flowm_play_status = FLOWM_PLAY;
298 flowm_say_text(text);
299 flowm_play_status = FLOWM_STOP;
300
301 if (flowm_selected_relation > 0)
302 SetDlgItemText(hwnd, FL_OUTPUT, fl_tts_msg);
303
304 return TRUE;
305 case FL_PUSHSAVE:
306 /* Save the last synthesized waveform */
307 ZeroMemory(&sf,sizeof(sf));
308 sf.lStructSize = sizeof(sf);
309 sf.lpstrFile = fl_filename;
310 sf.nMaxFile = 256;
311 sf.lpstrFilter = pszSaveFilter;
312 sf.Flags = 0;
313 sf.lpstrTitle = L"Flowm Save";
314
315 if (GetSaveFileName(&sf) != 0)
316 {
317 if (flowm_save_wave(fl_filename) == -1)
318 wsprintf(fl_tts_msg,L"Wave NOT saved in %s",fl_filename);
319 else
320 wsprintf(fl_tts_msg,L"Wave saved in %s",fl_filename);
321 MessageBox(hwnd, fl_tts_msg, AppName, MB_OK);
322 }
323 fl_filename[0] = '\0';
324
325 return TRUE;
326 case FL_BENCH:
327 /* Bench marking, find out the speed of synthesis on device */
328 if (flowm_play_status == FLOWM_BENCH)
329 {
330 flowm_play_status = FLOWM_STOP;
331 return TRUE;
332 }
333 flowm_play_status = FLOWM_BENCH;
334 /* Find out what voice we want */
335 flowm_selected_voice =
336 ComboBox_GetCurSel(GetDlgItem(hwnd,FL_VOXLIST));
337 flowm_selected_relation = 0;
338
339 flowm_duration = 0.0;
340 GetSystemTime(&StartTime);
341 GetDlgItemText(hwnd, FL_TEXT, szFilePos, FL_MAX_TEXTLEN);
342 looptimes = wcstod(szFilePos,&x);
343 if (looptimes < 5)
344 looptimes = 5;
345 wsprintf(fl_tts_msg,L"Bench marking: loop = %d ...",looptimes);
346 SetDlgItemText(hwnd, FL_OUTPUT, fl_tts_msg);
347 SetDlgItemText(hwnd, FL_TEXT,FL_BENCH_TEXT);
348 for (i=0; i<looptimes; i++)
349 flowm_say_text(FL_BENCH_TEXT);
350 GetSystemTime(&EndTime);
351 /* This will fail over noon (?) and midnight */
352 elapsedtime =
353 (EndTime.wHour*60.0*60.0+EndTime.wMinute*60.0+
354 EndTime.wSecond+EndTime.wMilliseconds/1000.0) -
355 (StartTime.wHour*60.0*60.0+StartTime.wMinute*60.0+
356 StartTime.wSecond+ StartTime.wMilliseconds/1000.0);
357 wsprintf(fl_tts_msg,L"%2.1f speech; %2.1f seconds; %2.2f rate;",
358 flowm_duration,
359 elapsedtime,
360 flowm_duration/elapsedtime);
361 SetDlgItemText(hwnd, FL_OUTPUT, fl_tts_msg);
362
363 flowm_play_status = FLOWM_STOP;
364 return TRUE;
365 case IDOK:
366 case IDCANCEL:
367 flowm_play_status = FLOWM_STOP;
368 EndDialog(hwnd,0);
369 return TRUE;
370 }
371 break;
372 }
373 return FALSE;
374 }
375
376 LPARAM DoMainCommandFile(HWND hwnd, WORD idItem,
377 HWND hwndCtl, WORD wNotifyCode)
378 {
379 DialogBox(hInst, L"filebox", hwnd, FileDlgProc);
380 return 0;
381 }
382
383 DWORD WINAPI tts_thread_function(PVOID pArg)
384 {
385
386 while (flowm_play_status != FLOWM_STOP)
387 {
388 flowm_say_file(fl_filename);
389 if (flowm_play_status == FLOWM_BACKSKIP)
390 flowm_play_status = FLOWM_PLAY; /* restart at new place */
391 else if (flowm_play_status != FLOWM_STOP)
392 {
393 /* If we finish the file without an explicit stop, reset */
394 /* the file position to the start of the file */
395 flowm_file_pos = 0;
396 if (TTSWindow) SetDlgItemText(TTSWindow, FL_FILEPOS, L"0");
397 flowm_play_status = FLOWM_STOP;
398 }
399 }
400
401 return 0x15;
402 }
403
404 static int flowm_find_filesize(TCHAR *filename)
405 {
406 HANDLE fp;
407 int fs = 0;
408
409 fp = CreateFile(filename, GENERIC_READ,
410 FILE_SHARE_READ, NULL,
411 OPEN_EXISTING,
412 FILE_ATTRIBUTE_NORMAL,
413 NULL);
414 if (!fp)
415 return -1;
416
417 fs = GetFileSize(fp,NULL);
418 CloseHandle(fp);
419
420 return fs;
421 }
422
423 void DisplayOff()
424 { /* Switch the screen off now */
425 HDC hdc;
426 VIDEO_POWER_MANAGEMENT vpm;
427
428 hdc = GetDC(NULL);
429 vpm.PowerState = VideoPowerOff;
430 vpm.Length = sizeof(VIDEO_POWER_MANAGEMENT);
431
432 ExtEscape(hdc,
433 SETPOWERMANAGEMENT,
434 sizeof(VIDEO_POWER_MANAGEMENT),
435 (LPCSTR)&vpm,
436 0,
437 NULL);
438
439 return;
440 }
441
442 BOOL CALLBACK FileDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
443 {
444 SHINITDLGINFO idi;
445 OPENFILENAME of;
446 const LPTSTR pszOpenFilter = L"Text Documents (*.txt)\0*.txt\0\0";
447 int nParameter = 5;
448 DWORD dwThreadID = 0;
449 TCHAR szFilePos[FL_MAX_TEXTLEN];
450 TCHAR *x;
451 int i;
452 float nfilepos;
453 HWND hwndvox;
454
455 switch (msg)
456 {
457 case WM_INITDIALOG:
458 idi.dwMask = SHIDIM_FLAGS;
459 idi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN;
460 idi.hDlg = hwnd;
461 SHInitDialog (&idi);
462
463 if (fl_filename[0] != '\0')
464 {
465 SetDlgItemText(hwnd, FL_FILENAME, fl_filename);
466 flowm_file_pos = 0;
467 SetDlgItemText(hwnd, FL_FILEPOS, L"0");
468 }
469
470 for (i=0; flowm_voice_name(i); i++)
471 { /* Add regestered voices to the voice dropdown */
472 SendDlgItemMessage(hwnd, FL_VOXLIST, CB_ADDSTRING,
473 0, (LPARAM)flowm_voice_name(i));
474 }
475 /* Position cursor at start, selecting first voice */
476 SendDlgItemMessage(hwnd, FL_VOXLIST, CB_SETCURSEL, 0, 0);
477
478 return TRUE;
479 case WM_COMMAND:
480 switch (LOWORD(wParam))
481 {
482 case FL_PUSHSELECT:
483 /* Find a file to synthesize */
484 fl_filename[0] = '\0';
485 ZeroMemory(&of,sizeof(of));
486 of.lStructSize = sizeof(of);
487 of.lpstrFile = fl_filename;
488 of.nMaxFile = 256;
489 of.lpstrFilter = pszOpenFilter;
490 of.Flags = 0;
491 of.lpstrTitle = L"Flowm Open";
492
493 if (GetOpenFileName(&of) != 0)
494 {
495 flowm_play_status = FLOWM_STOP;
496 SetDlgItemText(hwnd, FL_FILENAME, fl_filename);
497
498 flowm_file_pos = 0;
499 flowm_file_size = flowm_find_filesize(fl_filename);
500 flowm_utt_pos_pos = 0;
501 flowm_prev_utt_pos[flowm_utt_pos_pos] = 0;
502 SetDlgItemText(hwnd, FL_FILEPOS, L"0");
503 SetDlgItemText(hwnd, FL_SYNTHTEXT, L"");
504 if (flowm_file_size == -1)
505 {
506 wsprintf(fl_fp_msg,L"File not found: %s",fl_filename);
507 MessageBox(hwnd, fl_fp_msg,AppName, MB_OK);
508 fl_filename[0] = '\0';
509 }
510 }
511 return TRUE;
512 case FL_PUSHTTS:
513 /* Synthesize the selected file from the specified position */
514 /* with the selected voice */
515 if ((flowm_play_status != FLOWM_PLAY) &&
516 (fl_filename[0] != '\0'))
517 {
518 flowm_play_status = FLOWM_PLAY;
519 TTSWindow = hwnd;
520 /* Find out what voice we want */
521 hwndvox = GetDlgItem(hwnd,FL_VOXLIST);
522 flowm_selected_voice = ComboBox_GetCurSel(hwndvox);
523
524 /* Update file position, in case user changed it */
525 GetDlgItemText(hwnd, FL_FILEPOS, szFilePos, FL_MAX_TEXTLEN);
526 nfilepos = wcstod(szFilePos,&x);
527 /* Be a little careful we don't reset file position */
528 /* when we have an accuracy problem: filepos is an int */
529 /* but the display field is the % */
530 if (nfilepos > 100) nfilepos = 100.0;
531 if (nfilepos < 0) nfilepos = 0.0;
532 if (((nfilepos - flowm_find_file_percentage()) > 0.001) ||
533 ((nfilepos - flowm_find_file_percentage()) < -0.001))
534 flowm_file_pos = (int)((nfilepos*flowm_file_size)/100.0);
535
536 /* Do the synthesis in a new thread, so we can still process */
537 /* button pushes */
538 tts_thread = CreateThread(NULL, 0, tts_thread_function,
539 (PVOID)nParameter, 0, &dwThreadID);
540 CloseHandle(tts_thread);
541 }
542 return TRUE;
543 case FL_PUSHBACK:
544 /* Move back to previous utterance */
545 if (flowm_utt_pos_pos > 0)
546 { /* Jump back to beginning of previous utt (we know about) */
547 flowm_utt_pos_pos--;
548 flowm_file_pos = flowm_prev_utt_pos[flowm_utt_pos_pos];
549 }
550 else if (flowm_file_pos > 1)
551 /* Not got any previous -- we never payed that bit get */
552 /* so just jump back 100 chars */
553 flowm_file_pos -= 100;
554 else /* At start of file already */
555 flowm_file_pos = 0;
556 wsprintf(fl_fp_msg,L"%2.3f",flowm_find_file_percentage());
557 SetDlgItemText(TTSWindow, FL_FILEPOS, fl_fp_msg);
558 flowm_play_status = FLOWM_BACKSKIP;
559 return TRUE;
560 case FL_PUSHFORWARD:
561 /* Skip forward to next utterances now */
562 if ((flowm_play_status == FLOWM_PLAY) ||
563 (flowm_play_status == FLOWM_SKIP))
564 flowm_play_status = FLOWM_SKIP; /* already playing/skipping */
565 else
566 { /* No playing so just jump forward 100 chars */
567 flowm_file_pos += 100;
568 wsprintf(fl_fp_msg,L"%2.3f",flowm_find_file_percentage());
569 SetDlgItemText(TTSWindow, FL_FILEPOS, fl_fp_msg);
570 }
571 return TRUE;
572 case FL_PUSHSTOP:
573 flowm_play_status = FLOWM_STOP;
574
575 return TRUE;
576 case FL_SCREENOFF:
577 /* turn off the screen */
578 DisplayOff();
579 return TRUE;
580 case IDOK:
581 if (flowm_play_status == FLOWM_STOP)
582 { /* Only end if we are in stop mode */
583 TTSWindow = 0; /* just in case there is a race condition */
584 EndDialog(hwnd,0);
585 }
586 return TRUE; /* you need to press end to end */
587 case FL_PUSHEND:
588 case IDCANCEL:
589 flowm_play_status = FLOWM_STOP;
590 TTSWindow = 0; /* just in case there is a race condition */
591 EndDialog(hwnd,0);
592 return TRUE;
593 }
594 break;
595 }
596 return FALSE;
597 }
598
599 int WinMain(HINSTANCE hInstance,
600 HINSTANCE hPrevInstance,
601 LPWSTR lpCmdLine,
602 int nCmdShow)
603 {
604 MSG msg;
605 HWND hwndMain=0;
606 int rc;
607
608 rc = InitApp(hInstance);
609 if (rc) return rc;
610
611 hwndMain=InitInstance(hInstance,lpCmdLine, nCmdShow);
612 if (hwndMain == 0) return 0x10;
613
614 flowm_init(); /* Initialize the TTS system */
615
616 while (GetMessage(&msg,NULL,0,0))
617 {
618 TranslateMessage(&msg);
619 DispatchMessage(&msg);
620 }
621
622 flowm_terminate(); /* Close the TTS systems */
623
624 return msg.wParam;
625 }
626
627 int InitApp(HINSTANCE hInstance)
628 {
629 WNDCLASS wc;
630 HWND hWnd;
631
632 /* If already running, return */
633 hWnd = FindWindow(AppName,NULL);
634 if (hWnd)
635 {
636 SetForegroundWindow((HWND)(((DWORD)hWnd) | 0x01));
637 return -1;
638 }
639
640 wc.style = CS_VREDRAW | CS_HREDRAW;
641 wc.lpfnWndProc = MainWndProc; /* main callback function */
642 wc.cbClsExtra = 0;
643 wc.cbWndExtra = 0;
644 wc.hInstance = hInstance;
645 wc.hIcon = NULL;
646 wc.hCursor = LoadCursor(NULL, IDC_ARROW); /* Default cursor */
647 wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
648 wc.lpszMenuName = NULL; /* Menu name */
649 wc.lpszClassName = AppName; /* Window class name */
650
651 if (RegisterClass(&wc) == 0)
652 return 1;
653 else
654 return 0;
655 }
656
657 HWND InitInstance(HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow)
658 {
659 HWND hwnd;
660
661 hInst = hInstance;
662
663 hwnd = CreateWindow(AppName,
664 AppName,
665 WS_VISIBLE,
666 CW_USEDEFAULT, /* x position */
667 CW_USEDEFAULT, /* y position */
668 CW_USEDEFAULT, /* Initial width */
669 CW_USEDEFAULT, /* Initial height */
670 NULL, /* Parent */
671 NULL, /* Menu */
672 hInstance,
673 NULL); /* extra params */
674 if (!IsWindow(hwnd))
675 return 0; /* failed to create a window */
676
677 ShowWindow(hwnd, nCmdShow);
678 UpdateWindow(hwnd);
679
680 return hwnd;
681 }
682
683