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
|
HANDLE hPipeRead,hPipeWrite;
SECURITY_ATTRIBUTES tSecur;
PROCESS_INFORMATION pi;
STARTUPINFO si;
char *lBuffer;
public:
console(string title)
{
static bool i=false;
AllocConsole();
if(i==true)
{
tSecur.nLength = sizeof(SECURITY_ATTRIBUTES);
tSecur.bInheritHandle = TRUE;
tSecur.lpSecurityDescriptor = NULL;
CreatePipe(&hPipeRead,&hPipeWrite,&tSecur,0);
ZeroMemory (&si,sizeof(STARTUPINFO));
ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
si.cb=sizeof(STARTUPINFO);
si.dwFlags |= STARTF_USESTDHANDLES ;
si.hStdInput = hPipeRead;
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
if (! CreateProcess(NULL,"cmd.exe",0,0,TRUE,CREATE_NEW_CONSOLE, NULL,NULL, &si, &pi))
{
DebugText("error: no console created!!! getlasterror: " + to_string(GetLastError()));
}
hConsole=hPipeRead;
windowconsole=GetHWNDConsole();
hdcwindow=GetDC(windowconsole);
}
else
{
hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
i=true;
}
HANDLE out=CreateFile(TEXT("CONOUT$"),GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
hConsole=out;
windowconsole=GetHWNDConsole();
hdcwindow=GetDC(windowconsole);
SetWindowText(windowconsole,title.c_str());
cls();
cout << "hello world";
DWORD srect;
WriteConsoleOutputCharacter(hConsole, "hello world" ,strlen("hello world"),{0,10},&srect);
}
|