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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
// gotoXY and Clearing The Screen : main project file.
#include <stdafx.h>
#include <stdio.h>
#include <iostream>
#include <windows.h>
using namespace std;
using namespace System;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
void gotoXY(int, int);
void cls( HANDLE hConsole );
CHAR WaitKey(VOID);
int main( void )
{
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
for (int y = 0;y<1520;y++)
printf( "X" );
gotoXY(20,21);
cout << "Press any key to continue..";
WaitKey();
cls(console);
gotoXY(26,13);
cout << "Press any key to end..";
WaitKey();
return 0;
}
void gotoXY(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
}
void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; // home for the cursor
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
// Get the number of character cells in the current buffer.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
{
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill the entire screen with blanks.
if( !FillConsoleOutputCharacter( hConsole, // Handle to console screen buffer
(TCHAR) ' ', // Character to write to the buffer
dwConSize, // Number of cells to write
coordScreen, // Coordinates of first cell
&cCharsWritten ))// Receive number of characters written
{
return;
}
// Get the current text attribute.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
{
return;
}
// Set the buffer's attributes accordingly.
if( !FillConsoleOutputAttribute( hConsole, // Handle to console screen buffer
csbi.wAttributes, // Character attributes to use
dwConSize, // Number of cells to set attribute
coordScreen, // Coordinates of first cell
&cCharsWritten )) // Receive number of characters written
{
return;
}
// Put the cursor at its home coordinates.
SetConsoleCursorPosition( hConsole, coordScreen );
}
CHAR WaitKey (VOID)
{
HANDLE hStdin = GetStdHandle (STD_INPUT_HANDLE);
INPUT_RECORD irInputRecord;
DWORD dwEventsRead;
CHAR cChar;
while(ReadConsoleInputA (hStdin, &irInputRecord, 1, &dwEventsRead)) /* Read key press */
if (irInputRecord.EventType == KEY_EVENT
&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_SHIFT
&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_MENU
&&irInputRecord.Event.KeyEvent.wVirtualKeyCode != VK_CONTROL)
{
cChar = irInputRecord.Event.KeyEvent.uChar.AsciiChar;
ReadConsoleInputA (hStdin, &irInputRecord , 1, &dwEventsRead); /* Read key release */
return cChar;
}
return EOF;
}
|