commit e3bb1f9a28d08bbb02ac6fe50de897aed3a71837 Author: II-Paulus-II Date: Mon Mar 17 15:12:34 2025 +0000 commit basics of project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3558c56 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin/ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7e3d761 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +# Specify the minimum required version of CMake +cmake_minimum_required(VERSION 3.10) + +# Set the project name and version +project(MessiVsRonaldo VERSION 1.0) + +# Specify the C++ standard (e.g., C++17) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# Set the output directory for the executable +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) + +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}) +file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + +# Automatically find all .cpp files in the src directory +file(GLOB SOURCES "src/*.cpp") + +# Add an executable target +add_executable(MessiVsRonaldo ${SOURCES}) + +# Include the "include" directory (if you have header files) +target_include_directories(MessiVsRonaldo PUBLIC ${CMAKE_SOURCE_DIR}/include) \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..dab8110 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Cross Platform test with CMAKE, win32 and x11 + diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..aa94673 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,46 @@ + + +#ifdef _WIN32 +#include +// Tells msvc compiler to not show the console window +#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup") + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow); +#endif + +#ifdef __linux__ +#include +#include +#include +#include +#include + +void showMessageBox(Display *display, const char *title, const char *message); +#endif + +int main(){ + + #ifdef _WIN32 + HINSTANCE hInstance = GetModuleHandle(nullptr); + + LPSTR lpCmdLine = GetCommandLineA(); + + return WinMain(hInstance, nullptr, lpCmdLine, SW_SHOWDEFAULT); + #endif + + #ifdef __linux__ + Display *display = XOpenDisplay(NULL); + if (!display) { + fprintf(stderr, "Unable to open X display\n"); + return 1; + } + + // Show the message box + showMessageBox(display, "X11 Message Box", "Hello, X11!"); + + // Close the connection to the X server + XCloseDisplay(display); + #endif + + return 0; +} diff --git a/src/winmain.cpp b/src/winmain.cpp new file mode 100644 index 0000000..a56b6c1 --- /dev/null +++ b/src/winmain.cpp @@ -0,0 +1,10 @@ + +#ifdef _WIN32 +#include + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + MessageBox(nullptr, "Hello, World!", "Win32 Application", MB_OK); + return 0; +} + +#endif \ No newline at end of file diff --git a/src/xeleven.cpp b/src/xeleven.cpp new file mode 100644 index 0000000..ae09252 --- /dev/null +++ b/src/xeleven.cpp @@ -0,0 +1,56 @@ + +#ifdef __linux__ + +#include +#include +#include +#include +#include + +// Function to display a message box +void showMessageBox(Display *display, const char *title, const char *message) { + // Open a connection to the X server + int screen = DefaultScreen(display); + + // Create a simple window + Window window = XCreateSimpleWindow( + display, RootWindow(display, screen), + 100, 100, 400, 200, 1, + BlackPixel(display, screen), WhitePixel(display, screen) + ); + + // Set the window title + XStoreName(display, window, title); + + // Select events to handle + XSelectInput(display, window, ExposureMask | KeyPressMask); + + // Create a graphics context for drawing + GC gc = XCreateGC(display, window, 0, NULL); + + // Map the window (make it visible) + XMapWindow(display, window); + + // Event loop + XEvent event; + while (1) { + XNextEvent(display, &event); + + // Handle expose event (window needs to be redrawn) + if (event.type == Expose) { + // Draw the message in the window + XDrawString(display, window, gc, 50, 100, message, strlen(message)); + } + + // Handle key press event (close the window) + if (event.type == KeyPress) { + break; + } + } + + // Clean up + XFreeGC(display, gc); + XDestroyWindow(display, window); +} + +#endif \ No newline at end of file