C++ How to minimized sapisvr.exe (Window Speech Recognition) while code start?
<p>Good Evening,
As the title says it, I'm trying to make the "window"(Not really sure it was a window) of process of <strong>sapisvr.exe</strong> which is known as the <strong>Window Speech Recognition</strong>, to start as minimized when this code:</p>

<pre><code>system("start /min C:\\CMUSphinx\\pocketsphinx\\bin\\Debug\\WSRMacros");
</code></pre>

<p>trigger the software to open.</p>

<p>Well I know there's a way call <strong><code>ShowWindow(hwnd,SW_MINIMIZED)</code></strong> which it need the process id and the window handle of the process in order to do the minimized I desire.
But here's the question, does the <strong>sapisvr.exe</strong> have multiple window handle on one process? because the way I did it's not working. I found it's ProcessId compare it and it was correct but the Windows Speech Recognition just won't minimized while run.</p>

<p>So here's my code for "minimized" the sapisvr.exe(which it din't work) which it include the get process id and window handle function.   </p>

<pre><code>#include&lt;Windows.h&gt;
#include&lt;tlhelp32.h&gt;
#pragma comment(lib, "user32.lib")

void GetProcId(char* ProcName);
DWORD ProcId = -1;
HWND hwnd = NULL;


void GetProcId(LPCTSTR ProcName)
{
       PROCESSENTRY32   pe32;
       HANDLE         hSnapshot = NULL;

       pe32.dwSize = sizeof( PROCESSENTRY32 );
       hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

       if( Process32First( hSnapshot, &amp;pe32 ) )
       {
          do{
                    if( wcsicmp( pe32.szExeFile, ProcName ) == 0 )
                          break;
              }while( Process32Next( hSnapshot, &amp;pe32 ) );
       }

       if( hSnapshot != INVALID_HANDLE_VALUE )
               CloseHandle( hSnapshot );

       ProcId = pe32.th32ProcessID;
}

BOOL CALLBACK GetWindowFromProcess(HWND hWnd, LPARAM lParam)
{
       static HWND hWndFound;
       static DWORD dwPIDMatch;

       if(lParam != 0){
               dwPIDMatch = (DWORD)hWnd;
               if(EnumWindows(GetWindowFromProcess, 0))
                        return FALSE;
               *(HWND *)lParam = hWndFound;
       }else{
               DWORD dwPID = 0;
               GetWindowThreadProcessId(hWnd, &amp;dwPID);
               if(dwPIDMatch == dwPID){
                       hWndFound = hWnd;
                       return FALSE;
               }
       }
       return TRUE;
}

int main()
{
               system("start /min C:\\CMUSphinx\\pocketsphinx\\bin\\Debug\\WSRMacros");  //change your own Speech Recognition directory
               LPCTSTR ProcessNamei = TEXT("sapisvr.exe");
               GetProcId(ProcessNamei);
               GetWindowFromProcess((HWND)ProcId,(DWORD)&amp;hwnd);
               ShowWindow(hwnd,SW_SHOWMINIMIZED);
               ShowWindow(hwnd,SW_HIDE);
}
</code></pre>

<p>Sorry for the lengthy post, it doesn't have any spoiler function. :(</p>

<p>Have a nice weekend and Merry Christmas. </p>
