13 #pragma managed( push, off )    42         , m_bStopInput( false )
    78             if ( 
nullptr == pszString ) {
    84             HANDLE hOutput = ::GetStdHandle( STD_OUTPUT_HANDLE );
    87             int nCount = 
static_cast< int >( ::wcslen( pszString ) );
    90                 ::WriteConsoleW( hOutput, pszString, static_cast< DWORD >( nCount ), 
nullptr, 
nullptr );
    93             else for ( 
int nIndex = 0, nSize = 0; nCount > nIndex; nIndex += nSize, nCount -= nSize ) {
   103                 ::wcsncpy_s( 
m_szBuffer, &pszString[ nIndex ], nSize );
   109                 ::WriteConsoleW( hOutput, 
m_szBuffer, static_cast< DWORD >( nSize ), 
nullptr, 
nullptr );
   154                     rCh = sRecord.
m_sEvent.Event.KeyEvent.uChar.UnicodeChar;
   155                     if ( L
'\0' != rCh ) {
   157                         if ( L
'\r' == rCh ) {
   168                 else if ( cTimer.
Wait( 0 ) ) {
   191             if ( 
nullptr == pszBuffer ) {
   201             COORD sCursorFirst, sCursorLast;
   203             sCursorLast = sCursorFirst;
   208             if ( ( 
nullptr != pszString ) && ( L
'\0' != *pszString ) ) {
   211                 for ( 
int nIndex = 0; bResult; ++nIndex ) {
   213                     if ( L
'\0' == *pszString ) {
   224                     else if ( ( nSize - 1 ) > nIndex ) {
   226                         pszBuffer[ nCount++ ] = *pszString;
   259                 wchar_t ch = sRecord.
m_sEvent.Event.KeyEvent.uChar.UnicodeChar;
   260                 if ( L
'\033' == ch ) {
   271                     pszBuffer[ nCount ] = L
'\0';
   278                 else if ( 0 != ::iswprint( ch ) ) {
   280                     if ( ( nSize - 1 ) > nCount ) {
   282                         if ( nCount == nPos ) {
   284                             pszBuffer[ nCount++ ] = ch;
   298                             nRedrawPos = 
static_cast< int >( nPos );
   301                             for ( 
int nIndex = nCount; nPos < nIndex; --nIndex ) {
   302                                 pszBuffer[ nIndex ] = pszBuffer[ nIndex - 1 ];
   304                             pszBuffer[ nPos++ ] = ch;
   310                 else if ( L
'\b' == ch ) {
   314                         for ( 
int nIndex = nPos; nCount > nIndex; ++nIndex ) {
   315                             pszBuffer[ nIndex - 1 ] = pszBuffer[ nIndex ];
   328                     WORD wVKey = sRecord.
m_sEvent.Event.KeyEvent.wVirtualKeyCode;
   329                     if ( VK_HOME == wVKey ) {
   337                     else if ( VK_END == wVKey ) {
   345                     else if ( VK_RIGHT == wVKey ) {
   347                         if ( nCount > nPos ) {
   356                     else if ( VK_LEFT == wVKey ) {
   367                     else if ( VK_DELETE == wVKey ) {
   369                         if ( nCount > nPos ) {
   371                             for ( 
int nIndex = nPos; ( nCount - 1 ) > nIndex; ++nIndex ) {
   372                                 pszBuffer[ nIndex ] = pszBuffer[ nIndex + 1 ];
   385                         if ( 
'V' == wVKey ) {
   387                             if ( 0 != ::OpenClipboard( 
nullptr ) ) {
   389                                 HANDLE hClipBoard = ::GetClipboardData( CF_UNICODETEXT );
   390                                 if ( 
nullptr != hClipBoard ) {
   392                                     LPCWSTR pszText = 
static_cast< LPCWSTR 
>( ::GlobalLock( hClipBoard ) );
   393                                     if ( 
nullptr != pszText ) {
   395                                         if ( nCount == nPos ) {
   397                                             pszBuffer[ nCount ] = L
'\0';
   400                                             ::wcscat_s( pszBuffer, nSize, pszText );
   403                                             nCount = 
static_cast< int >( ::wcslen( pszBuffer ) );
   420                                             int nLen = 
static_cast< int >( ::wcslen( pszText ) );
   421                                             if ( ( nSize - 1 ) < ( nCount + nLen ) ) {
   422                                                 nLen = ( nSize - nCount - 1 );
   424                                             wchar_t const* pszSrc = &pszBuffer[ nCount - 1 ];
   425                                             wchar_t*       pszDst = &pszBuffer[ nCount + nLen - 1 ];
   426                                             for ( 
int nIndex = 0, uCount2 = ( nCount - nPos ); uCount2 > nIndex; ++nIndex ) {
   427                                                 *pszDst-- = *pszSrc--;
   429                                             pszDst = &pszBuffer[ nPos ];
   430                                             for ( 
int nIndex = 0; nLen > nIndex; ++nIndex ) {
   431                                                 *pszDst++ = *pszText++;
   439                                     ::GlobalUnlock( hClipBoard );
   450                 if ( 0 <= nRedrawPos ) {
   452                     pszString = &pszBuffer[ nRedrawPos ];
   455                     if ( 0 == nRedrawPos ) {
   466                     for ( 
int nIndex = nRedrawPos; bResult; ++nIndex ) {
   468                         if ( nPos == nIndex ) {
   474                         if ( nCount <= nIndex ) {
   578                 if ( cTimer.
Wait( 0 ) ) {
   601             if ( 
nullptr != pszString ) {
   631             if ( 
nullptr != pszString ) {
   652                 ch = ::towupper( ch );
   653                 if ( L
'\033' == ch ) {
   659                 else if ( L
'N' == ch ) {
   665                 else if ( L
'Y' == ch ) {
   672                 else if ( ( L
'\r' == ch ) || ( L
'\n' == ch ) )  {
   694             CONSOLE_FONT_INFO sFontInfo;
   695             if ( 0 == ::GetCurrentConsoleFont( 
GetOutputHandle(), 
false, &sFontInfo ) ) {
   701             rnWidth  = sFontInfo.dwFontSize.X;
   702             rnHeight = sFontInfo.dwFontSize.Y;
   719             CONSOLE_SCREEN_BUFFER_INFO sInfo;
   720             if ( 0 == ::GetConsoleScreenBufferInfo( 
GetOutputHandle(), &sInfo ) ) {
   726             rnWidth  = sInfo.dwSize.X;
   727             rnHeight = sInfo.dwSize.Y;
   744             COORD sCoord = { 
static_cast< SHORT 
>( nWidth ), static_cast< SHORT >( nHeight ) };
   745             if ( 0 == ::SetConsoleScreenBufferSize( 
GetOutputHandle(), sCoord ) ) {
   765             CONSOLE_SCREEN_BUFFER_INFO sInfo;
   766             if ( 0 == ::GetConsoleScreenBufferInfo( 
GetOutputHandle(), &sInfo ) ) {
   772             rnLeft = sInfo.srWindow.Left;
   773             rnTop  = sInfo.srWindow.Top;
   790             CONSOLE_SCREEN_BUFFER_INFO sInfo;
   791             if ( 0 == ::GetConsoleScreenBufferInfo( 
GetOutputHandle(), &sInfo ) ) {
   798                 static_cast< SHORT 
>( nLeft ),
   799                 static_cast< SHORT >( nTop ),
   800                 static_cast< SHORT 
>( nLeft + sInfo.srWindow.Right  - sInfo.srWindow.Left ),
   801                 static_cast< SHORT >( nTop  + sInfo.srWindow.Bottom - sInfo.srWindow.Top ) };
   802             if ( 0 == ::SetConsoleWindowInfo( 
GetOutputHandle(), 
true, &sRect ) ) {
   822             CONSOLE_SCREEN_BUFFER_INFO sInfo;
   823             if ( 0 == ::GetConsoleScreenBufferInfo( 
GetOutputHandle(), &sInfo ) ) {
   829             rnLeft   = sInfo.srWindow.Left;
   830             rnTop    = sInfo.srWindow.Top;
   831             rnWidth  = ( sInfo.srWindow.Right  - rnLeft + 1 );
   832             rnHeight = ( sInfo.srWindow.Bottom - rnTop  + 1 );
   850                 static_cast< SHORT 
>( nLeft ),
   851                 static_cast< SHORT >( nTop ),
   852                 static_cast< SHORT 
>( nLeft + nWidth  - 1 ),
   853                 static_cast< SHORT >( nTop  + nHeight - 1 ) };
   854             if ( 0 == ::SetConsoleWindowInfo( 
GetOutputHandle(), 
true, &sRect ) ) {
   874             WINDOWINFO sWndInfo = { 
sizeof( WINDOWINFO ) };
   881             rnLeft   = sWndInfo.rcWindow.left;
   882             rnTop    = sWndInfo.rcWindow.top;
   883             rnWidth  = ( sWndInfo.rcWindow.right  - sWndInfo.rcWindow.left + 1 );
   884             rnHeight = ( sWndInfo.rcWindow.bottom - sWndInfo.rcWindow.top  + 1 );
   901             ::SetWindowPos( 
GetWindowHandle(), HWND_TOP, nLeft, nTop, nWidth, nHeight, ( SWP_NOACTIVATE | SWP_SHOWWINDOW ) );
   919             CONSOLE_SCREEN_BUFFER_INFO sInfo;
   920             if ( 0 == ::GetConsoleScreenBufferInfo( 
GetOutputHandle(), &sInfo ) ) {
   926             rnX = 
static_cast< int >( sInfo.dwCursorPosition.X );
   927             rnY = 
static_cast< int >( sInfo.dwCursorPosition.Y );
   944             COORD sCoord = { 
static_cast< SHORT 
>( nX ), static_cast< SHORT >( nY ) };
   965             CONSOLE_SCREEN_BUFFER_INFO sInfo;
   966             if ( 0 == ::GetConsoleScreenBufferInfo( 
GetOutputHandle(), &sInfo ) ) {
   972             rsCursor = sInfo.dwCursorPosition;
   989             if ( 0 == ::SetConsoleCursorPosition( 
GetOutputHandle(), rsCursor ) ) {
  1006         bool result = 
false;
  1009             SMALL_RECT sRect = {
  1010                 static_cast< SHORT 
>( nX ),
  1011                 static_cast< SHORT >( nY ),
  1012                 static_cast< SHORT 
>( nX ),
  1013                 static_cast< SHORT >( nY ) };
  1014             if ( 0 == ::SetConsoleWindowInfo( 
GetOutputHandle(), 
false, &sRect ) ) {
  1031         bool result = 
false;
  1034             INPUT_RECORD sRecord;
  1036             if ( 0 == ::PeekConsoleInputW( 
GetInputHandle(), &sRecord, 1, &dwCount ) ) {
  1041             else if ( 0 == dwCount ) {
  1046             else if ( 0 == ::ReadConsoleInputW( 
GetInputHandle(), &sRecord, 1, &dwCount ) ) {
  1051             else if ( 0 == dwCount ) {
  1057             rCh = sRecord.Event.KeyEvent.uChar.UnicodeChar;
  1071         bool result = 
false;
  1075             if ( 0 == ::GetNumberOfConsoleInputEvents( 
GetInputHandle(), &dwCount ) ) {
  1080             else if ( 0 == dwCount ) {
  1092             if ( 0 == ::PeekConsoleInputW( 
GetInputHandle(), sInputRecord, dwCount, &dwCount ) ) {
  1097             else for ( DWORD dwIndex = 0; dwCount > dwIndex; ++dwIndex ) {
  1099                 if ( KEY_EVENT == sInputRecord[ dwIndex ].EventType ) {
  1121             if ( 
nullptr == rpcInstance ) {
  1129                 INPUT_RECORD sEvent  = {};
  1131                 if ( ( 0 == ::ReadConsoleInputW( 
GetInputHandle(), &sEvent, 1, &dwCount ) ) || ( 0 == dwCount ) ) {
  1139                 else if ( MOUSE_EVENT == sEvent.EventType ) {
  1141                     if ( MOUSE_WHEELED == sEvent.Event.MouseEvent.dwEventFlags ) {
  1143                         short nDelta  = HIWORD( sEvent.Event.MouseEvent.dwButtonState );
  1144                         int   nScroll = ( -nDelta / WHEEL_DELTA );
  1154                 else if ( KEY_EVENT != sEvent.EventType ) {
  1159                 else if ( 0 == sEvent.Event.KeyEvent.bKeyDown ) {
  1167                 sRecord.
m_bShift   = ( 0 != ( 0x8000 & ::GetKeyState( VK_SHIFT ) ) );
  1168                 sRecord.
m_bControl = ( 0 != ( 0x8000 & ::GetKeyState( VK_CONTROL ) ) );
  1169                 sRecord.
m_bMenu    = ( 0 != ( 0x8000 & ::GetKeyState( VK_MENU ) ) );
  1174                     bool bInvalid = 
true;
  1179                         switch ( sEvent.Event.KeyEvent.wVirtualKeyCode ) {
  1212                     else switch ( sEvent.Event.KeyEvent.wVirtualKeyCode ) {
  1246                             HWND hActive = ::GetActiveWindow();
  1252                             if ( hActive != ::GetActiveWindow() ) {
  1253                                 ::SetActiveWindow( hActive );
  1326 #pragma managed( pop ) static bool GetBufferPosition(int &rnLeft, int &rnTop) noexcept
出力バッファ表示位置取得関数 
virtual HANDLE GetHandle() const  noexcept
オブジェクトハンドル取得関数 
#define NotifyConstructor()
コンストラクタ実行通知マクロ 
virtual int HitAnyKey(wchar_t const *pszString=nullptr, DWORD dwTime=INFINITE) noexcept
キー入力待ち関数 
COORD m_sMaxCursor
最大カーソル位置 
SInputRecord m_sRecordBuffer[RECORD_SIZE]
入力レコードリングバッファ 
static bool KbHitDirect() noexcept
コンソール入力バッファ直接検査関数 
#define NotifyFatalError()
致命的エラー発生通知マクロ 
wchar_t m_szBuffer[BUFFER_SIZE+1]
文字列バッファ 
static bool InputDirect(wchar_t &rCh) noexcept
コンソール入力バッファ直接入力関数 
#define NotifyDestructor()
デストラクタ実行通知マクロ 
static HANDLE GetOutputHandle() noexcept
出力ハンドル取得関数 
static bool GetSize(int &rnWidth, int &rnHeight) noexcept
出力バッファサイズ取得関数 
CThread m_cThreadSub
サブスレッド 
virtual bool Wait(DWORD dwTime=INFINITE) noexcept override
ウェイト関数 
virtual bool InputRecord(SInputRecord &rsRecord, DWORD dwTime) noexcept
入力レコード取得関数 
static HWND GetWindowHandle() noexcept
ウィンドウハンドル取得関数 
static bool GetCursorPosition(int &rnX, int &rnY) noexcept
カーソル位置取得関数 
#define ConsoleNewLine()                        
改行出力マクロ 
CConsole() noexcept
コンストラクタ 
virtual bool Wait(DWORD dwTime=INFINITE) noexcept
ウェイト関数 
virtual ~CConsole() noexcept
デストラクタ 
static bool GetFontSize(int &rnWidth, int &rnHeight) noexcept
フォントサイズ取得関数 
static int const KBHIT_RECORD_SIZE
直接入力検査レコードバッファサイズ 
static bool GetBufferArea(int &rnLeft, int &rnTop, int &rnWidth, int &rnHeight) noexcept
出力バッファ表示領域取得関数 
static bool SetBufferPosition(int nLeft, int nTop) noexcept
出力バッファ表示位置設定関数 
static bool SetBufferSize(int nWidth, int nHeight) noexcept
出力バッファサイズ設定関数 
virtual bool Create(wchar_t const *pszObjectName=nullptr) noexcept
作成関数 
virtual bool OutputChar(wchar_t ch) noexcept
1文字出力関数 
virtual void ClearInputBuffer() noexcept
入力バッファクリア関数 
static bool ScrollWindow(int nX, int nY) noexcept
ウィンドウスクロール関数 
int m_nRecordPos
入力レコード先頭位置 
static bool SetBufferArea(int nLeft, int nTop, int nWidth, int nHeight) noexcept
出力バッファ表示領域設定関数 
static bool SetCursorPosition(int nX, int nY) noexcept
カーソル位置設定関数 
virtual bool OutputString(wchar_t const *pszString) noexcept override
文字列出力関数 
#define ConsoleLine(...)                        
ヘッダインデントなし書式設定文字列行出力マクロ 
int m_nRecordCount
入力レコードカウント 
static int const BUFFER_SIZE
文字列バッファサイズ 
static bool SetCursor(COORD const &rsCursor) noexcept
カーソル位置設定関数 
static bool SetWindowArea(int nLeft, int nTop, int nWidth, int nHeight) noexcept
ウィンドウ表示領域設定関数 
static bool GetCursor(COORD &rsCursor) noexcept
カーソル位置取得関数 
virtual void Close() noexcept override
クローズ関数 
static DWORD WINAPI SubThreadProc(LPVOID lpParam) noexcept
サブスレッド関数 
virtual bool InputChar(wchar_t &rCh) noexcept override
1文字入力関数 
virtual bool YesNoKey(wchar_t const *pszString=nullptr, DWORD dwTime=INFINITE) noexcept
確認入力待ち関数 
LIB_COMMON_API bool SetWindowPosition(HWND hWnd, EWindowPosition ePos) noexcept
ウィンドウ表示位置設定関数 
static HANDLE GetInputHandle() noexcept
入力ハンドル取得関数 
static int const RECORD_SIZE
入力レコードリングバッファサイズ 
virtual int InputString(wchar_t *pszBuffer, int nSize) noexcept override
文字列入力関数 
bool m_bStopInput
入力中止要求フラグ 
static bool GetWindowArea(int &rnLeft, int &rnTop, int &rnWidth, int &rnHeight) noexcept
ウィンドウ表示領域取得関数