Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

How to find whether the parent process is GUI or Console

2.36/5 (5 votes)
10 Apr 2009CPOL 124.4K  
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"));
}

License

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