|
|
1.1.1.3 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: 1.1 root 12: #include <windows.h> 13: #include "console.h" 14: 15: /********************************************************************* 16: * FUNCTION: demoFlush(HANDLE hConOut) * 17: * * 18: * PURPOSE: demonstrate FlushConsoleInputBuffer. Slowly read from the * 19: * iput queue, allowing a backlog of input events to start * 20: * filling the queue. Flush the input queue after outputting * 21: * every fifth character. * 22: * * 23: * INPUT: the output console handle to write to * 24: *********************************************************************/ 25: 26: void demoFlush(HANDLE hConOut) 27: { 28: HANDLE hStdIn; 29: INPUT_RECORD InputBuffer; 30: DWORD dwInputEvents; 31: int i = 0; 32: BOOL bSuccess; 33: DWORD dwBytesWritten; 34: 35: setConTitle(__FILE__); 36: hStdIn = GetStdHandle(STD_INPUT_HANDLE); 1.1.1.2 root 37: PERR(hStdIn != INVALID_HANDLE_VALUE, "GetStdHandle"); 1.1 root 38: myPuts(hConOut, "Type a number of characters quickly. I will read 5\n" 39: "characters from the input buffer with a Sleep() delay\n" 40: "which will allow it to fill with characters. After 5\n" 41: "characters I will flush the input buffer with\n" 42: "FlushConsoleInputBuffer and restart the sequence. Note\n" 43: "that any characters you've typed that haven't been read\n" 44: "yet are lost due to the flush.\n" 45: "Enter characters (hit ESC to return):"); 46: for(;;) 47: { 48: bSuccess = ReadConsoleInput(hStdIn, &InputBuffer, 1, &dwInputEvents); 49: PERR(bSuccess, "ReadConsoleInput"); 50: /* is it a key down event? */ 51: if (InputBuffer.EventType == KEY_EVENT && 52: InputBuffer.Event.KeyEvent.bKeyDown) 53: { 54: if (InputBuffer.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) 55: return; 56: /* write the ascii character out to the console */ 57: bSuccess = WriteFile(hConOut, 58: &InputBuffer.Event.KeyEvent.uChar.AsciiChar, 59: 1, &dwBytesWritten, NULL); 60: PERR(bSuccess, "WriteFile"); 61: Sleep(1000); /* pause for 1s */ 62: i++; 63: if (i > 5) 64: { 65: /* flush the input buffer */ 66: bSuccess = FlushConsoleInputBuffer(hStdIn); 67: PERR(bSuccess, "FlushConsoleInputBuffer"); 68: i = 0; 69: } 70: } /* if */ 71: } /* while */ 72: return; 73: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.