From dbe96e7055203c56d33d30d54a3e923a17902615 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Mon, 18 Sep 2023 11:09:05 +0000 Subject: [PATCH] init --- .devcontainer/Dockerfile | 21 ++++++++ .devcontainer/devcontainer.json | 39 ++++++++++++++ .gitignore | 2 + .vscode/cmake-kits.json | 9 ++++ .vscode/launch.json | 29 +++++++++++ .vscode/settings.json | 64 +++++++++++++++++++++++ .vscode/tasks.json | 15 ++++++ CMakeLists.txt | 15 ++++++ README.md | 1 + src/main.c | 91 +++++++++++++++++++++++++++++++++ 10 files changed, 286 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .gitignore create mode 100644 .vscode/cmake-kits.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 src/main.c diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..476b969 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,21 @@ +# [Choice] Debian / Ubuntu version (use Debian 12, Debian 11, Ubuntu 22.04 on local arm64/Apple Silicon): debian-12, debian-11, debian-10, ubuntu-22.04, ubuntu-20.04 +ARG VARIANT=debian-12 +FROM mcr.microsoft.com/devcontainers/base:${VARIANT} +USER root + +# Install needed packages. Use a separate RUN statement to add your own dependencies. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install build-essential cmake cppcheck valgrind clang lldb llvm gdb \ + && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# [Optional] Uncomment this section to install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends \ + mingw-w64 \ + mingw-w64-i686-dev \ + mingw-w64-x86-64-dev \ + gdb-mingw-w64 \ + gdb-mingw-w64-target \ + clang-format \ + ninja-build \ + && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..9cfc80c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,39 @@ +{ + "name": "C++", + "build": { + "dockerfile": "Dockerfile" + }, + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined" + ], + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "true", + "username": "vscode", + "userUid": "1000", + "userGid": "1000" + }, + "ghcr.io/maks1ms/devcontainers-features/wine:0": {}, + "ghcr.io/devcontainers/features/desktop-lite:1": {} + }, + "customizations": { + "vscode": { + "settings": {}, + "extensions": [ + "ms-vscode.cpptools-extension-pack", + "xaver.clang-format" + ] + } + }, + "forwardPorts": [ + 6080 + ], + "portsAttributes": { + "6080": { + "label": "desktop" + } + }, + "remoteUser": "vscode" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47d3961 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +depends diff --git a/.vscode/cmake-kits.json b/.vscode/cmake-kits.json new file mode 100644 index 0000000..945ef36 --- /dev/null +++ b/.vscode/cmake-kits.json @@ -0,0 +1,9 @@ +[ + { + "name": "GCC 8.3-posix (i686-w64-mingw32)", + "compilers": { + "C": "i686-w64-mingw32-gcc-posix", + "CXX": "i686-w64-mingw32-g++-posix" + } + } +] \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..97279ba --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "args": [], + "cwd": "${workspaceFolder}", + "environment": [], + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/i686-w64-mingw32-gdb", + "debugServerArgs": "Z:/usr/share/win32/gdbserver.exe localhost:1111 ${command:cmake.launchTargetPath} ${command:cmake.launchTargetPath} arg1 arg2", + "miDebuggerServerAddress": "localhost:1111", + "serverStarted":"Listening\\ on\\ port\\ \\d*", + "debugServerPath": "/usr/bin/wine", + "filterStderr":true, + "filterStdout":false, + "logging": { + "moduleLoad": true, + "programOutput": true, + "exceptions": true + }, + "preLaunchTask": "pkill gdbserver", + "postDebugTask": "pkill gdbserver" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d62387d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,64 @@ +{ + "files.associations": { + "*.ts": "typescriptreact", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "set": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "windows.h": "c" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..a8d0a01 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "pkill gdbserver", + "type": "shell", + "command": "pkill gdbserver || true", + "group": "test", + "presentation": { + "reveal": "never", + "panel": "shared" + } + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..29aa553 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.5) +project(hello) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_EXE_LINKER_FLAGS "-static -mwindows") +set(CMAKE_EXECUTABLE_SUFFIX ".exe") +set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) + +add_executable(hello + src/main.c) + +target_link_libraries(hello PRIVATE) + +install(TARGETS hello DESTINATION bin) diff --git a/README.md b/README.md new file mode 100644 index 0000000..683132b --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Hello world! \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..7ba93b4 --- /dev/null +++ b/src/main.c @@ -0,0 +1,91 @@ +#ifndef UNICODE +#define UNICODE +#endif + +#include +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) +{ + HWND hwnd; + MSG msg; + WNDCLASSEX wcex; + + wcex.cbSize = sizeof(wcex); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcex.lpszMenuName = NULL; + wcex.lpszClassName = L"HelloWin"; + wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + RegisterClassEx(&wcex); + + hwnd = CreateWindow(wcex.lpszClassName, // window class name + L"Hello World", // window caption + WS_OVERLAPPEDWINDOW, // window style + CW_USEDEFAULT, // initial x position + CW_USEDEFAULT, // initial y position + CW_USEDEFAULT, // initial x size + CW_USEDEFAULT, // initial y size + NULL, // parent window handle + NULL, // window menu handle + hInstance, // program instance handle + NULL); // creation parameters + + if (hwnd) + { + ShowWindow(hwnd, iCmdShow); + UpdateWindow(hwnd); + + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + return 0; +} + +LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) +{ + + switch (iMsg) + { + case WM_CREATE: + return 0; // return -1 to cancel the creation of the window + + case WM_PAINT: + { + HDC hdc; + PAINTSTRUCT ps; + RECT rect; + + hdc = BeginPaint(hwnd, &ps); + + GetClientRect(hwnd, &rect); + SetBkMode(hdc, TRANSPARENT); + + DrawText(hdc, L"Hello World!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + EndPaint(hwnd, &ps); + } + return 0; + + case WM_CLOSE: + if (MessageBox(hwnd, L"Sure?", L"Confirm Close", MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) == IDYES) + DestroyWindow(hwnd); + return 0; + + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + + return DefWindowProc(hwnd, iMsg, wParam, lParam); +} \ No newline at end of file