summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua_console.cpp
blob: 1a4fc5da1badb0156d4fc72d784155df732e8aec (plain)
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
#include "stdafx.h"

BOOL WINAPI ConsoleHandler(DWORD cEvent)
{
	return TRUE;
}

CMLuaConsole::CMLuaConsole(lua_State *L)
	: L(L), hConsole(NULL)
{
	if (db_get_b(NULL, MODULE, "ShowConsole", 0))
	{
		if (!AttachConsole(ATTACH_PARENT_PROCESS))
		{
			if (AllocConsole())
			{
				SetConsoleTitle(_T("MirLua Console"));
				freopen("CONOUT$", "w", stdout);
				hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
				if (HWND hConsoleWindow = GetConsoleWindow())
				{
					HMENU hConsoleMenu = GetSystemMenu(hConsoleWindow, FALSE);
					DeleteMenu(hConsoleMenu, SC_CLOSE, MF_BYCOMMAND);
				}
				SetConsoleCtrlHandler(ConsoleHandler, true);
			}
		}
	}
}

CMLuaConsole::~CMLuaConsole()
{
	if (hConsole)
		CloseHandle(hConsole);
	FreeConsole();
}