VC 程序片断

来源:百度文库 编辑:神马文学网 时间:2024/06/30 21:30:46
/*获取命令行参数, 如果是-a, 则自动运行*/
 int CommandLineCount = 0;
 LPWSTR * m_lpCommandLine = ::CommandLineToArgvW(GetCommandLineW(), &CommandLineCount);
 BOOL result = FALSE;
 CString m_strCommandLine;
 //获取参数行命令
 for(int i = 0; i < CommandLineCount; i ++)
 {
  m_strCommandLine = m_lpCommandLine[i];
  if(0 == m_strCommandLine.MakeLower().Compare(_T("-a")))
  {
   OutPutLog(_T("Auto run!"), TEST_LOG);
   OnBnClickedStartchange();
  }
  else if(0 == m_strCommandLine.MakeLower().Compare(_T("-bi")))
  { //begin index
   m_strCommandLine = m_lpCommandLine[++ i];
   m_dwCurMaxRecordId = atol(m_strCommandLine.GetString());
  }
 } //---> //设置应用程序所在目录为当前目录
 TCHAR strCurFileNameCh[255];
 GetModuleFileName(NULL, strCurFileNameCh, 255);
 CString strCurFileName = strCurFileNameCh;
 if(!strCurFileName.IsEmpty())
 {
  int nIndex = 0;
  int nOIndex;
  while(nIndex >= 0)
  {
   nOIndex = nIndex;
   nIndex = strCurFileName.Find('\\', nIndex + 1);
  }
  SetCurrentDirectory(strCurFileName.Left(nOIndex + 1));
 }