【发布时间】:2015-10-05 09:22:34
【问题描述】:
我曾经看过一部叫《战争游戏》的电影。我想模仿电影中的那个程序。我写了一个简单的程序,可以打印然后说出句子,或者反过来。我希望程序同时执行两者。我该怎么做?
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <Windows.h>
#include <sapi.h>
ISpVoice *pVoice = NULL;
void printSmoothly(wchar_t *Str);
int main(void)
{
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL,
IID_ISpVoice, (void **)&pVoice);
wchar_t *sentence = L"Greetings professor falken,What would you like to do ?";
// how can i execute these two at the same time ?
printSmoothly(sentence);
pVoice->Speak(sentence, 0, NULL);
pVoice->Release();
CoUninitialize();
return 0;
}
void printSmoothly(wchar_t *Str)
{
size_t len = wcslen( Str ) , n ;
for( n = 0 ; n < len ; n++ )
{
wprintf( L"%c", Str[n] );
Sleep(50);
}
}
【问题讨论】:
-
您所说的“C/C++”是什么?您真正使用哪种语言?
-
我更喜欢 C,你知道的。
-
那么让我们开始吧。包括
wchar.h,将“C/C++”更改为“C”并删除c++ 标签。然后你将不得不对这些成员函数做一些事情。
标签: c windows multiprocessing sapi