Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows


10.1.4..The Command Line.............................................................................


To execute a program, you must communicate its path and possibly some additional
parameters to the compiler. This information is called the command line information and
it is supplied as a string. You need to keep that in mind although all programs of this
book will be compiled inside of Visual C++. The command line information is supplied
to the compiler as the lpCmdLine argument of the WinMain() function. Internally, Visual
C++ creates the path and communicates it to the compiler when you execute the program.
If you want to find out what command line was used to execute your program, you can
call the Win32's GetCommandLine() function. Its syntax is:

LPTSTR GetCommandLine(VOID);

This function takes no argument but returns the command line of an application as null-
terminated string. Here is an example:

void CCommandLineDlg::OnBtnCmdLine()
{
// TODO: Add your control notification handler code here
char CmdLine[80];
char CmdResult[80];

strcpy(CmdLine, GetCommandLine());
sprintf(CmdResult, "%s", CmdLine);
m_CommandLine.Format("%s", CmdResult);

UpdateData(FALSE);
}
Free download pdf