Skip to content

Instantly share code, notes, and snippets.

@ydakoukn
Created October 2, 2016 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydakoukn/1880918f8b91c59d9dae4c4313b696e9 to your computer and use it in GitHub Desktop.
Save ydakoukn/1880918f8b91c59d9dae4c4313b696e9 to your computer and use it in GitHub Desktop.
Consoleウィンドウ表示
#include <iostream>
#include <Windows.h>
#include <io.h>
#include <fcntl.h>
#include "ConsoleWindow.h"
int ConsoleWindow::m_hConsole = 0;
ConsoleWindow::ConsoleWindow(){
m_hConsole = 0;
}
ConsoleWindow::ConsoleWindow(ConsoleWindow& other){
}
ConsoleWindow::~ConsoleWindow(){
this->Close();
m_hConsole = 0;
}
void ConsoleWindow::Create(){
::AllocConsole();
m_hConsole = ::_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
*stdout = *::_fdopen(m_hConsole, "w");
setvbuf(stdout, NULL, _IONBF, 0);
return;
}
void ConsoleWindow::Close(){
if (m_hConsole)
{
::_close(m_hConsole);
}
return;
}
#ifndef _CONSOLEWINDOW_H
#define _CONSOLEWINDOW_H
class ConsoleWindow
{
public:
ConsoleWindow();
ConsoleWindow(ConsoleWindow&);
~ConsoleWindow();
static void Create();
static void Close();
private:
static int m_hConsole;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment