Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit 02d1e51

Browse files
author
tomasmark79
committed
added WindowsHeaders.hpp for Windows Compatibility Support
1 parent cc86bd8 commit 02d1e51

File tree

3 files changed

+56
-43
lines changed

3 files changed

+56
-43
lines changed

src/Logger/ConsoleLogger.hpp

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,7 @@
1616
#include "fmt/core.h"
1717

1818
#ifdef _WIN32
19-
#ifndef NOMINMAX
20-
#define NOMINMAX
21-
// Disable min/max macros in windows.h to avoid conflicts with std::min/max
22-
// cxxopts.hpp uses std::min/max
23-
#endif
24-
25-
// Undefine Raylib functions to avoid conflicts
26-
#define Rectangle WindowsRectangle
27-
#define CloseWindow WindowsCloseWindow
28-
#define ShowCursor WindowsShowCursor
29-
#define DrawText WindowsDrawText
30-
#define PlaySound WindowsPlaySound
31-
#define PlaySoundA WindowsPlaySoundA
32-
#define PlaySoundW WindowsPlaySoundW
33-
#define LoadImage WindowsLoadImage
34-
#define DrawTextEx WindowsDrawTextEx
35-
36-
#include <windows.h>
37-
38-
// Restore Raylib functions
39-
#undef Rectangle
40-
#undef CloseWindow
41-
#undef ShowCursor
42-
#undef DrawText
43-
#undef PlaySound
44-
#undef PlaySoundA
45-
#undef PlaySoundW
46-
#undef LoadImage
47-
#undef DrawTextEx
48-
19+
#include "../WindowsHeaders.hpp"
4920
#endif
5021

5122
class ConsoleLogger : public dotnamecpp::logging::ILogger {
@@ -99,7 +70,8 @@ class ConsoleLogger : public dotnamecpp::logging::ILogger {
9970
void critical (const std::string& message, const std::string& caller = "") override {
10071
log (dotnamecpp::logging::Level::LOG_CRITICAL, message, caller);
10172
};
102-
void log (dotnamecpp::logging::Level level, const std::string& message, const std::string& caller) {
73+
void log (dotnamecpp::logging::Level level, const std::string& message,
74+
const std::string& caller) {
10375
// thread-safety
10476
std::lock_guard<std::mutex> lock (logMutex_);
10577

@@ -202,13 +174,15 @@ class ConsoleLogger : public dotnamecpp::logging::ILogger {
202174
}
203175

204176
#ifdef _WIN32
205-
static void setConsoleColorWindows (Level level) {
206-
const std::map<Level, WORD> colorMap
207-
= { { Level::LOG_DEBUG, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY },
208-
{ Level::LOG_INFO, FOREGROUND_GREEN | FOREGROUND_INTENSITY },
209-
{ Level::LOG_WARNING, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY },
210-
{ Level::LOG_ERROR, FOREGROUND_RED | FOREGROUND_INTENSITY },
211-
{ Level::LOG_CRITICAL,
177+
static void setConsoleColorWindows (dotnamecpp::logging::Level level) {
178+
const std::map<dotnamecpp::logging::Level, WORD> colorMap
179+
= { { dotnamecpp::logging::Level::LOG_DEBUG,
180+
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY },
181+
{ dotnamecpp::logging::Level::LOG_INFO, FOREGROUND_GREEN | FOREGROUND_INTENSITY },
182+
{ dotnamecpp::logging::Level::LOG_WARNING,
183+
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY },
184+
{ dotnamecpp::logging::Level::LOG_ERROR, FOREGROUND_RED | FOREGROUND_INTENSITY },
185+
{ dotnamecpp::logging::Level::LOG_CRITICAL,
212186
FOREGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_BLUE } };
213187
auto it = colorMap.find (level);
214188
if (it != colorMap.end ()) {
@@ -251,8 +225,8 @@ class ConsoleLogger : public dotnamecpp::logging::ILogger {
251225
bool includeCaller_ = true;
252226
bool includeLevel_ = true;
253227

254-
void logToStream (std::ostream& stream, dotnamecpp::logging::Level level, const std::string& message,
255-
const std::string& caller, const std::tm& now_tm) {
228+
void logToStream (std::ostream& stream, dotnamecpp::logging::Level level,
229+
const std::string& message, const std::string& caller, const std::tm& now_tm) {
256230
setConsoleColor (level);
257231
stream << buildHeader (now_tm, caller, level) << message;
258232
resetConsoleColor ();

src/Utils/Utils.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
// -----------------------------------------------------
2929

3030
#ifdef _WIN32
31-
#include <windows.h>
32-
#elif defined(__APPLE__)
31+
#include "../WindowsHeaders.hpp"
32+
#endif
33+
34+
#if defined(__APPLE__)
3335
#include <limits.h>
3436
#include <mach-o/dyld.h>
35-
#else // Linux
37+
#elif defined(__linux__)
3638
#include <unistd.h>
3739
#endif
3840

src/WindowsHeaders.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef WINDOWS_HEADERS_HPP
2+
#define WINDOWS_HEADERS_HPP
3+
4+
// Universal Windows.h wrapper with Raylib compatibility
5+
// Include this instead of <windows.h> directly to avoid conflicts
6+
7+
#ifdef _WIN32
8+
#ifndef NOMINMAX
9+
#define NOMINMAX
10+
// Disable min/max macros in windows.h to avoid conflicts with std::min/max
11+
#endif
12+
13+
// Protect Raylib functions from Windows.h macro conflicts
14+
#define Rectangle WindowsRectangle
15+
#define CloseWindow WindowsCloseWindow
16+
#define ShowCursor WindowsShowCursor
17+
#define DrawText WindowsDrawText
18+
#define PlaySound WindowsPlaySound
19+
#define LoadImage WindowsLoadImage
20+
#define DrawTextEx WindowsDrawTextEx
21+
22+
#include <windows.h>
23+
24+
// Restore Raylib function names
25+
#undef Rectangle
26+
#undef CloseWindow
27+
#undef ShowCursor
28+
#undef DrawText
29+
#undef PlaySound
30+
#undef LoadImage
31+
#undef DrawTextEx
32+
33+
#endif // _WIN32
34+
35+
#endif // WINDOWS_HEADERS_HPP
36+
37+
// MIT License Copyright (c) 2024-2025 Tomáš Mark

0 commit comments

Comments
 (0)