Esempio n. 1
0
BOOL KFunction::ShellRunApp(LPCTSTR szPath, LPCTSTR szFile, LPCTSTR szCmd)
{
	CString strExePath(szPath);	
	
	KFunction::PathAddBackslash(strExePath);
	strExePath += szFile;

	int nRetCode = (int)::ShellExecute(NULL, _T("open"), strExePath, szCmd, szPath, SW_HIDE);

	return nRetCode > 32;
}
Esempio n. 2
0
void CFileOpenDlg::OnBnClickedButtonbrowse()
{
	CFileDialog	dlg(TRUE,_T(".exe"),NULL,OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_FORCESHOWHIDDEN | OFN_HIDEREADONLY,
		_T("可执行文件 (*.exe)|*.exe|所有文件 (*.*)|*.*||"),this);
	if (dlg.DoModal() != IDOK)
	{
		return;
	}

	CString strExePath(dlg.GetPathName());
	SetDlgItemText(IDC_EDITFILEPATH,strExePath);

	SetDlgItemText(IDC_EDITRUNDIR,strExePath.Left(strExePath.ReverseFind('\\')+1));
}
Esempio n. 3
0
BOOL KFunction::RunApp(LPCTSTR szPath, LPCTSTR szFile, LPCTSTR szCmd, DWORD dwWaitTime /* = 0 */)
{
	BOOL bReturn = FALSE;
	STARTUPINFO si = { 0 };
	PROCESS_INFORMATION pi = { 0 };

	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;

	CString strExePath(szPath);	
	KFunction::PathAddBackslash(strExePath);
	strExePath += szFile;
	strExePath += _T(" ");
	strExePath += szCmd;

	bReturn = CreateProcessW(NULL,			// No module name (use command line). 
		(LPWSTR)(LPCTSTR)strExePath,      // Command line. 
		NULL,             // Process handle not inheritable. 
		NULL,             // Thread handle not inheritable. 
		TRUE,             // Set handle inheritance to FALSE. 
		0,                // No creation flags. 
		NULL,             // Use parent's environment block. 
		szPath,             // Use parent's starting directory. 
		&si,              // Pointer to STARTUPINFO structure.
		&pi				// Pointer to PROCESS_INFORMATION structure.
		);
	if (bReturn)
	{
		::WaitForSingleObject(pi.hThread, dwWaitTime);
	}

Exit0:
	if (pi.hProcess != NULL)
	{
		CloseHandle(pi.hProcess);
		pi.hProcess = NULL;
	}
	if (pi.hThread != NULL)
	{
		CloseHandle(pi.hThread);
		pi.hThread = NULL;
	}

	log_w(L"CreateProcess return:%d, path:%s, file:%s, cmd:%s\n", bReturn, szPath, szFile, szCmd);
	return bReturn;
}
Esempio n. 4
0
HINSTANCE CMultiLanguage::LoadLangResourceDLL(LPCTSTR szModuleName, LANGID langUpdateId)
{
    TCHAR       szResDLLName[_MAX_PATH+14];
    HINSTANCE   hLangDLL = NULL;
    LCID        alcid[MAX_NUM_LCID+1];
    TCHAR       szLangCode[4];
    //LPTSTR    pszExtension;
    int         nNoExtension;
    LCID        lcid;
    int         nLocales = 0;

    //pszExtension = ::PathFindExtension(szModuleName);
    //nNoExtension = pszExtension - szModuleName;   temp. for ".exe"
    nNoExtension = lstrlen(szModuleName) - 3 ;  // Quick and kind of dirty way to take ".exe"/".dll" away.

    /* Get executable name */
    CString strExePath(szModuleName);
    int nPos = strExePath.ReverseFind(_T('\\'));
    CString strExeName = strExePath.Right(strExePath.GetLength() - nPos - 1);
    strExeName = strExeName.Left(strExeName.GetLength() - 4 );  // Get rid of .exe extension

    if ( langUpdateId != MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL) )
    {
        alcid[nLocales] = MAKELCID(langUpdateId, SORT_DEFAULT);
        nLocales++;
    }
    for ( int iLocale = 0; iLocale < m_nLocales; iLocale++ )
    {
        if ( m_alcidSearch[iLocale] != 0 )
        {
            alcid[nLocales] = m_alcidSearch[iLocale];
            nLocales++;
        }
    }
    for ( int iLocale = 0; iLocale < nLocales; iLocale++ )
    {
        lcid = alcid[iLocale];
        if (lcid == LOCALE_SYSTEM_DEFAULT)
        {
            lstrcpy(szLangCode, _T("LOC"));
        }
        else
        {
            int nResult = ::GetLocaleInfo(lcid, LOCALE_SABBREVLANGNAME, szLangCode, 4);
            ASSERT( nResult == 4 );
            if ( nResult == 0 )
            {
                return NULL;
            }
        }
        if ( nNoExtension + 3 + 4 + 1 < _MAX_PATH+14 )
        {
            // append "ENU.DLL" to moduleName
            lstrcpyn(szResDLLName, szModuleName, nNoExtension - strExeName.GetLength());
            lstrcat(szResDLLName, szLangCode);
            lstrcat(szResDLLName, _T("\\"));
            lstrcat(szResDLLName, strExeName);
            lstrcat(szResDLLName, szLangCode);
            lstrcat(szResDLLName, _T(".DLL"));
        }
        else
        {
            ASSERT(FALSE);  // No enough space to hold language resource dll name path.
            return NULL;
        }
        hLangDLL = ::LoadLibrary(szResDLLName);
        if(hLangDLL != NULL)
        {
            return hLangDLL;    // Successful return
        }
    }

    return hLangDLL;
}
Esempio n. 5
0
CChildAttachDialogMan::CChildAttachDialogMan(void)
{
	m_arrAttachDlgInfoData.RemoveAll();
	CString strIni;
	TCHAR strModuleFileName[MAX_PATH];
	TCHAR strDriver[MAX_PATH];
	TCHAR strPath[MAX_PATH];
	GetModuleFileName(NULL,strModuleFileName,MAX_PATH);
	_tsplitpath_s(strModuleFileName, strDriver,_countof(strDriver), strPath,_countof(strPath),NULL,0,NULL,0);
	_tcscat_s(strDriver,_countof(strDriver),strPath);
	_tcscat_s(strDriver,_countof(strDriver),_T("process.ini"));  
	strIni=strDriver;
	int groupCount = GetPrivateProfileInt(_T("group"),_T("count"),0,strIni);
	int nMaxColumns = GetPrivateProfileInt(_T("group"),_T("maxColumn"),0,strIni);
	if(nMaxColumns<1)nMaxColumns = 3;
	for (int i=0;i<groupCount;i++)
	{
		//read group INFO
		stGroupInfo *pInfo = new stGroupInfo;
		TCHAR strTemp[255];
		CString strkeyName;
		strkeyName.Format(_T("groupname_%d"),i);
		GetPrivateProfileString(_T("group"),strkeyName,_T(""),strTemp,255,strIni);
		pInfo->nGroupID = i;
		pInfo->strGroupName = strTemp;
		pInfo->n_MaxColumns = nMaxColumns;
		m_mapGroupInfo[i] = pInfo;
	}
	stGroupInfo *pUnKnownGroupInfo = new stGroupInfo;
	pUnKnownGroupInfo->nGroupID = 20140409;//magicNum 组id 不会到这个数吧。
	pUnKnownGroupInfo->strGroupName=_T("UnKnownGroup");
	std::pair<std::map<int,stGroupInfo*>::iterator,bool> retInsertMap
		= m_mapGroupInfo.insert(std::pair<int,stGroupInfo*>(pUnKnownGroupInfo->nGroupID,pUnKnownGroupInfo));

	int processCount = GetPrivateProfileInt(_T("process"),_T("count"),0,strIni);
	BOOL bHadUnKnownGroupInfo=FALSE;
	for (int i=0;i<processCount;i++)
	{
		TCHAR strTemp[255];
		CString strAppName;
		strAppName.Format(_T("process_%d"),i);
		GetPrivateProfileString(strAppName,_T("path"),_T(""),strTemp,255,strIni);
		//这里需要去掉路径中的多余斜杠
		getRealPath(strTemp);
		CString strExePath(strTemp);
		if(strExePath.IsEmpty() || strExePath.GetLength()<3)//c:\1.exe
		{		
			continue;
		}

		GetPrivateProfileString(strAppName,_T("displayname"),_T(""),strTemp,255,strIni);
		int nGroupID = GetPrivateProfileInt(strAppName,_T("groupID"),pUnKnownGroupInfo->nGroupID,strIni);

		AttachDlgInfoData *lpData = new AttachDlgInfoData;

		lpData->strExePath =  strExePath;

		std::map<int ,stGroupInfo*>::iterator it ;
		it = m_mapGroupInfo.find(nGroupID);
		if(it !=m_mapGroupInfo.end())
			lpData->pstGroupInfo =it->second;
		else{
			lpData->pstGroupInfo = pUnKnownGroupInfo;
			bHadUnKnownGroupInfo = TRUE;
		}
		lpData->nInGroupPos = lpData->pstGroupInfo->AddRef();
		
		lpData->pAttachDlg = NULL;
		CMSVDlg*pDlg = new CMSVDlg();
		pDlg ->Create(IDD_MSVDLG);
		lpData->pAttachDlg = pDlg;
		AddToArr(lpData);
	}
	if(!bHadUnKnownGroupInfo && retInsertMap.second){
		m_mapGroupInfo.erase(retInsertMap.first);
	}

/*
 normal
 [group]
 count=
 groupname_0=
 groupname_1=

 [process]
 count=1

 [process_0]
 path=
 displayname=
 groupname=
 groupID=

 */

}