1. Establish an MFC project
1. Select "MFC Application" to create a project;
2. Select "dialog based" for "application type" in the Wizard ";
3. Click "finish" to complete the wizard;
2. Add console debugging window
1. Add the header file:
# Include "conio. H"
2. Add the following to the oninitdialog function:Code:
Allocconsole (); cprintf ("init \ r \ n ");
:
3. Compile and runProgram, The effect is as follows:
3. Add command line parameter judgment
If the released program has a console window that looks strange, you can add command line parameters to the MFC program to determine whether to enable the console debugging window. Of course, you can also set "allocconsole (); "This line of code is commented out.
I have an example here, but I have determined the number of command line parameters. This reader can modify it as needed.
1. Add the following code to the oninitdialog function:
If (_ argc> 1) {allocconsole (); cprintf ("init \ r \ n ");}
Compile and run the program.
2. Running Effect
Here we mainly demonstrate the Running Effect of command line parameters:
You can also create a shortcut, add parameters to the properties, and double-click it:
Okay, that's all. I hope it will help you.