From 8c4603c73675958efc960fbd4bb599a2909d106a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 16 Jan 2023 14:52:43 +0100 Subject: Source codes --- Examples/WhisperDesktop/Utils/DebugConsole.h | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Examples/WhisperDesktop/Utils/DebugConsole.h (limited to 'Examples/WhisperDesktop/Utils/DebugConsole.h') diff --git a/Examples/WhisperDesktop/Utils/DebugConsole.h b/Examples/WhisperDesktop/Utils/DebugConsole.h new file mode 100644 index 0000000..a9ee8f2 --- /dev/null +++ b/Examples/WhisperDesktop/Utils/DebugConsole.h @@ -0,0 +1,64 @@ +#pragma once +#include +#include +#include + +class AppState; +class DebugConsole +{ + using eLogLevel = Whisper::eLogLevel; + + struct Entry + { + eLogLevel level; + CStringA message; + HRESULT print( HANDLE hConsole, CString& tempString ) const; + }; + + CComAutoCriticalSection critSec; + std::deque buffer; + CString tempString; + CHandle output; + + inline void logSink( eLogLevel lvl, const char* message ); + static void __stdcall logSinkStatic( void* context, eLogLevel lvl, const char* message ); + + static BOOL __stdcall consoleHandlerRoutine( DWORD dwCtrlType ); + + static DebugConsole* pGlobalInstance; + void windowClosed(); + + std::unordered_set checkboxes; + + CStringA tempStringA; + void log( eLogLevel lvl, const char* pszFormat, va_list args ); + +public: + HRESULT initialize( eLogLevel level = eLogLevel::Debug ); + ~DebugConsole(); + + HRESULT show(); + HRESULT hide(); + bool isVisible() const { return output; } + + void addCheckbox( CButton& cb ); + void removeCheckbox( CButton& cb ); + + static void logMessage( eLogLevel lvl, const char* pszFormat, va_list args ); +}; + +class ConsoleCheckbox +{ + CButton control; + DebugConsole* console = nullptr; + +public: + HRESULT initialize( HWND dialog, int idc, AppState& state ); + void click(); + ~ConsoleCheckbox() + { + if( nullptr != console ) + console->removeCheckbox( control ); + } + void ensureChecked(); +}; \ No newline at end of file -- cgit v1.2.3