MCPcopy Create free account
hub / github.com/DFHack/dfhack / init

Method init

library/Console-windows.cpp:446–515  ·  view source on GitHub ↗

// DOESN'T WORK - locks up DF! void ForceForegroundWindow(HWND window) { DWORD nForeThread, nAppThread; nForeThread = GetWindowThreadProcessId(GetForegroundWindow(), 0); nAppThread = ::GetWindowThreadProcessId(window,0); if(nForeThread != nAppThread) { AttachThreadInput(nForeThread, nAppThread, true); BringWindowToTop(window); ShowWindow(window,3);

Source from the content-addressed store, hash-verified

444}
445*/
446bool Console::init(bool)
447{
448 d = new Private();
449 int hConHandle;
450 intptr_t lStdHandle;
451 CONSOLE_SCREEN_BUFFER_INFO coninfo;
452 FILE *fp;
453 DWORD oldMode, newMode;
454 DWORD dwTheardId;
455
456 HWND h = ::GetTopWindow(0 );
457 while ( h )
458 {
459 DWORD pid;
460 dwTheardId = ::GetWindowThreadProcessId( h,&pid);
461 if ( pid == GetCurrentProcessId() )
462 {
463 // here h is the handle to the window
464 break;
465 }
466 h = ::GetNextWindow( h , GW_HWNDNEXT);
467 }
468 d->MainWindow = h;
469
470 // Allocate a console!
471 AllocConsole();
472 d->ConsoleWindow = GetConsoleWindow();
473 wlock = new std::recursive_mutex();
474 HMENU hm = GetSystemMenu(d->ConsoleWindow,false);
475 DeleteMenu(hm, SC_CLOSE, MF_BYCOMMAND);
476
477 // force console code pages to utf-8
478 SetConsoleCP(CP_UTF8);
479 SetConsoleOutputCP(CP_UTF8);
480
481 // set the screen buffer to be big enough to let us scroll text
482 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
483 d->default_attributes = coninfo.wAttributes;
484 coninfo.dwSize.Y = MAX_CONSOLE_LINES; // How many lines do you want to have in the console buffer
485 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
486
487 // redirect unbuffered STDOUT to the console
488 d->console_out = GetStdHandle(STD_OUTPUT_HANDLE);
489 lStdHandle = (intptr_t)d->console_out;
490 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
491 d->dfout_C = _fdopen( hConHandle, "w" );
492 setvbuf( d->dfout_C, NULL, _IONBF, 0 );
493
494 // redirect unbuffered STDIN to the console
495 d->console_in = GetStdHandle(STD_INPUT_HANDLE);
496 lStdHandle = (intptr_t)d->console_in;
497 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
498 fp = _fdopen( hConHandle, "r" );
499 *stdin = *fp;
500 setvbuf( stdin, NULL, _IONBF, 0 );
501 GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),&oldMode);
502 newMode = oldMode | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT;
503 SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),newMode);

Callers

nothing calls this directly

Calls 1

clearFunction · 0.70

Tested by

no test coverage detected