OpenBarnyard
 
Loading...
Searching...
No Matches
TDebugConsole Class Reference

#include <TDebugConsole_Win.h>

Public Member Functions

 TDebugConsole ()
 
 ~TDebugConsole ()
 
TBOOL Show (TBOOL state)
 
TBOOL Toggle ()
 
TBOOL IsVisible () const
 
TBOOL IsCreated () const
 
HWND FindConsole () const
 

Detailed Description

Definition at line 9 of file TDebugConsole_Win.h.

Constructor & Destructor Documentation

◆ TDebugConsole()

TDebugConsole::TDebugConsole ( )

Definition at line 25 of file TDebugConsole_Win.cpp.

26{
27 m_HWND = FindConsole();
28 m_Created = m_HWND != TNULL;
29
30 m_LogListener.Connect(
32 this,
33 TDebugConsole::OnLog,
34 1
35 );
36}
#define TNULL
Definition Typedefs.h:23
HWND FindConsole() const
static TEmitter< TUtil, TUtil::LogEvent > & GetLogEmitter()
Definition TUtil.h:117

◆ ~TDebugConsole()

TDebugConsole::~TDebugConsole ( )

Definition at line 38 of file TDebugConsole_Win.cpp.

39{
40 if ( IsCreated() )
41 {
42 if ( IsVisible() )
43 {
44 TWARN( "Press any key to exit...\n" );
45 _getch();
46 }
47 }
48}
#define TWARN(...)
Definition Defines.h:152
TBOOL IsVisible() const
TBOOL IsCreated() const

Member Function Documentation

◆ FindConsole()

HWND TDebugConsole::FindConsole ( ) const

Definition at line 67 of file TDebugConsole_Win.cpp.

68{
69 TString8 str = TString8( TDebugConsoleUUID );
70
71 // Generate title for the console so we can find it's HWND
72 LARGE_INTEGER time;
73 QueryPerformanceCounter( &time );
74 TCHAR timeHex[ sizeof( time.QuadPart ) + 1 ] = { 0 };
75 _ultoa_s( (unsigned long)time.QuadPart, timeHex, 0x10 );
76 str += timeHex;
77
78 // Save the current title
79 TCHAR lpConsoleTitle[ 256 ];
80 DWORD titleLength = GetConsoleTitleA( lpConsoleTitle, 256 );
81 if ( titleLength == 0 ) { return TNULL; }
82
83 // Set the genereated title and wait for 50ms so it's applied
84 SetConsoleTitleA( str );
85 ThreadSleep( 50 );
86
87 // Find a window with the generated title and restore it
88 HWND consoleHWND = FindWindowA( TNULL, str );
89 SetConsoleTitleA( lpConsoleTitle );
90
91 return consoleHWND;
92}
TOSHI_NAMESPACE_START constexpr const TCHAR * TDebugConsoleUUID
void ThreadSleep(TUINT dwMilliseconds)
char TCHAR
Definition Typedefs.h:20

◆ IsCreated()

TBOOL TDebugConsole::IsCreated ( ) const
inline

Definition at line 22 of file TDebugConsole_Win.h.

22{ return m_Created; }

◆ IsVisible()

TBOOL TDebugConsole::IsVisible ( ) const
inline

Definition at line 19 of file TDebugConsole_Win.h.

19{ return m_Visible; }

◆ Show()

TBOOL TDebugConsole::Show ( TBOOL state)

Definition at line 50 of file TDebugConsole_Win.cpp.

51{
52 TBOOL oldState = m_Visible;
53 m_Visible = state;
54
55 ShowWindow( m_HWND, state );
56 UpdateWindow( m_HWND );
57
58 return oldState;
59}
bool TBOOL
Definition Typedefs.h:6

◆ Toggle()

TBOOL TDebugConsole::Toggle ( )

Definition at line 61 of file TDebugConsole_Win.cpp.

62{
63 Show( !m_Visible );
64 return m_Visible;
65}
TBOOL Show(TBOOL state)

The documentation for this class was generated from the following files: