65.9K
CodeProject is changing. Read more.
Home

How to find whether the parent process is GUI or Console

Apr 8, 2009

CPOL
viewsIcon

124461

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"));
}