commit basics of project

This commit is contained in:
II-Paulus-II 2025-03-17 15:12:34 +00:00
commit e3bb1f9a28
7 changed files with 140 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
bin/
build/

24
CMakeLists.txt Normal file
View File

@ -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)

0
CMakePresets.json Normal file
View File

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# Cross Platform test with CMAKE, win32 and x11

46
src/main.cpp Normal file
View File

@ -0,0 +1,46 @@
#ifdef _WIN32
#include <windows.h>
// 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 <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}

10
src/winmain.cpp Normal file
View File

@ -0,0 +1,10 @@
#ifdef _WIN32
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MessageBox(nullptr, "Hello, World!", "Win32 Application", MB_OK);
return 0;
}
#endif

56
src/xeleven.cpp Normal file
View File

@ -0,0 +1,56 @@
#ifdef __linux__
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 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