关闭

MFC 程序自启动外部程序的问题

526人阅读 评论(0) 收藏 举报
分类:

方法:

//获得程序安装的路径,注册表
BOOL COpenBurnIntestDlg::GetBurnInTestInstallPath(CString&path)
{
#define INSTALL_PATH_SIZE (256)

 CStringkeyPath(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\BurnInTest_is1"));
 //HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\BurnInTest_is1
 DWORD ulOptions = 0L;
 HKEY hKey = NULL;
 DWORD samDesired = KEY_READ;

 if( m_bIs64bitOS )
 {
  samDesired |=KEY_WOW64_64KEY;
 }
 else
 {
  samDesired |=KEY_WOW64_32KEY;
 }


 LONG hRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyPath, ulOptions, samDesired, &hKey);
 if(hRet != ERROR_SUCCESS)
 {
#ifdef ABORT_DEBUG_TEST
  return false;
#endif
 }

 DWORD ulType = REG_SZ;
 TCHAR tcPath[INSTALL_PATH_SIZE];
 DWORD ulSize = INSTALL_PATH_SIZE;
 hRet =RegQueryValueEx(hKey,_T("DisplayIcon"),NULL,&ulType,(LPBYTE)tcPath,&ulSize);
 RegCloseKey(hKey);
 if(hRet != ERROR_SUCCESS)
 {
#ifdef ABORT_DEBUG_TEST
  return false;
#else
  CString tmp(_T("C:\\ProgramFiles\\BurnInTest\\bit.exe"));
  _tcscpy_s(tcPath,tmp.GetString());
#endif
 }

 path.Format(_T("%s"),tcPath);
 return true;
}

 

//运行程序
void COpenBurnIntestDlg::Run()
{
 CString strInstallPath;

 //获取 BurnInTest的文件路径
 if ( !GetBurnInTestInstallPath(strInstallPath))
 {
  SaveXmlResult.SaveTxt(_T("BurnInTesthas not installed yet!"));
  return;
 }

 //运行程序
 STARTUPINFO startInfo = {
  sizeof(STARTUPINFO)
 };

 PROCESS_INFORMATION processInfo;

 if( !CreateProcess( NULL,strInstallPath.GetBuffer(), NULL, NULL,
      NULL,0, NULL, NULL, &startInfo, &processInfo) )
 {
  return;
 }

 WaitForSingleObject(processInfo.hProcess,5000);
 CloseHandle(processInfo.hProcess);
 CloseHandle(processInfo.hThread);

 if( IsTheClassTimeout( WINDWO_TITLE_MAIN, 120,2L) )
 {
  return;
 }

 if( !IsTimeout( _T("Error"), 3, 1L) )
 {
  ClickButton( _T("Error"),m_ptrButtonOK );
 }

 if( !m_registrationCode.IsEmpty() )
 {
  if( !IsTimeout(WINDOW_TITLE_REGISTRATION, 18, 2L ) )
  {
   HWNDhRegistWin = ::FindWindow( NULL, WINDOW_TITLE_REGISTRATION );
   if(hRegistWin )
   {
    HWNDhRegistEdit = ::GetDlgItem(hRegistWin,WIDGET_REGISTRATION_EDITID);
    if(hRegistEdit )
    {
     ::SendMessage(hRegistEdit, WM_SETTEXT, m_registrationCode.GetLength(),(LPARAM)m_registrationCode.GetBuffer()); 
     Sleep(2000);
    }
   }
  }
 }

 ///注册界面
 if( ClickButton( WINDOW_TITLE_REGISTRATION,_T("Continue") ) )
 {
  if( IsTimeout( _T("Thanks"), 5,1L) )
  {
   if(ClickButton(_T("Invalid license information"), _T("OK")) )
   {
    SaveXmlResult.SaveTxt(_T("Invalid license information") );
    ClickButton(WINDOW_TITLE_REGISTRATION, _T("Exit BurnInTest"));
    return;
   }

   if(ClickButton(_T("Evaluation expired"), m_ptrButtonOK) )
   {
    SaveXmlResult.SaveTxt(_T("Evaluationexpired"));
    ClickButton(WINDOW_TITLE_REGISTRATION, _T("Exit BurnInTest"));
    return;
   }
  }
  else
  {
   ClickButton(_T("Thanks"), m_ptrButtonOK );
  }
 }
 

 Sleep(2000);
 //弹出一个框框
 //CUtil::ClickButton(_T("SystemInformation"),Button_OK);

 //记录 主窗体句柄
 HWND hMainWnd = ::FindWindow( WINDWO_TITLE_MAIN,NULL );
 //点击配置页面
 if( !SelectToolBarItem(hMainWnd,TOOLBAR_TEST_SELECTION_AND_DUTY_CYCLES) )
 {
  return;
 }
 //清楚所有选项 All Off
 ClickButton(WINDOW_TITLE_TEST_SELECTION_AND_DUTY_CYCLES,_T("All Off"));
 HWND hCfgWin = ::FindWindow(NULL,WINDOW_TITLE_TEST_SELECTION_AND_DUTY_CYCLES );

 //读取xml 对 BurnInTest 设置
 SetWidget(m_minutes, m_XmlRoot, hCfgWin);
 SetWidget(m_cycles, m_XmlRoot, hCfgWin);
 SetWidget(m_CPU, m_XmlRoot, hCfgWin);
 SetWidget(m_opticalDrives, m_XmlRoot,hCfgWin);
 SetWidget(m_printer, m_XmlRoot, hCfgWin);
 SetWidget(m_RAM, m_XmlRoot, hCfgWin);
 SetWidget(m_COMPort, m_XmlRoot, hCfgWin);
 SetWidget(m_tape, m_XmlRoot, hCfgWin);
 SetWidget(m_video, m_XmlRoot, hCfgWin);
 SetWidget(m_plugIn, m_XmlRoot, hCfgWin);
 SetWidget(m_2DGraphics, m_XmlRoot,hCfgWin);
 SetWidget(m_3DGraphics, m_XmlRoot,hCfgWin);
 SetWidget(m_disks, m_XmlRoot, hCfgWin);
 SetWidget(m_sound, m_XmlRoot, hCfgWin);
 SetWidget(m_network, m_XmlRoot, hCfgWin);
 SetWidget(m_parallelPort, m_XmlRoot,hCfgWin);
 SetWidget(m_USB, m_XmlRoot,hCfgWin); 

 ClickButton(WINDOW_TITLE_TEST_SELECTION_AND_DUTY_CYCLES, _T("OK") );
 Sleep(2000);

 hCfgWin = ::FindWindow( NULL,WINDOW_TITLE_TEST_SELECTION_AND_DUTY_CYCLES );
 while( hCfgWin )
 {
  if( !IsTimeout(_T("Warning -Possible conflict"), 3, 1L) )
  {
   ClickButton(_T("Warning - Possible conflict"), m_ptrButtonOK );
  }
  else
  {
   ClickButton(WINDOW_TITLE_TEST_SELECTION_AND_DUTY_CYCLES, _T("OK") );
  }

  Sleep(1000);
  hCfgWin = ::FindWindow( NULL,WINDOW_TITLE_TEST_SELECTION_AND_DUTY_CYCLES );
 }


 //ClickButton( _T("Possible permissionsproblem"), m_ptrButtonYes );
 //ClickButton( _T("Warning - Possible conflict"),m_ptrButtonOK );


 //如果测试时 选择disk 硬盘 这一选项。 则 Preferences 中 的Disk  要全部选择

 CXmlNodeWrapper xmlDisks =m_XmlRoot.GetNode(m_disks.GetXmlMark());
 if( xmlDisks.IsValid() )
 {
  SetTestPreferencesDisk(hMainWnd );
 }

 //点击 toolbar 中 的启动
 SelectToolBarItem(hMainWnd,TOOLBAR_START_SELECTED_TESTS);
 ClickButton( WINDOW_TITLE_READY_TO_RUN,m_ptrButtonOK);

 CStringstrWndTitleOXPS(WINDOW_TITLE_SAVE_PRINT_OUTPUT);
 TCHAR tcFileSaveAs[MAX_PATH] = {0};
 LoadString(NULL,OBIT_IDS_SAVE_FILE_AS,tcFileSaveAs,MAX_PATH);
 CString strWndTitleMDI(tcFileSaveAs);

 // 0x1 oxps, 0x2 mdi 0x3 both
 INT iFlag = E_SAVE_PRINT_BOTH;
 HWND hResultWnd = NULL;

 do{
  hResultWnd = ::FindWindow(NULL, WINDOW_TITLE_TEST_RESULT );

  HWND hPrint = NULL;
  
  if( iFlag &E_SAVE_PRINT_OXPS )
  {
   hPrint =::FindWindow(NULL, strWndTitleOXPS );
   if( hPrint)
   {
    iFlag= E_SAVE_PRINT_OXPS;
    SavePrintOutput(hPrint,E_SAVE_PRINT_OXPS);
   }
  }

  if( iFlag &E_SAVE_PRINT_MDI )
  {
   hPrint =::FindWindow(NULL, strWndTitleMDI );
   if( hPrint)
   {
    iFlag= E_SAVE_PRINT_MDI;
    SavePrintOutput(hPrint,E_SAVE_PRINT_MDI);
   }
  }

  Sleep(2000);

 }while( NULL == hResultWnd );


 if( E_SAVE_PRINT_BOTH != iFlag )
 {
  CStringstrWndTitle(_T(""));
  if(iFlag &E_SAVE_PRINT_OXPS)
   strWndTitle =strWndTitleOXPS;
  else
  if( iFlag &E_SAVE_PRINT_MDI )
   strWndTitle =strWndTitleMDI;

  if( !strWndTitle.IsEmpty())
   if(!IsTimeout(strWndTitle, 5, 1L) )
    SavePrintOutput(::FindWindow(NULL,strWndTitle ), iFlag);
 }


 ClickButton(WINDOW_TITLE_TEST_RESULT, _T("OK"),true);

 if( !SelectToolBarItem( hMainWnd,TOOLBAR_SAVE_RESULTS_AS_A_RESULT_LOG ) )
 {
  return;
 }


 //保存运行结果
 Sleep(1000);
 SaveBurnInTestResult();


 //Test Zhaobin
 return;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1048346次
    • 积分:18294
    • 等级:
    • 排名:第521名
    • 原创:741篇
    • 转载:523篇
    • 译文:0篇
    • 评论:105条
    最新评论