ParseCommandLine
-
Kann mir mal jemand erklären, wie ich ParseCommandLine in einer MFC anwendung nutzen kann? Ich möchte die Kommandozeilenparameter, sofern vorhanden auslesen und anwenden.
Bisher schauts bei mir so aus:BOOL CHLRUSLG_SampleDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here CString temp_cmdLine, cmdLine = GetCommandLine(); int pos = cmdLine.Find( '/'); // letztes '/' finden m_ipos = pos; if (m_ipos==-1) { int n = cmdLine.GetLength(); cmdLine.Delete(0,n); } else { temp_cmdLine = cmdLine.Left(pos); // Anzahl der Zeichen bis zum '/' Zeichen cmdLine.Delete(0,pos+1); // Pfad abtrennen incl. '/' zeichen } if(cmdLine != "") { WithArgument(); } else { OnUpdate(); for (int i=1; i<=96; i++) { char a[10]; sprintf(a, "%d",i); ((CComboBox*) GetDlgItem(IDCE_SNUM))->AddString(a); } ((CComboBox*) GetDlgItem(IDCE_SNUM))->SetCurSel(0); for (int j=0; j<(96*3); j+=3) { slotList[j]=mv_sexp; slotList[j+1]=mv_sval; slotList[j+2]=mv_ssng; } this->UpdateData(false); } return TRUE; // return TRUE unless you set the focus to a control }
in der MSDN steht nur, wie es mit einer neuen MFC Anwendung funzt, und selbst das versteh ich nicht so ganz, da mein Englisch ein wenig verostet ist.
Gruß
Teddy
-
Hier mal ein paar Anregungen: (keywords für die suchmaschinen)
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);CCommandLineInfo hat einige Methoden ...
m_lpCmdLine ... ganze Parameterzeile (global)
__argv[] ... Parameterarray (global)
__argc ... Anzahl der Parameter (global)73,
Captn.