Программирование звука в Windows (C++)
#ifndef DConsoleH #define DConsoleH #include <string> #include <iomanip> #include <sstream> class DCons { public: DCons(bool isEnabled = true); ~DCons(); void WriteLn(std::string message); void WriteLn(int value); void WriteLn(float value); void WriteLn(std::string message, int value); void WriteLn(std::string message, float value); void WriteError(std::string message); void WriteError(std::string message, int value); void WriteError(std::string message, float value); private: HANDLE hConsoleOutput; DWORD NumberOfCharsWritten; LPVOID lpReserved; bool consoleIsEnabled; }; #endif
#include "DConsole.h" DCons::DCons(bool isEnabled) { consoleIsEnabled = isEnabled; if (!consoleIsEnabled) return; if (!AllocConsole()) { MessageBox(NULL, "Failed to create the console!", "Debug console error", MB_OK|MB_ICONEXCLAMATION); hConsoleOutput = NULL; } else { hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); } } //----------------------------------------------------------------------------- DCons::~DCons() { if (!consoleIsEnabled) return; if (!FreeConsole()) MessageBox(NULL, "Could not free the console!", "Debug console error!", MB_OK); } //----------------------------------------------------------------------------- void DCons::WriteLn(std::string message) { if (!consoleIsEnabled) return; message += "\n"; if (hConsoleOutput) WriteConsole(hConsoleOutput, // handle to a console screen buffer message.c_str(), // pointer to buffer to write from message.size(), // number of characters to write &NumberOfCharsWritten, // pointer to number of characters written lpReserved); // reserved } //----------------------------------------------------------------------------- void DCons::WriteLn(int value) { if (!consoleIsEnabled) return; std::ostringstream strStream; strStream << value; WriteLn(strStream.str()); } //------------------------------------------------------------------------------ void DCons::WriteLn(float value) { if (!consoleIsEnabled) return; std::ostringstream strStream; strStream << value; WriteLn(strStream.str()); } //------------------------------------------------------------------------------ void DCons::WriteLn(std::string message, int value) { if (!consoleIsEnabled) return; std::ostringstream strStream; strStream << message << value; WriteLn(strStream.str()); } //------------------------------------------------------------------------------ void DCons::WriteLn(std::string message, float value) { if (!consoleIsEnabled) return; std::ostringstream strStream; strStream << message << value; WriteLn(strStream.str()); } //------------------------------------------------------------------------------ void DCons::WriteError(std::string message) { WriteLn("------------- ERROR MESSAGE: --------------"); WriteLn(message); WriteLn("-------------------------------------------"); } //------------------------------------------------------------------------------ void DCons::WriteError(std::string message, int value) { WriteLn("------------- ERROR MESSAGE: --------------"); WriteLn(message, (int)value); WriteLn("-------------------------------------------"); } //------------------------------------------------------------------------------ void DCons::WriteError(std::string message, float value) { WriteLn("------------- ERROR MESSAGE: --------------"); WriteLn(message, (float)value); WriteLn("-------------------------------------------"); } //------------------------------------------------------------------------------
Программирование звука в Windows (C++)