Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HomeWork1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdio.h>
- #include <tchar.h>
- #include <iostream>
- #include <Windows.h>
- using namespace std;
- int PressAnyKey(char *prompt) // msdn library
- {
- DWORD mode;
- HANDLE hstdin;
- INPUT_RECORD inrec;
- DWORD count;
- char default_prompt[] = "Press a key to continue...";
- // Set the console mode to no-echo, raw input,
- // and no window or mouse events.
- hstdin = GetStdHandle(STD_INPUT_HANDLE);
- if (hstdin == INVALID_HANDLE_VALUE || !GetConsoleMode(hstdin, &mode) || !SetConsoleMode(hstdin, 0))
- return 0;
- if (!prompt)
- prompt = default_prompt;
- // little fix on the example code by me: convert const char* to WCHAR*
- int buffer_size = MultiByteToWideChar(0, 0, prompt, -1, NULL, NULL) * sizeof(wchar_t);
- WCHAR *w_prompt = new WCHAR[buffer_size]; // allocate memory
- MultiByteToWideChar(0, 0, prompt, -1, w_prompt, buffer_size);
- // Instruct the user
- WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), w_prompt, lstrlen(w_prompt), &count, NULL);
- FlushConsoleInputBuffer(hstdin);
- // Get a single key RELEASE
- do ReadConsoleInput(hstdin, &inrec, 1, &count);
- while ((inrec.EventType != KEY_EVENT) || inrec.Event.KeyEvent.bKeyDown);
- // Restore the original console mode
- SetConsoleMode(hstdin, mode);
- return inrec.Event.KeyEvent.wVirtualKeyCode;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- cout << "Countback program." << endl;
- for(int i = 0; i <= 10; i++)
- {
- cout << i << endl;
- if(i == 10)
- {
- cout << "Thunderbirds are go!" << endl;
- break;
- }
- Sleep(1000);
- }
- PressAnyKey("Press any key to continue...");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement