Click here to Skip to main content
15,881,861 members
Articles / Programming Languages / C++

How to find whether the parent process is GUI or Console

Rate me:
Please Sign up or sign in to vote.
2.36/5 (5 votes)
10 Apr 2009CPOL 123.9K   5   9
This is not 100% fool proof. How ever in normal cases, this works great.

This is not 100% fool proof. How ever in normal cases, this works great. This technique can be used to find out, whether the child application was launched from a GUI application or from a Console application.

if( AttachConsole( ATTACH_PARENT_PROCESS ))
{
     AfxMessageBox( _T("Parent process is a console application"));
}
else
{
     AfxMessageBox( _T("Parent process is not a console application"));
}
This article was originally posted at http://0memory.blogspot.com/feeds/posts/default?alt=rss

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Aoi Karasu 12-Jan-10 2:37
professional Aoi Karasu 12-Jan-10 2:37 
GeneralMy vote of 1 Pin
Blkbam9-Apr-09 5:10
Blkbam9-Apr-09 5:10 
GeneralRe: My vote of 1 Pin
Naveen10-Apr-09 5:19
Naveen10-Apr-09 5:19 
AnswerThe C# way Pin
Blkbam9-Apr-09 5:08
Blkbam9-Apr-09 5:08 
GeneralRe: The C# way Pin
Qistoph9-Apr-09 20:09
Qistoph9-Apr-09 20:09 
GeneralRe: The C# way Pin
Naveen10-Apr-09 5:22
Naveen10-Apr-09 5:22 
GeneralMy vote of 1 Pin
Qistoph8-Apr-09 22:41
Qistoph8-Apr-09 22:41 
GeneralRe: My vote of 1 Pin
Naveen10-Apr-09 5:18
Naveen10-Apr-09 5:18 
GeneralRe: My vote of 1 Pin
toxcct27-Apr-09 2:48
toxcct27-Apr-09 2:48 

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.