diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/Console.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'CPP/Windows/Console.h')
-rw-r--r-- | CPP/Windows/Console.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/CPP/Windows/Console.h b/CPP/Windows/Console.h new file mode 100644 index 0000000..43e02fa --- /dev/null +++ b/CPP/Windows/Console.h | |||
@@ -0,0 +1,52 @@ | |||
1 | // Windows/Console.h | ||
2 | |||
3 | #ifndef __WINDOWS_CONSOLE_H | ||
4 | #define __WINDOWS_CONSOLE_H | ||
5 | |||
6 | #include "Defs.h" | ||
7 | |||
8 | namespace NWindows { | ||
9 | namespace NConsole { | ||
10 | |||
11 | class CBase | ||
12 | { | ||
13 | protected: | ||
14 | HANDLE m_Object; | ||
15 | public: | ||
16 | void Attach(HANDLE handle) { m_Object = handle; } | ||
17 | bool GetMode(DWORD &mode) | ||
18 | { return BOOLToBool(::GetConsoleMode(m_Object, &mode)); } | ||
19 | bool SetMode(DWORD mode) | ||
20 | { return BOOLToBool(::SetConsoleMode(m_Object, mode)); } | ||
21 | }; | ||
22 | |||
23 | class CIn: public CBase | ||
24 | { | ||
25 | public: | ||
26 | bool PeekEvents(PINPUT_RECORD events, DWORD numEvents, DWORD &numEventsRead) | ||
27 | { return BOOLToBool(::PeekConsoleInput(m_Object, events, numEvents, &numEventsRead)); } | ||
28 | bool PeekEvent(INPUT_RECORD &event, DWORD &numEventsRead) | ||
29 | { return PeekEvents(&event, 1, numEventsRead); } | ||
30 | bool ReadEvents(PINPUT_RECORD events, DWORD numEvents, DWORD &numEventsRead) | ||
31 | { return BOOLToBool(::ReadConsoleInput(m_Object, events, numEvents, &numEventsRead)); } | ||
32 | bool ReadEvent(INPUT_RECORD &event, DWORD &numEventsRead) | ||
33 | { return ReadEvents(&event, 1, numEventsRead); } | ||
34 | bool GetNumberOfEvents(DWORD &numEvents) | ||
35 | { return BOOLToBool(::GetNumberOfConsoleInputEvents(m_Object, &numEvents)); } | ||
36 | |||
37 | bool WriteEvents(const INPUT_RECORD *events, DWORD numEvents, DWORD &numEventsWritten) | ||
38 | { return BOOLToBool(::WriteConsoleInput(m_Object, events, numEvents, &numEventsWritten)); } | ||
39 | bool WriteEvent(const INPUT_RECORD &event, DWORD &numEventsWritten) | ||
40 | { return WriteEvents(&event, 1, numEventsWritten); } | ||
41 | |||
42 | bool Read(LPVOID buffer, DWORD numChars, DWORD &numCharsRead) | ||
43 | { return BOOLToBool(::ReadConsole(m_Object, buffer, numChars, &numCharsRead, NULL)); } | ||
44 | |||
45 | bool Flush() | ||
46 | { return BOOLToBool(::FlushConsoleInputBuffer(m_Object)); } | ||
47 | |||
48 | }; | ||
49 | |||
50 | }} | ||
51 | |||
52 | #endif | ||