以对话框程序a为例:
1、重载CAApp::InitInstance 代码如下:
BOOL CAApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
/*
__argc 表示个数
__argv 表示参数
__argv[0] 就是你启动应用程序的完整路径
__argv[1] 传入的一个参数
__argv[n] 传入的第n-1个参数
*/
for(int i=0; i<__argc; i++)
{
TRACE(_T("arg%d = %s\\n"), i, __argv[i]);
}
CADlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
2、按下“ALT+F7”打开“Projet Settings” 切换到Debug选项卡,在Program arguments下的文本框中输入"a b c",点击“OK” 退出。
3、按下"F5"运行程序,可以看到Debug窗口输出:
Loaded 'C:\\Windows\\System32\\msctf.dll', no matching symbolic information found.
Loaded 'C:\\Windows\\System32\\MFC42LOC.DLL', no matching symbolic information found.
arg0 = D:\\Documents\\Microsoft Visual Studio\\MyProjects\\a\\Debug\\a.exe
arg1 = a
arg2 = b
arg3 = c
Loaded 'C:\\Windows\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\\comctl32.dll', no matching symbolic information found.
Loaded 'C:\\Windows\\System32\\advapi32.dll', no matching symbolic information found.
注意:本文归作者所有,未经作者允许,不得转载