Thread View: borland.public.cppbuilder.nativeapi
14 messages
14 total messages
Started by Richard Casten
Tue, 14 Mar 2006 19:52
Finding whether Console app has a window
Author: Richard Casten
Date: Tue, 14 Mar 2006 19:52
Date: Tue, 14 Mar 2006 19:52
7 lines
1331 bytes
1331 bytes
I have a console application that is either executed in a console window or is executed from another application using CreateProcess with the creation flag set to CREATE_NO_WINDOW so that there is no window for which the console application to write standard output. My question is how, within the console application, to determine if the application was created with the CREATE_NO_WINDOW flag.
Re: Finding whether Console app has a window
Author: Remy Lebeau (TeamB)
Date: Wed, 15 Mar 2006 01:27
Date: Wed, 15 Mar 2006 01:27
16 lines
1376 bytes
1376 bytes
"Richard Casten" <richard.casten@aero.org> wrote in message news:44171EF9.DD8A51D0@aero.org... > CreateProcess with the creation flag set to CREATE_NO_WINDOW Keep in mind that CREATE_NO_WINDOW is not supported on Win9x/ME. > how, within the console application, to determine if the application > was created with the CREATE_NO_WINDOW flag. Use GetStdHandle() or CreateFile() to retreive the process's console handles and then check if they are assigned or not. Gambit
Re: Finding whether Console app has a window
Author: Richard Casten
Date: Thu, 30 Mar 2006 23:42
Date: Thu, 30 Mar 2006 23:42
8 lines
1162 bytes
1162 bytes
"Remy Lebeau (TeamB)" wrote: > Use GetStdHandle() or CreateFile() to retreive the process's console handles > and then check if they are assigned or not. How do I determine if they are assigned or not?
Re: Finding whether Console app has a window
Author: Bob Gonder
Date: Fri, 31 Mar 2006 00:15
Date: Fri, 31 Mar 2006 00:15
16 lines
1570 bytes
1570 bytes
Richard Casten wrote: >"Remy Lebeau (TeamB)" wrote: > >> Use GetStdHandle() or CreateFile() to retreive the process's console handles >> and then check if they are assigned or not. > >How do I determine if they are assigned or not? Return value should be INVALID_HANDLE_VALUE Note that the stdin/stdout might be redirected, with no visible console, and the above would return valid handles. Depending on your needs, you might see if GetConsoleTitle() returns an error if no console is visible.
Re: Finding whether Console app has a window
Author: Richard Casten
Date: Fri, 31 Mar 2006 17:20
Date: Fri, 31 Mar 2006 17:20
23 lines
1673 bytes
1673 bytes
Bob Gonder wrote: > Richard Casten wrote: > > >"Remy Lebeau (TeamB)" wrote: > > > >> Use GetStdHandle() or CreateFile() to retreive the process's console handles > >> and then check if they are assigned or not. > > > >How do I determine if they are assigned or not? > > Return value should be INVALID_HANDLE_VALUE > > Note that the stdin/stdout might be redirected, with no visible > console, and the above would return valid handles. GetStdHandle does not return INVALID_HANDLE_VALUE for any of the standard handles in this situation.. > Depending on your needs, you might see if GetConsoleTitle() returns an > error if no console is visible. GetConsoleTitle does not return in this situation.
Re: Finding whether Console app has a window
Author: Richard Casten
Date: Fri, 31 Mar 2006 17:41
Date: Fri, 31 Mar 2006 17:41
1 lines
1068 bytes
1068 bytes
Oops. GetConsoleTitle does not return an error in this situation.
Re: Finding whether Console app has a window
Author: Remy Lebeau (TeamB)
Date: Fri, 31 Mar 2006 19:02
Date: Fri, 31 Mar 2006 19:02
12 lines
1333 bytes
1333 bytes
"Richard Casten" <richard.casten@aero.org> wrote in message news:442D64E0.85D41157@aero.org... > GetStdHandle does not return INVALID_HANDLE_VALUE > for any of the standard handles in this situation.. It should if the process is not run in a console application, and the parent process is not redirecting the handles. Gambit
Re: Finding whether Console app has a window
Author: Richard Casten
Date: Fri, 31 Mar 2006 19:35
Date: Fri, 31 Mar 2006 19:35
18 lines
1734 bytes
1734 bytes
"Remy Lebeau (TeamB)" wrote:
> It should if the process is not run in a console application, and the parent
> process is not redirecting the handles.
Well it doesn't. This is the code I used to test:
ret = 0;
if(GetStdHandle(STD_INPUT_HANDLE) == INVALID_HANDLE_VALUE)
ret = 1;
else if(GetStdHandle(STD_OUTPUT_HANDLE) == INVALID_HANDLE_VALUE)
ret = 2;
else if(GetStdHandle(STD_ERROR_HANDLE) == INVALID_HANDLE_VALUE)
ret = 3;
The value of ret is 0. As a reminder from the initial message, this is a
console program but is being executed from a non-console program with the
CREATE_NO_WINDOW flag.
Re: Finding whether Console app has a window
Author: Richard Casten
Date: Mon, 03 Apr 2006 17:46
Date: Mon, 03 Apr 2006 17:46
7 lines
1181 bytes
1181 bytes
I found on the Microsoft website the article:
How To Obtain a Console Window Handle (HWND)
http://support.microsoft.com/default.aspx?scid=kb;en-us;124103
Using the console window handle in the function IsWindowVisible will
indicate whether the console is visible or not.
This solves my problem. Thanks for all the suggestions.
Re: Finding whether Console app has a window
Author: Richard Casten
Date: Wed, 05 Apr 2006 16:35
Date: Wed, 05 Apr 2006 16:35
8 lines
1229 bytes
1229 bytes
Boba wrote: > just have a question on that article: what if the application in > question does not let its console SetConsoleTitle in 40 ms? That's a good question. I guess the author thinks that is enough. I guess you could put a loop and not break out of the loop until hwndFound is not NULL.
Re: Finding whether Console app has a window
Author: Boba
Date: Wed, 05 Apr 2006 16:52
Date: Wed, 05 Apr 2006 16:52
10 lines
1471 bytes
1471 bytes
"Richard Casten" <richard.casten@aero.org> wrote in message news:4433F1D2.56C6B4ED@aero.org... > ... > That's a good question. I guess the author thinks that is enough. I > guess you could put a loop and not break out of the loop until hwndFound > is not NULL. > if you are after a robust code, then consider a possible console window management by the application running in that window. in my case i am the one who starts that application, so i have the process information.
Re: Finding whether Console app has a window
Author: Boba
Date: Wed, 05 Apr 2006 18:25
Date: Wed, 05 Apr 2006 18:25
12 lines
1498 bytes
1498 bytes
"Richard Casten" <richard.casten@aero.org> wrote in message news:44315F62.9A989B20@aero.org... > I found on the Microsoft website the article: > How To Obtain a Console Window Handle (HWND) > http://support.microsoft.com/default.aspx?scid=kb;en-us;124103 > Using the console window handle in the function IsWindowVisible will > indicate whether the console is visible or not. > > This solves my problem. Thanks for all the suggestions. just have a question on that article: what if the application in question does not let its console SetConsoleTitle in 40 ms?
Re: Finding whether Console app has a window
Author: Richard Casten
Date: Wed, 05 Apr 2006 18:35
Date: Wed, 05 Apr 2006 18:35
9 lines
1483 bytes
1483 bytes
Boba wrote: > if you are after a robust code, then consider a possible console window > management by the application running in that window. in my case i am > the one who starts that application, so i have the process information. I think I misread your first post. The code for finding the console window handle is in the application in question, i.e. my application, and hence I see no reason why the SetConsoleTitle would not work.
Re: Finding whether Console app has a window
Author: Boba
Date: Thu, 06 Apr 2006 16:55
Date: Thu, 06 Apr 2006 16:55
2 lines
1153 bytes
1153 bytes
sorry, i was talking 'bout an application started with CreateProcess call.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads