-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShell.h
107 lines (89 loc) · 2.11 KB
/
Shell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
namespace Easy {
class Shell
{
public:
Shell(void);
~Shell(void);
typedef enum SHELL_TYPE { CONSOLE = 0, APP };
/*!
* @brief Execute
*
* Execute a program
* @param sPath The path of program.
* @param sCommand The command line with program
* @param type The type of program to execute
* @param bShow Show the program window or not. Not work for all program.
* @return bool Execute success or not
*/
bool Execute(CString sPath, CString sCommand=_T(""), SHELL_TYPE type=APP, bool bShow=true, CString sWorkDirectory=_T(""));
/*!
* @brief IsRunning
*
* Is the program running
* @return bool True means running, false was not.
*/
bool IsRunning(void);
/*!
* @brief Stop
*
* Stop run the program.
* @return bool Stop success or not
*/
bool Stop(void);
/*!
* @brief GetOutput
*
* Get the program output, work for console application.
* @return CString The output string.
*/
CString GetOutput(void);
/*!
* @brief GetOutput
*
* Get the program window handle.
* @return HWND The window handle.
*/
HWND GetWnd(void);
/*!
* @brief GetLastError
*
* Get the last error code
* @return DWORD the error code
*/
DWORD GetLastError();
/*!
* @brief GetLastErrorMsg
*
* Get the last error message
* @return CString the error message
*/
CString GetLastErrorMsg();
private:
static DWORD WINAPI ShellThread(LPVOID lpParam);
static BOOL WINAPI EnumWindowsProc(HWND hWnd, LPARAM lParam);
bool ExecuteConsole(CString sPath, CString sCommand, bool bShow, CString sWorkDirectory);
bool ExecuteApplication(CString sPath, CString sCommand, bool bShow, CString sWorkDirectory);
/*!
* @brief GetSystemError
*
* used to get system error and save it
*/
void GetSystemError();
/*!
* @brief FormatLastError
*
* format the last error code to string
* @param dwLastError the error code want to format
* @return CString the error message
*/
CString FormatLastError(DWORD dwLastError);
CString m_sLastError;
DWORD m_nLastError;
PROCESS_INFORMATION m_pi;
HANDLE m_hRead;
bool m_bRunning;
HWND m_hWnd;
CString m_sOutput;
};
}