Repository navigation
Expand file tree
/
Copy pathAppThread.cpp
More file actions
107 lines (77 loc) · 2.63 KB
/
Copy pathAppThread.cpp
File metadata and controls
107 lines (77 loc) · 2.63 KB
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
// AppThread.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "AppThread.h"
#include "OperatorConsole.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// AppThread
BEGIN_MESSAGE_MAP(AppThread, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// AppThread construction
AppThread::AppThread()
{
// support Restart Manager
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
}
AppThread::~AppThread()
{
}
// The one and only AppThread object
AppThread theApp;
// AppThread initialization
BOOL AppThread::InitInstance()
{
#if 0
//TODO: call AfxInitRichEdit2() to initialize richedit2 library.
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
AfxInitRichEdit(); // this must be called once before displaying a dialog that uses RichEdit control
// Create the shell manager, in case the dialog contains
// any shell tree view or shell list view controls.
CShellManager *pShellManager = new CShellManager;
// Activate "Windows Native" visual manager for enabling themes in MFC controls
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
#else
CWinApp::InitInstance();
#endif
CreatePipes();
COperatorConsoleApp *thread = (COperatorConsoleApp *)AfxBeginThread(RUNTIME_CLASS(COperatorConsoleApp), 0, CREATE_SUSPENDED);
// thread->m_appInstance = hInstance;
thread->ResumeThread();
::WaitForSingleObject(thread->m_hThread, INFINITE);
// Delete the shell manager created above.
#if 0
if (pShellManager != NULL)
{
delete pShellManager;
}
#endif
return FALSE;
}
void AppThread::CreatePipes()
{
SECURITY_ATTRIBUTES saAttr;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
// Create a pipe for the child process's STDOUT.
// Ensure the read handle to the pipe for STDOUT is not inherited.
CreatePipe(&m_stdout_Rd, &m_stdout_Wr, &saAttr, 0);
SetHandleInformation(m_stdout_Rd, HANDLE_FLAG_INHERIT, 0);
CreatePipe(&m_stderr_Rd, &m_stderr_Wr, &saAttr, 0);
SetHandleInformation(m_stderr_Rd, HANDLE_FLAG_INHERIT, 0);
SetStdHandle(STD_OUTPUT_HANDLE, m_stdout_Wr);
SetStdHandle(STD_ERROR_HANDLE, m_stderr_Wr);
}