|
楼主 |
发表于 2014-7-3 11:46:53
|
显示全部楼层
- BOOL CXPage1::OnStartSaoMiaoBtnClick(HELE hEle,HELE hEleEvent)
- {
- //WCHAR* aa=XStatic_GetText(CXPage1::m_hEdit);
- if (XEdit_IsEmpty(CXPage1::m_hEdit))
- {
- return false;
- }
- BOOL bRet = FALSE;
- USES_CONVERSION;
- WCHAR szCmdPath[MAX_PATH] = {0};
- GetSystemDirectory(szCmdPath, sizeof(szCmdPath));
- PathAppend(szCmdPath, L"cmd.exe");
- SECURITY_ATTRIBUTES SecurityAttributes;
- SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
- SecurityAttributes.lpSecurityDescriptor = NULL;
- SecurityAttributes.bInheritHandle = TRUE;
- HANDLE hRead = NULL;
- HANDLE hWrite = NULL;
- WCHAR pszCommand[] = L"ping 127.0.0.1 -t";
- WCHAR pszResult[256]=L"";
- DWORD dwCount=_countof(pszResult);
- if(CreatePipe(&hRead, &hWrite, &SecurityAttributes, 0))
- {
- STARTUPINFO StartupInfo = {0};
- StartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
- StartupInfo.hStdOutput = hWrite;
- StartupInfo.hStdError = hWrite;
- StartupInfo.wShowWindow = SW_HIDE;
- PROCESS_INFORMATION ProcessInformation = {0};
- WCHAR szCurrentPath[MAX_PATH] = {0};
- GetCurrentDirectory(sizeof(szCurrentPath), szCurrentPath);
-
- if(CreateProcess(NULL, pszCommand, NULL, NULL, TRUE, 0, NULL, szCurrentPath, &StartupInfo, &ProcessInformation))
- {
- CloseHandle(hWrite);
- char szBuffer[4096] = {0};
- DWORD dwRead = 0;
- string tmp;
- string strBuffer;
- if(pszResult)
- {
- pszResult[0] = 0;
-
- while(TRUE)
- {
- memset(szBuffer, 0, sizeof(szBuffer));
- bRet = ReadFile(hRead, szBuffer, sizeof(szBuffer), &dwRead, NULL);
- if((FALSE == bRet) || (dwRead = 0))
- break;
- int pos=0,found=0,i=0;
- strBuffer="";
- strBuffer = szBuffer;
- while(found!=string::npos)
- {
- tmp="";
- found = strBuffer.find("\n",pos);
- tmp=strBuffer.substr(pos,found-pos);
- memset(pszResult, 0, _countof(pszResult));
- wcscat_s(pszResult, dwCount, A2W(tmp.c_str()));
- XList_AddItem(CXPage1::m_hList,pszResult,i);
- pos=found+1;
- i++;
- XEle_RedrawEle(CXPage1::m_hList,true);
-
- }
-
-
- }
- }
- }
-
-
- CloseHandle(hRead);
- }
- //free(strBuff);
-
- return true;
- }
复制代码
|
|