extern void ConsoleInit(void) { CONSOLE_CURSOR_INFO cci; int i; /* コンソール標準出力画面のハンドルを取得。プログラム終了時にアクティブ化 */ m_hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); if (m_hStdOut == INVALID_HANDLE_VALUE) { fprintf(stderr, "error: Console: InitConsole: hStdOut: %ld\n", GetLastError()); } /* コンソールスクリーンの作成と初期化 */ for (i=0; i<NUM_SCREEN_MAX; i++) { m_hScreen[i] = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); if (m_hScreen[i] == INVALID_HANDLE_VALUE) { fprintf(stderr, "error: Console: InitConsole: %ld\n", GetLastError()); } /* カーソル情報の初期化 */ GetConsoleCursorInfo(m_hScreen[i], &cci); cci.bVisible = FALSE;// カーソルの非表示 SetConsoleCursorInfo(m_hScreen[i], &cci); /* ウィンドウサイズの初期化 */ SetWindowSize(m_hScreen[i], NUM_WINDOW_HEIGHT, NUM_WINDOW_WIDTH); /* コンソールモードの初期化 */ SetConsoleMode(m_hScreen[i], ENABLE_PROCESSED_OUTPUT); } m_hScreenIndex = 0; m_hOut = m_hScreen[1]; m_hWork = m_hScreen[0]; SetConsoleActiveScreenBuffer(m_hOut);// 出力スクリーンをアクティブ化 }
void System::CreateBuffer(short width, short height) { srWidth = width; srHeight = height; CONSOLE_CURSOR_INFO cci; COORD size = { srWidth, srHeight }; SMALL_RECT rect; rect.Left = 0; rect.Top = 0; rect.Right = srWidth - 1; rect.Bottom = srHeight - 1; hBuffer[0] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); SetConsoleScreenBufferSize(hBuffer[0], size); SetConsoleWindowInfo(hBuffer[0], TRUE, &rect); hBuffer[1] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); SetConsoleScreenBufferSize(hBuffer[1], size); SetConsoleWindowInfo(hBuffer[1], TRUE, &rect); cci.dwSize = 1; cci.dwSize = FALSE; SetConsoleCursorInfo(hBuffer[0], &cci); SetConsoleCursorInfo(hBuffer[1], &cci); }
void ScreenInit() { CONSOLE_CURSOR_INFO cci; g_hScreen[0] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); // 화면 버퍼 1 생성 g_hScreen[1] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); // 화면 버퍼 2 생성 cci.dwSize = 1; cci.bVisible = FALSE; SetConsoleCursorInfo(g_hScreen[0], &cci); SetConsoleCursorInfo(g_hScreen[1], &cci); // 커서 숨기기 13 - 16 }
Window() { for (int y = 0; y < HEIGHT; y++) chars[y][0] = '\0'; hSrc0 = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); if (hSrc0 == INVALID_HANDLE_VALUE) throw; hSrc1 = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); if (hSrc1 == INVALID_HANDLE_VALUE) throw; hSrc = hSrc0; }
void Print::ScreenInit() { CONSOLE_CURSOR_INFO cci; // 가상의 콘솔창 2개룰 만든다. m_hscreen[0] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); m_hscreen[1] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); // 커서 숨기기 cci.dwSize = 1; cci.bVisible = FALSE; SetConsoleCursorInfo(m_hscreen[0], &cci); SetConsoleCursorInfo(m_hscreen[1], &cci); }
/* * ScreenInit - get screen info */ void ScreenInit( void ) { CONSOLE_SCREEN_BUFFER_INFO sbi; char tmp[256]; InputHandle = CreateFile( "CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); SetConsoleMode( InputHandle, ENABLE_MOUSE_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_EXTENDED_FLAGS ); OutputHandle = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); SetConsoleMode( OutputHandle, 0 ); // SetConsoleActiveScreenBuffer( OutputHandle ); GetConsoleScreenBufferInfo( OutputHandle, &sbi ); EditVars.WindMaxWidth = sbi.dwMaximumWindowSize.X; EditVars.WindMaxHeight = sbi.dwMaximumWindowSize.Y; BSize.X = EditVars.WindMaxWidth; BSize.Y = EditVars.WindMaxHeight; EditFlags.Color = true; Scrn = malloc( EditVars.WindMaxWidth * EditVars.WindMaxHeight * sizeof( char_info ) ); ScreenPage( 0 ); tmp[0] = '\0'; GetConsoleTitle( tmp, sizeof( tmp ) ); oldConTitle = DupString( tmp ); if( !EditFlags.Quiet ) { SetConsoleTitle( "Open Watcom vi" ); } } /* ScreenInit */
extern void switch_console() { static int isConsoleOpened = 0; if (isConsoleOpened){ FreeConsole(); } else{ AllocConsole(); CreateConsoleScreenBuffer(GENERIC_WRITE | GENERIC_READ, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0); HANDLE input = GetStdHandle(STD_INPUT_HANDLE); HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE eoutput = GetStdHandle(STD_ERROR_HANDLE); FILE *fi = _fdopen(_open_osfhandle((long)input, _O_TEXT), "r"); *stdin = *fi; setvbuf(stdin, NULL, _IONBF, 0); FILE *fo = _fdopen(_open_osfhandle((long)output, _O_TEXT), "w"); *stdout = *fo; setvbuf(stdout, NULL, _IONBF, 0); FILE *fe = _fdopen(_open_osfhandle((long)eoutput, _O_TEXT), "w"); *stderr = *fe; setvbuf(stderr, NULL, _IONBF, 0); SetConsoleMode(input, ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_LINE_INPUT | 0x0004 | 0x0040); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); } isConsoleOpened = !isConsoleOpened; }
int init_console() { /* Set Project title */ SetConsoleTitle(PROJECT_TITLE); char command_buffer[15]; /* Set buffer size */ sprintf(command_buffer, "mode %d,%d", W*2, H+1); system(command_buffer); /* Buffer initialization */ buffer1=GetStdHandle(STD_OUTPUT_HANDLE); buffer2=CreateConsoleScreenBuffer(GENERIC_WRITE,FILE_SHARE_READ,0,CONSOLE_TEXTMODE_BUFFER,NULL); /* Initialize initial screen. !Free later! */ last_colormap = (color *)malloc(W*H*2*sizeof(color) + 1); last_screen = (char *)malloc(W*H*2 + 1); initial_last_colormap = last_colormap; initial_last_screen = last_screen; current_buffer = buffer1; return init_buffer(buffer1) && init_buffer(buffer2); }
ConsoleImpl::ConsoleImpl() { hndSavedOutput_ = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hndSavedOutput_, &csbiSaved_); GetConsoleCursorInfo(hndSavedOutput_, &cciSaved_); hndOutput_ = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); }
void putASCII2( int x, int y, int ch, int fgcolor, int bgcolor ) { if ( Touched_Global == 0) { hOutput[0] = (HANDLE) GetStdHandle( STD_OUTPUT_HANDLE ); SetConsoleScreenBufferSize(hOutput[0], dwBufferSize); hOutput[1] = CreateConsoleScreenBuffer( GENERIC_READ | // read/write access GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, // shared NULL, // default security attributes CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE NULL); // reserved; must be NULL SetConsoleScreenBufferSize(hOutput[1], dwBufferSize); SetConsoleActiveScreenBuffer(hOutput[0]); Double_Buffer_Switch = 1; Touched_Global = 1; } if (x<SCREEN_WIDTH && x>=0 && y<SCREEN_HEIGHT && y>=0) { screen_buffer[y][x].Char.AsciiChar = ch; screen_buffer[y][x].Attributes = fgcolor | bgcolor<<4; } }
/* * コンストラクタ。 * @return なし */ ScreenControl::ScreenControl() : mHandle(), mInfo() { // 初期ハンドルの取得 mInitHandle = GetStdHandle(STD_OUTPUT_HANDLE); // スクリーン情報設定 infoUpdate(); // カラー情報の初期値退避 mInitColor = mInfo.wAttributes; // バッファサイズの初期値退避 mInitBufferSize.X = mInfo.dwSize.X; mInitBufferSize.Y = mInfo.dwSize.Y; // 画面バッファ表示サイズの初期値退避 mInitWindow.Bottom = mInfo.srWindow.Bottom - mInfo.srWindow.Top; mInitWindow.Top = 0; mInitWindow.Left = 0; mInitWindow.Right = mInfo.srWindow.Right - mInfo.srWindow.Left; // スクリーンバッファを作成 mHandle = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); if (INVALID_HANDLE_VALUE == mHandle) { std::cerr << "Error" << std::endl; } // 対象のスクリーンバッファをアクティブ化 SetConsoleActiveScreenBuffer(mHandle); }
CL_ConsoleWindow_Generic::CL_ConsoleWindow_Generic( const CL_StringRef &title, int width, int height) { #ifdef WIN32 AllocConsole(); SetConsoleTitle(CL_StringHelp::utf8_to_ucs2(title).c_str()); COORD coord; coord.X = width; coord.Y = height; scrbuf = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); if(scrbuf == INVALID_HANDLE_VALUE) throw CL_Exception("Unable to allocate console screen buffer"); SetStdHandle(STD_OUTPUT_HANDLE, scrbuf); SetConsoleActiveScreenBuffer(scrbuf); SetConsoleScreenBufferSize(scrbuf, coord); #endif }
DblBuffer::DblBuffer() : m_swapped(false) { //m_hCons = GetStdHandle( STD_OUTPUT_HANDLE ); m_hCons1 = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); m_hCons2 = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); SetConsoleActiveScreenBuffer(m_hCons1); CONSOLE_CURSOR_INFO info; info.dwSize = 1; info.bVisible = FALSE; SetConsoleCursorInfo(m_hCons1, &info); SetConsoleCursorInfo(m_hCons2, &info); }
Screen::Screen () : mModeSwitcher (static_cast<Runable&>(*this), ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT) { mScreenBuf = CreateConsoleScreenBuffer (GENERIC_READ | GENERIC_WRITE, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0); if (mScreenBuf == INVALID_HANDLE_VALUE) throw AppException (WHERE, ERR_WINDOWS_FMT, "CreateConsoleScreenBuffer", GetLastError ()); setCursor (); // disable cursor }
int main( int argc, char *argv [] ) { LARGE_INTEGER lint; DWORD Written; COORD Coord = { 0, 0 }; myself = GetModuleHandle(NULL); GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &ScreenBufferInfo); ScreenBufferInfo.dwSize.X = ScreenBufferInfo.srWindow.Right - ScreenBufferInfo.srWindow.Left + 1; ScreenBufferInfo.dwSize.Y = ScreenBufferInfo.srWindow.Bottom - ScreenBufferInfo.srWindow.Top + 1; ScreenBuffer = CreateConsoleScreenBuffer( GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); if (INVALID_HANDLE_VALUE == ScreenBuffer) { _ftprintf( stderr, _TEXT("%s: could not create a new screen buffer\n"), app_name ); return EXIT_FAILURE; } // Fill buffer with black background FillConsoleOutputAttribute( ScreenBuffer, 0, ScreenBufferInfo.dwSize.X * ScreenBufferInfo.dwSize.Y, Coord, &Written ); WaitableTimer = CreateWaitableTimer( NULL, FALSE, NULL ); if( WaitableTimer == INVALID_HANDLE_VALUE ) { printf( "CreateWaitabletimer() failed\n" ); return 1; } lint.QuadPart = -2000000; if( SetWaitableTimer( WaitableTimer, &lint, 200, NULL, NULL, FALSE ) == FALSE ) { printf( "SetWaitableTimer() failed: 0x%lx\n", GetLastError() ); return 2; } SetConsoleActiveScreenBuffer(ScreenBuffer); MainLoop(); CloseHandle(ScreenBuffer); return EXIT_SUCCESS; }
void Console_Init() { int i; for (i = 0; i < CONSOLE_SCREEN_MAX; i++) { g_console.hScreen[i] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); } g_console.hScreenIndex = 0; g_console.hOut = g_console.hWork = g_console.hScreen[g_console.hScreenIndex]; SetConsoleActiveScreenBuffer(g_console.hOut); g_console.hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); }
static VALUE rb_CreateConsoleScreenBuffer( VALUE self, VALUE dwDesiredAccess, VALUE dwShareMode, VALUE dwFlags ) { if (CreateConsoleScreenBuffer( NUM2UINT(dwDesiredAccess), NUM2UINT( dwShareMode), NULL, NUM2UINT( dwFlags), NULL )) return INT2FIX(1); return rb_getWin32Error(); }
static void ScreenBuffer_CreatePort(SIOPCB * cb) { cb->Handle = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); /* cb->Handle should not be compared with NULL because CreateConsoleScreenBuffer returns INVALID_HANDLE_VALUE if it failed */ FatalAssertion(cb->Handle != INVALID_HANDLE_VALUE && cb->Handle != NULL, "ScreenBuffer_CreatePort failed to allocate its own console."); SetConsoleActiveScreenBuffer(cb->Handle); SetConsoleTitle("TOPPERS/JSP SerialConsole"); /* 受信バッファ監視用スレッドを作成 */ CreateThread(NULL,0,ScreenBuffer_ReceiverThread,(LPVOID)cb,0,NULL); }
int ConsoleInit(void) { //create debug console AllocConsole(); //initial screen buffer so console commands will work HANDLE hStdout=CreateConsoleScreenBuffer(GENERIC_WRITE|GENERIC_READ,FILE_SHARE_WRITE, NULL,CONSOLE_TEXTMODE_BUFFER, NULL); //error check if(hStdout==0) return 1; SetConsoleActiveScreenBuffer(hStdout); //lets text formating (ie newlines, etc) work with writeconsole() SetConsoleMode(hStdout, ENABLE_PROCESSED_OUTPUT); //redirects std output to console buffer, so that printf works //freopen( "CON", "w", stdout ); //redirects stdout to console, but //doesn"t work after SetConsoleActiveScreenBuffer issued freopen("CONOUT$", "wta", stdout); //freopen("CONOUT$", "wta+", stdout); //Also let us read from console with c library, since I can"t get //ReadConsole to work freopen("CONIN$","r",stdin); //set console title char *title="Console"; #ifdef UNICODE // Convert to a wchar_t* size_t origsize = strlen(title) + 1; const size_t newsize = 128; size_t convertedChars = 0; wchar_t wcstring[newsize]; mbstowcs(wcstring, title, newsize); // wcscat_s(wcstring, L" (wchar_t *)"); SetConsoleTitle(wcstring); #endif #ifndef UNICODE SetConsoleTitle(title); #endif //set buffer size COORD crd; crd.X=80; crd.Y=3000; SetConsoleScreenBufferSize(hStdout, crd); }
JNIEXPORT jlong JNICALL Java_com_yifanlu_Josh_Josh_CREATECONSOLESCREENBUFFER (JNIEnv *env, jclass jcls, jboolean read, jboolean write, jint shared) { long readWrite = 0x00000000L; if(read) readWrite |= GENERIC_READ; if(write) readWrite |= GENERIC_WRITE; HANDLE hNewScreenBuffer = CreateConsoleScreenBuffer(readWrite, shared, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); UINT_PTR pointer = (UINT_PTR)hNewScreenBuffer; return pointer; }
static void ntconio_open(void) { CONSOLE_CURSOR_INFO newcci; BOOL newcci_ok; TRACE(("ntconio_open\n")); set_colors(NCOLORS); set_palette(initpalettestr); hOldConsoleOutput = 0; hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); origcci_ok = GetConsoleCursorInfo(hConsoleOutput, &origcci); GetConsoleScreenBufferInfo(hConsoleOutput, &csbi); if (csbi.dwMaximumWindowSize.Y != csbi.srWindow.Bottom - csbi.srWindow.Top + 1 || csbi.dwMaximumWindowSize.X != csbi.srWindow.Right - csbi.srWindow.Left + 1) { TRACE(("..creating alternate screen buffer\n")); hOldConsoleOutput = hConsoleOutput; hConsoleOutput = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); SetConsoleActiveScreenBuffer(hConsoleOutput); GetConsoleScreenBufferInfo(hConsoleOutput, &csbi); newcci_ok = GetConsoleCursorInfo(hConsoleOutput, &newcci); if (newcci_ok && origcci_ok && newcci.dwSize != origcci.dwSize) { /* * Ensure that user's cursor size prefs are carried forward * in the newly created console. */ show_cursor(TRUE, origcci.dwSize); } } originalAttribute = csbi.wAttributes; crow = csbi.dwCursorPosition.Y; ccol = csbi.dwCursorPosition.X; nfcolor = cfcolor = gfcolor; nbcolor = cbcolor = gbcolor; set_current_attr(); newscreensize(csbi.dwMaximumWindowSize.Y, csbi.dwMaximumWindowSize.X); hConsoleInput = GetStdHandle(STD_INPUT_HANDLE); SetConsoleCtrlHandler(nthandler, TRUE); }
// 출력 전용 Sub screen 초기화 VOID CConsoleForOutput::InitOutputHandle( VOID ) { // 출력 전용 Handle 추출 및 Sub screen buffer 크기 설정 m_hOutput = CreateConsoleScreenBuffer( GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); if( m_hOutput == INVALID_HANDLE_VALUE ) { g_Log.PrintErrorMsg( TEXT( __FUNCTION__ ), true, GetLastError() ); m_hOutput = NULL; } else SetScreenBufferSize( m_hOutput ); }
static void mswindows_ensure_console_buffered (void) { if (!mswindows_console_buffered) { COORD new_size; new_size.X = 80; new_size.Y = 1000; mswindows_ensure_console_allocated (); mswindows_console_buffer = CreateConsoleScreenBuffer (GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); SetConsoleScreenBufferSize (mswindows_console_buffer, new_size); SetConsoleActiveScreenBuffer (mswindows_console_buffer); mswindows_console_buffered = 1; } }
void init_terminal(const std::string& title, int width, int height) { HANDLE handle = GetStdHandle( STD_INPUT_HANDLE ); SetConsoleMode( handle, ENABLE_EXTENDED_FLAGS ); if (_console_buffer_handle == NULL) { _console_buffer_handle = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); SetConsoleMode( _console_buffer_handle, ENABLE_EXTENDED_FLAGS ); //SetConsoleActiveScreenBuffer(_console_buffer_handle); _hide_cursor(handle); _hide_cursor(_console_buffer_handle); } }
void GetInputOutputHandles() { #ifdef NEW_CONSOLE HANDLE console = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CONSOLE_TEXTMODE_BUFFER, 0); if (SetConsoleActiveScreenBuffer(console) == FALSE) { hStdin = GetStdHandle(STD_INPUT_HANDLE); hStdout = GetStdHandle(STD_OUTPUT_HANDLE); } else { hStdin = GetStdHandle(STD_INPUT_HANDLE);//console; hStdout = console; } #else hStdin = GetStdHandle(STD_INPUT_HANDLE); hStdout = GetStdHandle(STD_OUTPUT_HANDLE); #endif }
void initConsole(COORD consoleSize, LPCSTR lpConsoleTitle) { // Use the ascii version for the consoleTitle SetConsoleTitleA(lpConsoleTitle); SetConsoleCP(437); // set up screen buffer screenDataBuffer = new CHAR_INFO[consoleSize.X * consoleSize.Y]; hScreenBuffer = CreateConsoleScreenBuffer( GENERIC_READ | // read/write access GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, // shared NULL, // default security attributes CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE NULL); // reserved; must be NULL SetConsoleActiveScreenBuffer(hScreenBuffer); // Sets the console size setConsoleSize(consoleSize.X, consoleSize.Y); }
BOOL CScreen::InitiateScreen(int X, int Y, DWORD cursor_size, BOOL cursor_visable){ m_cScreenSize.X = X; m_cScreenSize.Y = Y; CHAR_INFO tempChar; tempChar.Char.UnicodeChar = ' '; tempChar.Attributes = 0; for(int i = 0; i < X * Y; i++){ m_pDrawn.push_back(tempChar); } SMALL_RECT screenArea; screenArea.Top = 0; screenArea.Left = 0; screenArea.Right = m_cScreenSize.X - 1; screenArea.Bottom = m_cScreenSize.Y - 1; CONSOLE_CURSOR_INFO cursor = {cursor_size, cursor_visable}; m_hBuff1 = GetStdHandle(STD_OUTPUT_HANDLE); m_hBuff2 = CreateConsoleScreenBuffer(GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); SetConsoleScreenBufferSize(m_hBuff1, m_cScreenSize); SetConsoleScreenBufferSize(m_hBuff2, m_cScreenSize); SetConsoleCursorInfo(m_hBuff1, &cursor); SetConsoleCursorInfo(m_hBuff2, &cursor); SetConsoleWindowInfo(m_hBuff1, TRUE, &screenArea); SetConsoleWindowInfo(m_hBuff2, TRUE, &screenArea); m_hpBuffSwap = &m_hBuff2; return TRUE; }
/** * This function initializes libcaca vout method. */ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; if (vout_display_IsWindowed(vd)) return VLC_EGENERIC; #if !defined(__APPLE__) && !defined(_WIN32) # ifndef X_DISPLAY_MISSING if (!vlc_xlib_init(object)) return VLC_EGENERIC; # endif #endif #if defined(_WIN32) CONSOLE_SCREEN_BUFFER_INFO csbiInfo; SMALL_RECT rect; COORD coord; HANDLE hstdout; if (!AllocConsole()) { msg_Err(vd, "cannot create console"); return VLC_EGENERIC; } hstdout = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); if (!hstdout || hstdout == INVALID_HANDLE_VALUE) { msg_Err(vd, "cannot create screen buffer"); FreeConsole(); return VLC_EGENERIC; } if (!SetConsoleActiveScreenBuffer(hstdout)) { msg_Err(vd, "cannot set active screen buffer"); FreeConsole(); return VLC_EGENERIC; } coord = GetLargestConsoleWindowSize(hstdout); msg_Dbg(vd, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y); /* Force size for now */ coord.X = 100; coord.Y = 40; if (!SetConsoleScreenBufferSize(hstdout, coord)) msg_Warn(vd, "SetConsoleScreenBufferSize %i %i", coord.X, coord.Y); /* Get the current screen buffer size and window position. */ if (GetConsoleScreenBufferInfo(hstdout, &csbiInfo)) { rect.Top = 0; rect.Left = 0; rect.Right = csbiInfo.dwMaximumWindowSize.X - 1; rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1; if (!SetConsoleWindowInfo(hstdout, TRUE, &rect)) msg_Dbg(vd, "SetConsoleWindowInfo failed: %ix%i", rect.Right, rect.Bottom); } #endif /* Allocate structure */ vd->sys = sys = calloc(1, sizeof(*sys)); if (!sys) goto error; sys->cv = cucul_create_canvas(0, 0); if (!sys->cv) { msg_Err(vd, "cannot initialize libcucul"); goto error; } const char *driver = NULL; #ifdef __APPLE__ // Make sure we don't try to open a window. driver = "ncurses"; #endif sys->dp = caca_create_display_with_driver(sys->cv, driver); if (!sys->dp) { msg_Err(vd, "cannot initialize libcaca"); goto error; } if (vd->cfg->display.title) caca_set_display_title(sys->dp, vd->cfg->display.title); else caca_set_display_title(sys->dp, VOUT_TITLE "(Colour AsCii Art)"); /* Fix format */ video_format_t fmt = vd->fmt; if (fmt.i_chroma != VLC_CODEC_RGB32) { fmt.i_chroma = VLC_CODEC_RGB32; fmt.i_rmask = 0x00ff0000; fmt.i_gmask = 0x0000ff00; fmt.i_bmask = 0x000000ff; } /* TODO */ vout_display_info_t info = vd->info; /* Setup vout_display now that everything is fine */ vd->fmt = fmt; vd->info = info; vd->pool = Pool; vd->prepare = Prepare; vd->display = PictureDisplay; vd->control = Control; vd->manage = Manage; /* Fix initial state */ vout_display_SendEventFullscreen(vd, false); Refresh(vd); return VLC_SUCCESS; error: if (sys) { if (sys->pool) picture_pool_Release(sys->pool); if (sys->dither) cucul_free_dither(sys->dither); if (sys->dp) caca_free_display(sys->dp); if (sys->cv) cucul_free_canvas(sys->cv); free(sys); } #if defined(_WIN32) FreeConsole(); #endif return VLC_EGENERIC; }
DWORD main( int argc, char *argv[] ) { BOOL Success; int i; HPALETTE hPalette; LOGPALETTE *Palette; HANDLE hgo; CONSOLE_GRAPHICS_BUFFER_INFO cgbi; Palette = LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)); Palette->palNumEntries = (WORD) 256; Palette->palVersion = 0x300; /* Fill in the palette entries from the DIB color table and * create a logical color palette. */ for (i = 0; i < 256; i++) { Palette->palPalEntry[i].peRed = 255-i; Palette->palPalEntry[i].peGreen = 255-i; Palette->palPalEntry[i].peBlue = 255-i; Palette->palPalEntry[i].peFlags = (BYTE)0; } hPalette = CreatePalette(Palette); if (hPalette==NULL) { printf("first CreatePalette failed\n"); printf("last error is %x\n",GetLastError()); } #if 0 call HANDLE APIENTRY CreateConsoleScreenBuffer( DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwFlags, == CONSOLE_GRAPHICS_BUFFER PVOID lpScreenBufferData == pCONSOLE_GRAPHICS_BUFFER_INFO ); typedef struct _CONSOLE_GRAPHICS_BUFFER_INFO { DWORD dwBitMapInfoLength; LPBITMAPINFO lpBitMapInfo; DWORD dwUsage; HANDLE hMutex; PVOID lpBitMap; } CONSOLE_GRAPHICS_BUFFER_INFO, *PCONSOLE_GRAPHICS_BUFFER_INFO; #define CONSOLE_GRAPHICS_BUFFER 2 #endif hgo = CreateConsoleScreenBuffer(MAXIMUM_ALLOWED, 0, NULL, CONSOLE_GRAPHICS_BUFFER, &cgbi); if (hgo == NULL) { DbgPrint("CreateConsoleScreenBuffer failed\n"); return FALSE; } Success = SetConsolePalette(hgo, hPalette, SYSPAL_NOSTATIC ); if (!Success) { printf("first SetConsolePalette failed\n"); } printf("palette should be different\n"); Sleep(5000); DeleteObject(hPalette); /* Fill in the palette entries from the DIB color table and * create a logical color palette. */ for (i = 0; i < 16; i++) { memcpy(&Palette->palPalEntry[i], MyPalette, 64 ); } hPalette = CreatePalette(Palette); if (hPalette==NULL) { printf("first CreatePalette failed\n"); } Success = SetConsolePalette(hgo, hPalette, SYSPAL_STATIC ); if (!Success) { printf("second SetConsolePalette failed\n"); } printf("palette should be different\n"); Sleep(5000); DeleteObject(hPalette); printf( "TCURSOR: Exiting Test Program\n" ); return TRUE; }
int OpenDebugLog() { #if defined (FBA_DEBUG) #if defined (APP_DEBUG_LOG) time_t nTime; tm* tmTime; time(&nTime); tmTime = localtime(&nTime); { // Initialise the debug log file #ifdef _UNICODE DebugLog = _tfopen(_T("zzBurnDebug.html"), _T("wb")); if (ftell(DebugLog) == 0) { WRITE_UNICODE_BOM(DebugLog); _ftprintf(DebugLog, _T("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">")); _ftprintf(DebugLog, _T("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=unicode\"></head><body><pre>")); } #else DebugLog = _tfopen(_T("zzBurnDebug.html"), _T("wt")); if (ftell(DebugLog) == 0) { _ftprintf(DebugLog, _T("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">")); _ftprintf(DebugLog, _T("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=windows-%i\"></head><body><pre>"), GetACP()); } #endif _ftprintf(DebugLog, _T("</font><font size=larger color=#000000>")); _ftprintf(DebugLog, _T("Debug log created by ") _T(APP_TITLE) _T(" v%.20s on %s\n<br>"), szAppBurnVer, _tasctime(tmTime)); } #endif { // Initialise the debug console COORD DebugBufferSize = { 80, 1000 }; { // Since AttachConsole is only present in Windows XP, import it manually #if _WIN32_WINNT >= 0x0500 && defined (_MSC_VER) // #error Manually importing AttachConsole() function, but compiling with _WIN32_WINNT >= 0x0500 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { AllocConsole(); } #else #define ATTACH_PARENT_PROCESS ((DWORD)-1) BOOL (WINAPI* pAttachConsole)(DWORD dwProcessId) = NULL; HINSTANCE hKernel32DLL = LoadLibrary(_T("kernel32.dll")); if (hKernel32DLL) { pAttachConsole = (BOOL (WINAPI*)(DWORD))GetProcAddress(hKernel32DLL, "AttachConsole"); } if (pAttachConsole) { if (!pAttachConsole(ATTACH_PARENT_PROCESS)) { AllocConsole(); } } else { AllocConsole(); } if (hKernel32DLL) { FreeLibrary(hKernel32DLL); } #undef ATTACH_PARENT_PROCESS #endif } DWORD ignore; DebugBuffer = CreateConsoleScreenBuffer(GENERIC_WRITE, FILE_SHARE_READ, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); SetConsoleScreenBufferSize(DebugBuffer, DebugBufferSize); SetConsoleActiveScreenBuffer(DebugBuffer); SetConsoleTitle(_T(APP_TITLE) _T(" Debug console")); SetConsoleTextAttribute(DebugBuffer, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); _sntprintf(szConsoleBuffer, 1024, _T("Welcome to the ") _T(APP_TITLE) _T(" debug console.\n")); WriteConsole(DebugBuffer, szConsoleBuffer, _tcslen(szConsoleBuffer), &ignore, NULL); SetConsoleTextAttribute(DebugBuffer, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); if (DebugLog) { _sntprintf(szConsoleBuffer, 1024, _T("Debug messages are logged in zzBurnDebug.html")); if (!DebugLog || bEchoLog) { _sntprintf(szConsoleBuffer + _tcslen(szConsoleBuffer), 1024 - _tcslen(szConsoleBuffer), _T(", and echod to this console")); } _sntprintf(szConsoleBuffer + _tcslen(szConsoleBuffer), 1024 - _tcslen(szConsoleBuffer), _T(".\n\n")); } else { _sntprintf(szConsoleBuffer, 1024, _T("Debug messages are echod to this console.\n\n")); } WriteConsole(DebugBuffer, szConsoleBuffer, _tcslen(szConsoleBuffer), &ignore, NULL); } nPrevConsoleStatus = -1; bprintf = AppDebugPrintf; // Redirect Burn library debug to our function #endif return 0; }