-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxtread.cpp
829 lines (749 loc) · 24.8 KB
/
txtread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
//////////////////////////////////////////////////////////////////////////////////
//
// The main class for the text reader application
//
// Author P.J.Lawrence Feb 2007 Email P.J.Lawrence@gre.ac.uk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose
// and to alter it and redistribute it freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
//
//////////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <shellapi.h>
#include <commctrl.h>
#include "resource.h"
///////////////////////////////////////////////////////////////////////////////////
#include <atlbase.h> // ATL
#include <sapi.h> // SAPI includes
#include <sphelper.h>
#include <spuihelp.h>
///////////////////////////////////////////////////////////////////////////////////
#include <string>
#include "dlgtxtctrl.h"
#include "voiceclass.h"
#include "txtreader.h"
//////////////////////////////////////////////////////////////////////////////////
WinTextReader_Class::WinTextReader_Class()
{
m_hInst=NULL;
m_VoiceClass=NULL;
m_nIDHotKey=0;
m_MainControlDlg=NULL;
m_SystemWindow=NULL;
m_TxtWindow=NULL;
m_CurrentTxt.assign("");
m_AllTxt.assign("");
m_AboutBox=NULL;
m_HotKeyBox=NULL;
LoadedUsersSetting=false;
m_CurrentVoiceIndex=0;
m_CurrentFormatIndex=18;
m_UserVolume = 100;
m_UserRate = 3;
m_HotKeyCode = 'S'; // was T changed to S for windows 7
m_HotKeyModifier = MOD_WIN;
m_KeepText=true;
LoadInitialSettings();
}
//////////////////////////////////////////////////////////////////////////////////
WinTextReader_Class::~WinTextReader_Class()
{
SaveInitialSettings();
ShutDownWindowInterface();
}
//////////////////////////////////////////////////////////////////////////////////
void WinTextReader_Class::SetMainControlDlg(HWND aWin)
{
m_MainControlDlg = aWin;
if (m_MainControlDlg==NULL)
{
if (m_TxtWindow)
{
delete m_TxtWindow;
m_TxtWindow=NULL;
}
}
}
//////////////////////////////////////////////////////////////////////////////////
//
// Store the current settings for the voice control
//
BOOL WinTextReader_Class::UpdateVoiceSettings()
{
if (m_VoiceClass)
{
m_UserVolume=m_VoiceClass->GetVolume();
m_UserRate = m_VoiceClass->GetRate();
CComPtr<ISpStreamFormat> cpStream;
HRESULT hrOutputStream = m_VoiceClass->GetcpVoice()->GetOutputStream(&cpStream);
if (hrOutputStream == S_OK)
{
CSpStreamFormat Fmt;
HRESULT hr = Fmt.AssignFormat(cpStream);
if (SUCCEEDED(hr))
{
SPSTREAMFORMAT eFmt = Fmt.ComputeFormatEnum();
for(int i=0; i<NUM_OUTPUTFORMATS; i++ )
{
if( g_aOutputFormat[i] == eFmt )
{
m_CurrentFormatIndex=i;
}
}
}
}
return (TRUE);
}
return (FALSE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL WinTextReader_Class::SaveInitialSettings()
{
LONG lRetVal;
HKEY hkResult;
lRetVal = RegCreateKeyEx( HKEY_CURRENT_USER,
_T("SOFTWARE\\T2SReader"), 0, NULL, 0,
KEY_ALL_ACCESS, NULL, &hkResult, NULL );
if( lRetVal == ERROR_SUCCESS )
{
RegSetValueEx( hkResult, _T("HotKey"), NULL, REG_DWORD, (PBYTE) &m_HotKeyCode, sizeof(m_HotKeyCode) );
RegSetValueEx( hkResult, _T("HotKeyModifier"), NULL, REG_DWORD, (PBYTE) &m_HotKeyModifier, sizeof(m_HotKeyModifier) );
RegSetValueEx( hkResult, _T("KeepText"), NULL, REG_DWORD, (PBYTE) &m_KeepText, sizeof(m_KeepText) );
return(TRUE);
}
return(FALSE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL WinTextReader_Class::LoadInitialSettings()
{
LONG lRetVal;
HKEY hkResult;
DWORD size;
LoadedUsersSetting=false;
lRetVal = RegCreateKeyEx( HKEY_CURRENT_USER,
_T("SOFTWARE\\T2SReader"), 0, NULL, 0,
KEY_ALL_ACCESS, NULL, &hkResult, NULL );
if( lRetVal == ERROR_SUCCESS )
{
if (lRetVal == ERROR_SUCCESS)
{
size = sizeof(m_HotKeyCode);
lRetVal = RegQueryValueEx( hkResult, _T("HotKey"), NULL, NULL, (PBYTE) &m_HotKeyCode, &size );
}
if (lRetVal == ERROR_SUCCESS)
{
size = sizeof(m_HotKeyModifier);
lRetVal = RegQueryValueEx( hkResult, _T("HotKeyModifier"), NULL, NULL, (PBYTE) &m_HotKeyModifier, &size );
}
if (lRetVal == ERROR_SUCCESS)
{
size = sizeof(m_KeepText);
lRetVal = RegQueryValueEx( hkResult, _T("KeepText"), NULL, NULL, (PBYTE) &m_KeepText, &size );
}
if (lRetVal == ERROR_SUCCESS)
{
return (TRUE);
}
}
return (FALSE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL WinTextReader_Class::SaveSpeechSettings()
{
LONG lRetVal;
HKEY hkResult;
lRetVal = RegCreateKeyEx( HKEY_CURRENT_USER,
_T("SOFTWARE\\T2SReader"), 0, NULL, 0,
KEY_ALL_ACCESS, NULL, &hkResult, NULL );
if( lRetVal == ERROR_SUCCESS )
{
RegSetValueEx( hkResult, _T("Voice"), NULL, REG_DWORD, (PBYTE) &m_CurrentVoiceIndex, sizeof(m_CurrentVoiceIndex) );
RegSetValueEx( hkResult, _T("VoiceFormat"), NULL, REG_DWORD, (PBYTE) &m_CurrentFormatIndex, sizeof(m_CurrentFormatIndex) );
// Ensure voice settings are up to date
UpdateVoiceSettings();
RegSetValueEx( hkResult, _T("Volume"), NULL, REG_DWORD, (PBYTE) &m_UserVolume, sizeof(m_UserVolume) );
RegSetValueEx( hkResult, _T("Rate"), NULL, REG_DWORD, (PBYTE) &m_UserRate, sizeof(m_UserRate) );
return(TRUE);
}
return(FALSE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL WinTextReader_Class::LoadSpeechSettings()
{
LONG lRetVal;
HKEY hkResult;
DWORD size;
LoadedUsersSetting=false;
lRetVal = RegCreateKeyEx( HKEY_CURRENT_USER,
_T("SOFTWARE\\T2SReader"), 0, NULL, 0,
KEY_ALL_ACCESS, NULL, &hkResult, NULL );
if( lRetVal == ERROR_SUCCESS )
{
if (lRetVal == ERROR_SUCCESS)
{
size = sizeof(m_CurrentVoiceIndex);
lRetVal = RegQueryValueEx( hkResult, _T("Voice"), NULL, NULL, (PBYTE) &m_CurrentVoiceIndex, &size );
}
if (lRetVal == ERROR_SUCCESS)
{
size = sizeof(m_CurrentFormatIndex);
lRetVal = RegQueryValueEx( hkResult, _T("VoiceFormat"), NULL, NULL, (PBYTE) &m_CurrentFormatIndex, &size );
}
if (lRetVal == ERROR_SUCCESS)
{
size = sizeof(m_UserVolume);
lRetVal = RegQueryValueEx( hkResult, _T("Volume"), NULL, NULL, (PBYTE) &m_UserVolume, &size );
}
if (lRetVal == ERROR_SUCCESS)
{
size = sizeof(m_UserRate);
lRetVal = RegQueryValueEx( hkResult, _T("Rate"), NULL, NULL, (PBYTE) &m_UserRate, &size );
}
if (lRetVal == ERROR_SUCCESS)
{
LoadedUsersSetting=true;
return (TRUE);
}
}
return (FALSE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL WinTextReader_Class::SaveDialogueCurrentStatus()
{
if (m_MainControlDlg)
{
RECT TheRect;
if (IsIconic(m_MainControlDlg) || IsZoomed(m_MainControlDlg) || GetWindowRect(m_MainControlDlg,&TheRect)==0)
{
return (FALSE);
}
LONG lRetVal;
HKEY hkResult;
lRetVal = RegCreateKeyEx( HKEY_CURRENT_USER,
_T("SOFTWARE\\T2SReader"), 0, NULL, 0,
KEY_ALL_ACCESS, NULL, &hkResult, NULL );
if( lRetVal == ERROR_SUCCESS )
{
TheRect.right-=TheRect.left;
TheRect.bottom-=TheRect.top;
RegSetValueEx( hkResult, _T("WinLeftPos"),NULL, REG_DWORD, (PBYTE) &TheRect.left, sizeof(TheRect.left) );
RegSetValueEx( hkResult, _T("WinTopPos"), NULL, REG_DWORD, (PBYTE) &TheRect.top, sizeof(TheRect.top) );
RegSetValueEx( hkResult, _T("WinWidth"), NULL, REG_DWORD, (PBYTE) &TheRect.right, sizeof(TheRect.right) );
RegSetValueEx( hkResult, _T("WinHeight"), NULL, REG_DWORD, (PBYTE) &TheRect.bottom, sizeof(TheRect.bottom) );
return(TRUE);
}
}
return(FALSE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL WinTextReader_Class::LoadDialogueCurrentStatus(bool RetoreWindowStatus)
{
if (m_MainControlDlg)
{
LONG lRetVal;
HKEY hkResult;
DWORD size;
lRetVal = RegCreateKeyEx( HKEY_CURRENT_USER,
_T("SOFTWARE\\T2SReader"), 0, NULL, 0,
KEY_ALL_ACCESS, NULL, &hkResult, NULL );
if( lRetVal == ERROR_SUCCESS )
{
RECT TheRect;
GetWindowRect(m_MainControlDlg,&TheRect);
TheRect.right-=TheRect.left;
TheRect.bottom-=TheRect.top;
size = sizeof(TheRect.left);
lRetVal = RegQueryValueEx( hkResult, _T("WinLeftPos"),NULL, NULL, (PBYTE) &TheRect.left, &size );
if (lRetVal == ERROR_SUCCESS)
lRetVal = RegQueryValueEx( hkResult, _T("WinTopPos"), NULL, NULL, (PBYTE) &TheRect.top, &size);
if (lRetVal == ERROR_SUCCESS)
lRetVal = RegQueryValueEx( hkResult, _T("WinWidth"), NULL, NULL, (PBYTE) &TheRect.right, &size );
if (lRetVal == ERROR_SUCCESS)
lRetVal = RegQueryValueEx( hkResult, _T("WinHeight"), NULL, NULL, (PBYTE) &TheRect.bottom, &size );
if (TheRect.left<0)
{
TheRect.left=0;
}
if (TheRect.top<0)
{
TheRect.top=0;
}
if (TheRect.right<DlgMinXVal)
{
TheRect.right=DlgMinXVal;
}
if (TheRect.bottom<DlgMinYVal)
{
TheRect.bottom=DlgMinYVal;
}
if (RetoreWindowStatus && lRetVal == ERROR_SUCCESS)
{
SetWindowPos(m_MainControlDlg,HWND_TOP,TheRect.left,TheRect.top,TheRect.right,TheRect.bottom,SWP_SHOWWINDOW);
}
if (lRetVal == ERROR_SUCCESS)
return (TRUE);
}
}
return (FALSE);
}
///////////////////////////////////////////////////////////////////////////////////
bool WinTextReader_Class::InitTxtWindow()
{
if (m_TxtWindow)
{
m_TxtWindow->Clear();
m_TxtWindow->AppendText(m_AllTxt);
return (true);
}
return (false);
}
///////////////////////////////////////////////////////////////////////////////////
bool WinTextReader_Class::ClearHistory()
{
m_AllTxt.erase();
if (m_TxtWindow)
{
m_TxtWindow->Clear();
}
return (true);
}
///////////////////////////////////////////////////////////////////////////////////
bool WinTextReader_Class::ShutDownWindowInterface()
{
if (m_nIDHotKey>0)
{
if (UnregisterHotKey(m_SystemWindow, m_nIDHotKey)==0)
{
DWORD ErrCode=GetLastError();
m_nIDHotKey=0;
}
else
{
m_nIDHotKey=0;
}
}
if (m_VoiceClass)
{
UpdateVoiceSettings();
delete m_VoiceClass;
m_VoiceClass=NULL;
}
if (m_TxtWindow)
{
delete m_TxtWindow;
m_TxtWindow=NULL;
}
return (true);
}
///////////////////////////////////////////////////////////////////////////////////
bool WinTextReader_Class::StartUpWindowInterface(HWND aWnd)
{
m_SystemWindow=aWnd;
if (m_nIDHotKey==0)
{
m_nIDHotKey = GlobalAddAtom("T2SReader");
if (RegisterHotKey(m_SystemWindow, m_nIDHotKey, m_HotKeyModifier,m_HotKeyCode)==0)
{
// problem registering hot key
m_nIDHotKey=0;
MessageBox( NULL,
_T("Failed to register hot key.\r\nPlease select a new key.\r\nThe application could be already running or the currently\r\nset Hotkey could be in use by another program"),
_T("Error"), MB_OK );
DialogBox(m_hInst, (LPCTSTR)IDD_HOTKEYDIALOG, m_SystemWindow, (DLGPROC)HotKeyDlg);
if (m_nIDHotKey==0)
{
MessageBox( NULL,
_T("Failed to register hot key. Shutting down."),
_T("Error"), MB_OK );
return (false);
}
}
}
if (!m_VoiceClass)
{
HRESULT hr = S_FALSE;
m_VoiceClass = new VoiceClass();
if (m_VoiceClass)
{
hr = m_VoiceClass->InitSapi();
}
if( SUCCEEDED( hr ) )
{
m_VoiceClass->OnInit(m_SystemWindow);
}
else
{
// Error - shut down
MessageBox( NULL,
_T("Error initializing failed. Shutting down."),
_T("Error"), MB_OK );
return (FALSE);
}
if ( SUCCEEDED( hr ) )
{
m_VoiceClass->GetcpVoice()->SetNotifyWindowMessage(m_SystemWindow, WM_TalkingNoteAppCUSTOMEVENT, 0, 0 );
}
}
if (m_VoiceClass)
{
if (LoadedUsersSetting)
{
SetVoiceToInitSettings();
}
else
{
m_CurrentVoiceIndex = m_VoiceClass->GetDefaultVoiceIndex();
m_CurrentFormatIndex = m_VoiceClass->GetDefaultFormatIndex();
m_UserVolume = m_VoiceClass->GetDefaultVolume();
m_UserRate = m_VoiceClass->GetDefaultRate();
}
}
return (true);
}
///////////////////////////////////////////////////////////////////////////////////
bool WinTextReader_Class::SetVoiceToInitSettings()
{
if (m_VoiceClass)
{
// set voice to user's settings
HRESULT hr = S_OK;
CComPtr<IEnumSpObjectTokens> cpEnum;
//Enumerate the available voices
if(SUCCEEDED(hr))
hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum);
ULONG ulCount = 0;
//Get the number of voices
if(SUCCEEDED(hr))
hr = cpEnum->GetCount(&ulCount);
if (SUCCEEDED(hr) && m_CurrentVoiceIndex<ulCount)
{
CComPtr<ISpObjectToken> cpVoiceToken;
ULONG i;
for (i=0;(i<ulCount && SUCCEEDED(hr));i++)
{
cpVoiceToken.Release();
if(SUCCEEDED(hr))
hr = cpEnum->Next( 1, &cpVoiceToken, NULL );
if(SUCCEEDED(hr) && i == m_CurrentVoiceIndex)
{
hr = m_VoiceClass->GetcpVoice()->Speak( NULL, SPF_PURGEBEFORESPEAK, 0);
if(SUCCEEDED(hr))
{
hr = m_VoiceClass->GetcpVoice()->SetVoice(cpVoiceToken);
}
}
}
}
m_VoiceClass->SetVolume(m_UserVolume);
m_VoiceClass->SetRate(m_UserRate);
if (m_VoiceClass->GetcpOutAudio() && m_CurrentFormatIndex<NUM_OUTPUTFORMATS)
{
SPSTREAMFORMAT eFmt = g_aOutputFormat[m_CurrentFormatIndex];
CSpStreamFormat Fmt;
Fmt.AssignFormat(eFmt);
hr = m_VoiceClass->GetcpOutAudio()->SetFormat( Fmt.FormatId(), Fmt.WaveFormatExPtr() );
if( SUCCEEDED( hr ) )
{
hr = m_VoiceClass->GetcpVoice()->SetOutput( m_VoiceClass->GetcpOutAudio(), FALSE );
}
}
return (true);
}
return (false);
}
///////////////////////////////////////////////////////////////////////////////////
bool WinTextReader_Class::SetVoiceToSystemDefaults()
{
if (m_VoiceClass)
{
if (m_VoiceClass->SetToDefaults())
{
m_CurrentVoiceIndex = m_VoiceClass->GetDefaultVoiceIndex();
m_CurrentFormatIndex = m_VoiceClass->GetDefaultFormatIndex();
m_UserVolume = m_VoiceClass->GetDefaultVolume();
m_UserRate = m_VoiceClass->GetDefaultRate();
return (true);
}
}
return (false);
}
///////////////////////////////////////////////////////////////////////////////////
bool WinTextReader_Class::DoMenuCommand(int MenuCommand)
{
switch (MenuCommand)
{
case IDM_EXIT:
DestroyWindow(m_SystemWindow);
return(true);
case IDD_SHOW:
if (m_MainControlDlg)
{
if (IsIconic(m_MainControlDlg))
{
OpenIcon(m_MainControlDlg);
}
BringWindowToTop(m_MainControlDlg);
}
else
{
DialogBox(m_hInst, (LPCTSTR)IDD_VOICEDIALOG, NULL, (DLGPROC)MainControlDlg);
}
return(true);
case IDD_HIDE:
if (m_MainControlDlg)
{
SendMessage(m_MainControlDlg,WM_CLOSE,0,0);
}
return(true);
case IDD_ClearHistory:
m_AllTxt.erase();
m_CurrentTxt.erase();
if (m_TxtWindow)
{
m_TxtWindow->Clear();
}
return (true);
case IDD_KeepText:
m_KeepText=!m_KeepText;
if (m_MainControlDlg)
{
HMENU hmenu = GetMenu(m_MainControlDlg);
if (hmenu)
{
HMENU hpopup = GetSubMenu(hmenu, 0);
if (hpopup)
{
if (m_KeepText)
{
CheckMenuItem(hmenu,IDD_KeepText,MF_CHECKED | MF_BYCOMMAND);
}
else
{
CheckMenuItem(hmenu,IDD_KeepText,MF_UNCHECKED | MF_BYCOMMAND);
}
}
}
}
return (true);
case IDD_TEST:
if (m_VoiceClass)
{
m_VoiceClass->TestVoice();
}
return(true);
case IDD_REPEAT:
m_VoiceClass->Speak(m_CurrentTxt);
return (true);
case IDD_Halt:
m_VoiceClass->Stop();
return (true);
case IDD_RESETVOICEINIT:
LoadSpeechSettings();
if (LoadedUsersSetting)
{
SetVoiceToInitSettings();
}
else
{
SetVoiceToSystemDefaults();
}
if (m_MainControlDlg)
{
SendMessage(m_MainControlDlg,WM_COMMAND,ID_RESET,0);
}
break;
case IDD_RESETVOICESYS:
SetVoiceToSystemDefaults();
if (m_MainControlDlg)
{
SendMessage(m_MainControlDlg,WM_COMMAND,ID_RESET,0);
}
break;
case IDD_HOTKEY:
if (m_HotKeyBox)
{
BringWindowToTop(m_HotKeyBox);
}
else
{
DialogBox(m_hInst, (LPCTSTR)IDD_HOTKEYDIALOG, m_SystemWindow, (DLGPROC)HotKeyDlg);
}
break;
case IDD_ABOUTBOX:
if (m_AboutBox)
{
BringWindowToTop(m_AboutBox);
}
else
{
DialogBox(m_hInst, (LPCTSTR)IDD_ABOUTBOX, m_SystemWindow, (DLGPROC)About);
}
return(true);
}
return (false);
}
///////////////////////////////////////////////////////////////////////////////////
BOOL WinTextReader_Class::TalkClipBoardData()
{
HGLOBAL hglb;
if (IsClipboardFormatAvailable(CF_TEXT))
{
if (!OpenClipboard(NULL))
return(FALSE);
hglb = GetClipboardData(CF_TEXT);
if (hglb != NULL)
{
char* lptstr = (char*) GlobalLock(hglb);
if (lptstr != NULL)
{
if (m_VoiceClass->IsProcessing())
{
m_VoiceClass->Stop();
}
m_CurrentTxt.assign(lptstr);
GlobalUnlock(hglb);
if (m_KeepText)
{
m_AllTxt.append(m_CurrentTxt);
}
else
{
m_AllTxt.assign(m_CurrentTxt);
}
m_VoiceClass->Speak(m_CurrentTxt.c_str());
if (m_TxtWindow)
{
if (!m_KeepText)
m_TxtWindow->Clear();
m_TxtWindow->AppendText(m_CurrentTxt.c_str());
}
}
CloseClipboard();
if (lptstr)
{
return(TRUE);
}
}
}
else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
{
hglb = GetClipboardData(CF_UNICODETEXT);
if (hglb != NULL)
{
WCHAR *wStr = (WCHAR*) GlobalLock(hglb);
if (wStr != NULL)
{
m_VoiceClass->Speak(wStr);
GlobalUnlock(hglb);
}
CloseClipboard();
if (wStr)
{
return(TRUE);
}
}
}
return(FALSE);
}
///////////////////////////////////////////////////////////////////////////////////
//
// Handles the WM_TalkingNoteAppCUSTOMEVENT application defined message and all
// of it's appropriate SAPI5 events.
//
void WinTextReader_Class::MainHandleSynthEvent()
{
CSpEvent event; // helper class in sphelper.h for events that releases any
// allocated memory in it's destructor - SAFER than SPEVENT
SPVOICESTATUS Stat;
WPARAM nStart;
LPARAM nEnd;
int i = 0;
HRESULT hr = S_OK;
if (!m_VoiceClass)
return;
while( event.GetFrom(m_VoiceClass->GetcpVoice()) == S_OK )
{
switch( event.eEventId )
{
case SPEI_START_INPUT_STREAM:
break;
case SPEI_END_INPUT_STREAM:
// Set global boolean stop to TRUE when finished speaking
m_VoiceClass->SetStopFlag(TRUE);
/*
// Highlight entire text
nStart=m_SelStart;
nEnd=m_SelEnd;
SendDlgItemMessage( m_hWnd, IDE_EDITBOX, EM_SETSEL, nStart, nEnd );
*/
break;
case SPEI_VOICE_CHANGE:
break;
case SPEI_TTS_BOOKMARK:
break;
case SPEI_WORD_BOUNDARY:
if (m_TxtWindow)
{
hr = m_VoiceClass->GetcpVoice()->GetStatus( &Stat, NULL );
if (SUCCEEDED( hr ))
{
// Highlight word
nStart = (LPARAM)( Stat.ulInputWordPos / sizeof(char) ) + m_AllTxt.length()-m_CurrentTxt.length();
nEnd = nStart + Stat.ulInputWordLen;
m_TxtWindow->HighlightTxt(nStart,nEnd);
}
}
break;
case SPEI_PHONEME:
break;
case SPEI_VISEME:
break;
case SPEI_SENTENCE_BOUNDARY:
break;
case SPEI_TTS_AUDIO_LEVEL:
break;
case SPEI_TTS_PRIVATE:
break;
default:
// Unknown message
break;
}
}
}
///////////////////////////////////////////////////////////////////////////////////
//
// This function handles the volume and rate controls
//
void WinTextReader_Class::HandleScroll(HWND hCtl)
{
long hpos = 1;
HWND hVolume, hRate;
HRESULT hr = S_OK;
// Get the current position of the slider
hpos = SendMessage( hCtl, TBM_GETPOS, 0, 0 );
// Get the Handle for the scroll bar so it can be associated with an edit box
hVolume = GetDlgItem( m_MainControlDlg, IDC_VOLUME_SLIDER );
hRate = GetDlgItem( m_MainControlDlg, IDC_RATE_SLIDER );
if( hCtl == hVolume )
{
m_VoiceClass->SetVolume((USHORT)hpos);
}
else if( hCtl == hRate )
{
m_VoiceClass->SetRate(hpos);
}
return;
}