Click here to Skip to main content
16,011,804 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How can i know if a given PID have a window & how to get the handle of that window ? Pin
Tomasz Sowinski6-Mar-02 0:54
Tomasz Sowinski6-Mar-02 0:54 
AnswerThanx guys Pin
6-Mar-02 1:46
suss6-Mar-02 1:46 
GeneralDetecting when running from the command line Pin
Parish5-Mar-02 23:16
Parish5-Mar-02 23:16 
GeneralRe: Detecting when running from the command line Pin
Nish Nishant5-Mar-02 23:24
sitebuilderNish Nishant5-Mar-02 23:24 
GeneralRe: Detecting when running from the command line Pin
Parish5-Mar-02 23:54
Parish5-Mar-02 23:54 
GeneralRe: Detecting when running from the command line Pin
moliate6-Mar-02 1:05
moliate6-Mar-02 1:05 
GeneralRe: Detecting when running from the command line Pin
Joel Lucsy6-Mar-02 4:52
Joel Lucsy6-Mar-02 4:52 
GeneralRe: Detecting when running from the command line Pin
Parish6-Mar-02 20:22
Parish6-Mar-02 20:22 
I know that, and the code is there, but the problem is getting it to send the output to the correct place, i.e. the CMD window the app was started from.

I've found the reason *why* it doesn't work from reading the MSDN section about WinMain() but haven't found a solution.

When a win32 GUI app is run from the command prompt and I/O redirection is included *on the commandline*, e.g.

C:> myapp | more
C:> myapp > filename

then the apps starts with its' I/O linked to the pipe or redirect. However, if no redirection is included on the commandline then the app has no connection to the window (instance of cmd.exe) that it was started from. As the command prompt returns as soon as the app starts there appears to be no way, from within the app, of linking to the window it started from, they run as 2 unrelated tasks; even usning "START /W myapp" does not achieve the desired result.

This contrasts with Unix where the apps' I/O is connected to the shell it was started from by default, even if the app is started as a background task (so the command prompt returns immediately - normally this doesn't happen until the app exits). When starting from a menu or icon it is usual to redirect stdout and stderr to the console (myapp > /dev/console 2>&1) so you can see any messages.

If you put this simplified piece of code in WinMain() and run the app from a CMD window you will not see any output unless you redirect on the commandline:

if (__argc > 1)
{
printf("Hello, world\n");
exit(0);
}

......

I assume that, by default, std{out,err} go to NUL??





while (!asleep)
code();
GeneralFile names inside a folder.. Pin
Neha5-Mar-02 22:58
Neha5-Mar-02 22:58 
GeneralRe: File names inside a folder.. Pin
Nish Nishant5-Mar-02 23:18
sitebuilderNish Nishant5-Mar-02 23:18 
GeneralRe: File names inside a folder.. Pin
Mazdak6-Mar-02 0:29
Mazdak6-Mar-02 0:29 
GeneralSpinbutton and EN_CHANGE Pin
Arjan Schouten5-Mar-02 22:09
Arjan Schouten5-Mar-02 22:09 
GeneralCopy constructor ignored when passing by value to a function with unspecified number of arguments. Pin
Serge Krynine5-Mar-02 21:01
Serge Krynine5-Mar-02 21:01 
GeneralRe: Copy constructor ignored when passing by value to a function with unspecified number of arguments. Pin
Joaquín M López Muñoz5-Mar-02 21:38
Joaquín M López Muñoz5-Mar-02 21:38 
GeneralRe: Check this disassembly.... Pin
Atul Dharne6-Mar-02 0:04
Atul Dharne6-Mar-02 0:04 
GeneralRe: Copy constructor ignored when passing by value to a function with unspecified number of arguments. Pin
Serge Krynine6-Mar-02 14:41
Serge Krynine6-Mar-02 14:41 
GeneralCalling member function from CALLBACK function Pin
5-Mar-02 20:46
suss5-Mar-02 20:46 
GeneralRe: Calling member function from CALLBACK function Pin
5-Mar-02 20:53
suss5-Mar-02 20:53 
GeneralRe: Calling member function from CALLBACK function Pin
Michael Dunn6-Mar-02 7:28
sitebuilderMichael Dunn6-Mar-02 7:28 
GeneralDraw something on the button Pin
Rickard Andersson205-Mar-02 20:44
Rickard Andersson205-Mar-02 20:44 
GeneralRe: Draw something on the button Pin
Christian Graus6-Mar-02 10:30
protectorChristian Graus6-Mar-02 10:30 
GeneralI want to Write CToolBar class from the scratch Pin
Abhishek Narula5-Mar-02 19:34
Abhishek Narula5-Mar-02 19:34 
GeneralRe: I want to Write CToolBar class from the scratch Pin
Christian Graus5-Mar-02 20:09
protectorChristian Graus5-Mar-02 20:09 
GeneralRe: I want to Write CToolBar class from the scratch Pin
Abhishek Narula5-Mar-02 20:33
Abhishek Narula5-Mar-02 20:33 
GeneralRe: I want to Write CToolBar class from the scratch Pin
Christian Graus5-Mar-02 20:31
protectorChristian Graus5-Mar-02 20:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.