|
-
November 12th, 2003, 05:37 AM
#1
How to close the console window?
I use CreateProcess to execute a DOS program and call WaitForSingleObject(..., INFINITE) to wait till it's finished.
But the console window remains open until I close it manually.
How to close the console without my interation?
If I hide the DOS program using the CreateProcess, WaitForSingleObject will wait forever as the hidden console is not closed.
Any way to close the console so that WaitForSingleObject can continue?
How do I know that the process has finished before the console can be closed if it is hidden?
Last edited by Kurosan; November 12th, 2003 at 06:04 AM.
-
November 12th, 2003, 05:44 AM
#2
Maybe you can do it using function system("Exit") defined in <stdlib.h>
-
November 12th, 2003, 06:30 AM
#3
I use CreateProcess to execute a DOS program and call WaitForSingleObject(..., INFINITE) to wait till it's finished.
But the console window remains open until I close it manually.
How to close the console without my interation?
If I hide the DOS program using the CreateProcess, WaitForSingleObject will wait forever as the hidden console is not closed.
Any way to close the console so that WaitForSingleObject can continue?
How do I know that the process has finished before the console can be closed if it is hidden?
quite tricky! probably you can try this dirty solution.
call WaitForSingleObject in a loop with some timeout value (say every 100 milli-seconds). just below send WM_CHAR messages for exit. (like SendMessage(hWnd, WM_CHAR, 'e', 0) . it is assumed that you'll get hwnd of that console window somehow.
Code:
CreateProcess(...);
HWND hWnd = NULL;
do
{
WaitForSingleObject(..., 100);
hWnd = GetConsoleWindowSomeHow(); //dont know how. may be from hprocess (not sure)..
if (hWnd)
{
PostMessage(hWnd, WM_CHAR, 'e', 0);
PostMessage(hWnd, WM_CHAR, 'x', 0);
PostMessage(hWnd, WM_CHAR, 'i', 0);
PostMessage(hWnd, WM_CHAR, 't', 0);
}
} while (hWnd);
i really dont know if this works, but just give a try.
-john.
-
November 12th, 2003, 06:50 AM
#4
You can use SetConsoleTitle and FindWindow to get the console HWND and then use
SendMessage( hWnd, WM_CLOSE, VK_LEFT, 0 );
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|