本文整理汇总了C++中SetConsoleMode函数的典型用法代码示例。如果您正苦于以下问题:C++ SetConsoleMode函数的具体用法?C++ SetConsoleMode怎么用?C++ SetConsoleMode使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetConsoleMode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enableRawMode
static int enableRawMode(struct current *current) {
DWORD n;
INPUT_RECORD irec;
current->outh = GetStdHandle(STD_OUTPUT_HANDLE);
current->inh = GetStdHandle(STD_INPUT_HANDLE);
if (!PeekConsoleInput(current->inh, &irec, 1, &n)) {
return -1;
}
if (getWindowSize(current) != 0) {
return -1;
}
if (GetConsoleMode(current->inh, &orig_consolemode)) {
SetConsoleMode(current->inh, ENABLE_PROCESSED_INPUT);
}
return 0;
}
示例2: installsighandler
static void installsighandler()
{
#ifndef _WIN32
signal(SIGHUP,sighandler);
signal(SIGUSR1,sighandler);
signal(SIGPIPE,sighandler);
#endif
signal(SIGINT,sighandler);
#ifdef _WIN32
SetConsoleCtrlHandler(ConsoleCtrlHandler,true);
HANDLE hs=GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
if (GetConsoleMode(hs,&mode)) {
mode|=ENABLE_PROCESSED_INPUT;
SetConsoleMode(hs,mode);
};
#endif
}
示例3: ConsoleInit
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);// 出力スクリーンをアクティブ化
}
示例4: oss_con_init
/* initialize console */
void oss_con_init(void)
{
DWORD new_console_mode;
OSVERSIONINFO ver_info;
/* get the console input and output handles */
G_out_bufhdl = GetStdHandle(STD_OUTPUT_HANDLE);
G_in_bufhdl = GetStdHandle(STD_INPUT_HANDLE);
/* get the original console mode so we can restore it when we're done */
GetConsoleMode(G_out_bufhdl, &S_orig_console_out_mode);
GetConsoleMode(G_in_bufhdl, &S_orig_console_in_mode);
/* if we're in 'plain' mode, don't change the console mode */
if (os_f_plain)
return;
/* start with the original console mode bits */
new_console_mode = S_orig_console_out_mode;
/*
* Turn off wrapping when writing at the end of the line - the
* automatic wrapping screws up our scrolling, and we don't need it
* anyway since we keep track of all of our cursor positioning
* ourselves, hence it's easier if we just turn this feature off
*/
new_console_mode &= ~ENABLE_WRAP_AT_EOL_OUTPUT;
/*
* If we're on a 95 derivative (95, 98, ME), also clear the "processed
* output" flag. This flag is necessary on NT for proper character
* set handling, but is not on 95/98/ME; and if that flag isn't
* cleared on 95/98/ME, clearing the wrap-at-eol flag has no effect.
* So, we must clear this flag on 95/98/ME, but we must leave it
* enabled on NT. (What a pain.)
*/
ver_info.dwOSVersionInfoSize = sizeof(ver_info);
GetVersionEx(&ver_info);
if (ver_info.dwPlatformId != VER_PLATFORM_WIN32_NT)
new_console_mode &= ~ENABLE_PROCESSED_OUTPUT;
/* set the new console mode */
SetConsoleMode(G_out_bufhdl, new_console_mode);
}
示例5: InitializeTerminal
/*--------------------------------------------------------------------------*/
void InitializeTerminal(void)
{
if (!Win32InputStream)
{
Win32InputStream = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(Win32InputStream, &OldWin32Mode);
SetConsoleMode(Win32InputStream, ENABLE_PROCESSED_INPUT);
}
if (!Win32OutputStream)
{
Win32OutputStream = GetStdHandle(STD_OUTPUT_HANDLE);
}
setFocusOnConsole();
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE );
}
示例6: CON_Init
/*
==================
CON_Init
==================
*/
void CON_Init (void)
{
CONSOLE_CURSOR_INFO curs;
CONSOLE_SCREEN_BUFFER_INFO info;
int i;
// handle Ctrl-C or other console termination
SetConsoleCtrlHandler(CON_CtrlHandler, TRUE);
qconsole_hin = GetStdHandle(STD_INPUT_HANDLE);
if (qconsole_hin == INVALID_HANDLE_VALUE)
return;
qconsole_hout = GetStdHandle(STD_OUTPUT_HANDLE);
if (qconsole_hout == INVALID_HANDLE_VALUE)
return;
GetConsoleMode(qconsole_hin, &qconsole_orig_mode);
// allow mouse wheel scrolling
SetConsoleMode(qconsole_hin, qconsole_orig_mode & ~ENABLE_MOUSE_INPUT);
FlushConsoleInputBuffer(qconsole_hin);
GetConsoleScreenBufferInfo(qconsole_hout, &info);
qconsole_attrib = info.wAttributes;
qconsole_backgroundAttrib = qconsole_attrib & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
SetConsoleTitle("Dedicated Server Console");
// make cursor invisible
GetConsoleCursorInfo(qconsole_hout, &qconsole_orig_cursorinfo);
curs.dwSize = 1;
curs.bVisible = FALSE;
SetConsoleCursorInfo(qconsole_hout, &curs);
// initialize history
for (i = 0; i < QCONSOLE_HISTORY; i++)
qconsole_history[i][0] = '\0';
// set text color to white
SetConsoleTextAttribute(qconsole_hout, CON_ColorCharToAttrib(COLOR_WHITE));
}
示例7: GetStdHandle
WindowsInputController::WindowsInputController() {
HANDLE hStdin;
DWORD fdwMode, fdwSaveOldMode;
// Get the standard input handle.
hStdin = GetStdHandle( STD_INPUT_HANDLE );
if( hStdin == INVALID_HANDLE_VALUE )
return;
// Save the current input mode, to be restored on exit.
if( !GetConsoleMode(hStdin, &fdwSaveOldMode) )
return;
// Enable the window and mouse input events.
fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
if( !SetConsoleMode(hStdin, fdwMode) )
return;
}
示例8: sizeof
DWORD CPequote::Start()
{
//CEgRegKey key;
CModuleVersion ver;
TCHAR pModName [1024] = { 0 };
TCHAR pVer[100] = { 0 };
//detecting the module version
::GetModuleFileName( NULL, pModName, sizeof(pModName)/sizeof(TCHAR));
ver.GetModuleVersionInfo(pModName);
ver.GetValue(_T("ProductVersion"), pVer);
DWORD dwFlags;
if(GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &dwFlags))
{
dwFlags &= ~(ENABLE_QUICK_EDIT | ENABLE_INSERT_MODE);
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), dwFlags);
}
m_hStopApplication = ::CreateEvent(NULL, TRUE, FALSE, NULL);
if (!m_hStopApplication)
{
return TraceError();
}
if (!::SetConsoleCtrlHandler(HandlerRoutine, TRUE))
return TraceError();
CTracer::TraceMessage(CTracer::enMtInformation, NULL, _T("Starting Pequote connector..."));
DWORD dwRes = m_PequoteConnector.Start(NULL);
if (dwRes)
{
CTracer::TraceMessage(CTracer::enMtError, NULL, _T("Failed to start Pequote connector."));
return dwRes;
}
CTracer::TraceMessage(CTracer::enMtInformation, NULL, _T("Pequote connector started."));
CTracer::TraceMessage(CTracer::enMtInformation, NULL, _T("Server started."));
return 0;
}
示例9: noecho_console
static int noecho_console(UI *ui)
{
#ifdef TTY_FLAGS
memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
tty_new.TTY_FLAGS &= ~ECHO;
#endif
#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
return 0;
#endif
#ifdef OPENSSL_SYS_VMS
if (is_a_tty) {
tty_new[0] = tty_orig[0];
tty_new[1] = tty_orig[1] | TT$M_NOECHO;
tty_new[2] = tty_orig[2];
status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12,
0, 0, 0, 0);
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) {
char tmp_num[2][12];
BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X",
status);
BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X",
iosb.iosb$w_value);
UIerr(UI_F_NOECHO_CONSOLE, UI_R_SYSQIOW_ERROR);
ERR_add_error_data(5, "status=", tmp_num[0],
",", "iosb.iosb$w_value=", tmp_num[1]);
return 0;
}
}
#endif
#if defined(_WIN32) && !defined(_WIN32_WCE)
if (is_a_tty) {
tty_new = tty_orig;
tty_new &= ~ENABLE_ECHO_INPUT;
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), tty_new);
}
#endif
return 1;
}
示例10: init_terminal
/*
* initialize the terminal data structures.
*/
void init_terminal(void) {
if (ttyoring.init(2*BUFSIZ, ttysink, NULL) != 1) {
exit(1);
}
if (ttyiring.init(BUFSIZ, NULL, ttysrc) != 1) {
exit(1);
}
autoflush = TerminalAutoFlush();
#ifdef __WIN32__
/*
* Set the console mode. This will only have an effect if the
* handle is a console handle
*/
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
#if 0
printf("1. Calling SetConsoleMode(0x%08x, 0x%08x)\n",
hOut, ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT);
#endif
SetConsoleMode(hOut, ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT);
#endif
}
示例11: stdin_echo
void stdin_echo(bool enable)
{
#ifdef WIN32
HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin,&mode);
if(!enable)
mode&=~ENABLE_ECHO_INPUT;
else
mode|=ENABLE_ECHO_INPUT;
SetConsoleMode(hStdin, mode );
#else
struct termios tty;
tcgetattr(STDIN_FILENO,&tty);
if(!enable)
tty.c_lflag&=~ECHO;
else
tty.c_lflag|=ECHO;
tcsetattr(STDIN_FILENO,TCSANOW,&tty);
#endif
}
示例12: termset
static void
termset(void)
{
DWORD flag;
if(donetermset)
return;
donetermset = 1;
conh = GetStdHandle(STD_OUTPUT_HANDLE);
kbdh = GetStdHandle(STD_INPUT_HANDLE);
errh = GetStdHandle(STD_ERROR_HANDLE);
if(errh == INVALID_HANDLE_VALUE)
errh = conh;
// The following will fail if kbdh not from console (e.g. a pipe)
// in which case we don't care
GetConsoleMode(kbdh, &consolestate);
flag = consolestate;
flag = flag & ~(ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT);
SetConsoleMode(kbdh, flag);
}
示例13: mygetch
/** get a character from the terminal */
int
mygetch(void)
{
#if !defined(_WIN32) || !defined(__CYGWIN__)
/* longjmp won't work, it's in a different thread */
sighandler_t savesig; /* old value of signal */
#endif
int c;
/* change an interrupt signal to a break key character */
if (setjmp(env) == 0) {
#if defined(_WIN32) && !defined(__CYGWIN__)
/* turn off Ctrl+C handling (PDCurses does this, but it gets turned on
again by CMD during system) */
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ), 0 );
#else
savesig = signal(SIGINT, catchint);
#endif
refresh(); /* update the display */
mousereinit(); /* curses can change the menu number */
if(prevchar) {
c = prevchar;
prevchar = 0;
} else {
c = -1;
while (c == -1) {
/* get a character from the terminal */
c = getch();
if ((c == -1) && (errno != EINTR))
break;
}
}
} else { /* longjmp to here from signal handler */
c = KEY_BREAK;
}
#if !defined(_WIN32) || !defined(__CYGWIN__)
signal(SIGINT, savesig);
#endif
return(c);
}
示例14: CON_Init
/*
==================
CON_Init
==================
*/
void CON_Init( void )
{
CONSOLE_SCREEN_BUFFER_INFO info;
char consoleTitle[128];
int i;
// handle Ctrl-C or other console termination
SetConsoleCtrlHandler( CON_CtrlHandler, TRUE );
qconsole_hin = GetStdHandle( STD_INPUT_HANDLE );
if( qconsole_hin == INVALID_HANDLE_VALUE )
return;
qconsole_hout = GetStdHandle( STD_OUTPUT_HANDLE );
if( qconsole_hout == INVALID_HANDLE_VALUE )
return;
GetConsoleMode( qconsole_hin, &qconsole_orig_mode );
// allow mouse wheel scrolling
SetConsoleMode( qconsole_hin,
qconsole_orig_mode & ~ENABLE_MOUSE_INPUT );
FlushConsoleInputBuffer( qconsole_hin );
GetConsoleScreenBufferInfo( qconsole_hout, &info );
qconsole_attrib = info.wAttributes;
qconsole_backgroundAttrib = qconsole_attrib & (BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED|BACKGROUND_INTENSITY);
// ZTM: FIXME: com_productName isn't initialized or set to game title yet.
Com_sprintf( consoleTitle, sizeof (consoleTitle), "%s Dedicated Server Console", com_productName ? com_productName->string : PRODUCT_NAME );
SetConsoleTitle( consoleTitle );
// initialize history
for( i = 0; i < QCONSOLE_HISTORY; i++ )
qconsole_history[ i ][ 0 ] = '\0';
// set text color to white
SetConsoleTextAttribute( qconsole_hout, CON_ColorCharToAttrib( COLOR_WHITE ) );
}
示例15: readpassphrase
static char *
readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
{
HANDLE hStdin, hStdout;
DWORD mode, rbytes;
BOOL success;
(void)flags;
hStdin = GetStdHandle(STD_INPUT_HANDLE);
if (hStdin == INVALID_HANDLE_VALUE)
return (NULL);
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdout == INVALID_HANDLE_VALUE)
return (NULL);
success = GetConsoleMode(hStdin, &mode);
if (!success)
return (NULL);
mode &= ~ENABLE_ECHO_INPUT;
mode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
success = SetConsoleMode(hStdin, mode);
if (!success)
return (NULL);
success = WriteFile(hStdout, prompt, (DWORD)strlen(prompt),
NULL, NULL);
if (!success)
return (NULL);
success = ReadFile(hStdin, buf, (DWORD)bufsiz - 1, &rbytes, NULL);
if (!success)
return (NULL);
WriteFile(hStdout, "\r\n", 2, NULL, NULL);
buf[rbytes] = '\0';
/* Remove trailing carriage return(s). */
if (rbytes > 2 && buf[rbytes - 2] == '\r' && buf[rbytes - 1] == '\n')
buf[rbytes - 2] = '\0';
return (buf);
}