MFC and command line interaction

I would like to add a command line interface to my MFC application so that I can provide command line options. These options will determine how the application starts.

However, I cannot figure out how to interact with these two. How can I do this if possible?

+3
source share
3 answers

MFC has the CCommandLineInfo class for this: see the CCommandLineInfo documentation .

+8
source

Here's how I do it in MFC applications:

int option1_value;
BOOL option2_value;

if (m_lpCmdLine[0] != '\0')
{
     // parse each command line token
     char seps[] = " "; // spaces
     char *token;
     char *p;
     token = strtok(m_lpCmdLine, seps); // establish first token            
     while (token != NULL)
     {
          // check the option
          do    // block to break out of         
          {
               if ((p = strstr(strupr(token),"/OPTION1:")) != NULL)
               {
                    sscanf(p + 9,"%d", &option1_value);
                    break;
               }

               if ((p = strstr(strupr(token),"/OPTION2")) != NULL)
               {
                    option2_value = TRUE;
                    break;
               }
          }
          while(0); 

          token = strtok(NULL, seps);       // get next token           
     }
}   // end command line not empty
+2
source

CCommandLineInfo . TCALP (Templatized ++ Command Line Parser http://tclap.sourceforge.net/manual.html) program_options (http://www.boost.org/doc/libs/1_48_0/doc/html/program_options.html) , MFC ++, . TCLAP Windows, "/" POSIX, "-" (http://tclap.sourceforge.net/manual.html#CHANGING_STARTSTRINGS)

0

Source: https://habr.com/ru/post/1709851/


All Articles