diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41afb57 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +/.idea/ +/cmake-build-debug/ +/cmake-build-release/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6c5ab6a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.28) +project(black_screen_app) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_GENERATOR_PLATFORM "Win32") + +if (MSVC) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ob2 /Oi /Ot /Oy /GL /GS-") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") +endif() + +add_executable(black_screen_app WIN32 + src/app/main.cpp + src/app/WindowInitiator.cpp + src/app/WindowInitiator.hpp +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea1ec41 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Black Screen Application +[![C++](https://img.shields.io/badge/C%2B%2B-23-blue.svg "C++ Standard")](https://en.cppreference.com/w/cpp/23) +[![CMake](https://img.shields.io/badge/CMake-3.28-important.svg "CMake Version")](https://cmake.org/) + +[![Windows x86](https://img.shields.io/badge/Windows-x86-lightgrey?logo=windows)](https://www.microsoft.com/) +[![Windows x64](https://img.shields.io/badge/Windows-x64-551a8b?logo=windows)](https://www.microsoft.com/) + +The Black Screen App is a simple yet effective tool designed to display a fully black screen on your Windows computer. Whether you're looking to save energy, eliminate distractions, or simply need a black backdrop, this app has you covered. + +## Features + +- **Full-Screen Blackout**: Fills your entire screen with pure black color. +- **Compatibility**: Supports both 32-bit (x32) and 64-bit (x64) Windows versions. + +## Quick Start + +1. **Launch**: Double-click the app icon to run. +2. **Exit**: Simply press any key to close the app and return to your desktop. + +## Acknowledgments + +- Thanks to all the contributors who have helped make this app better. +- Special thanks to the community for the valuable feedback and support. + +--- + +Enjoy the simplicity and utility of the Black Screen App! diff --git a/src/app/WindowInitiator.cpp b/src/app/WindowInitiator.cpp new file mode 100644 index 0000000..ae38786 --- /dev/null +++ b/src/app/WindowInitiator.cpp @@ -0,0 +1,62 @@ +// +// Created by spoil on 04/14/2024. +// + +#include "WindowInitiator.hpp" +#include + +LRESULT CALLBACK HandleWindowMessages(HWND windowHandle, UINT messageType, WPARAM windowParameterValue, LPARAM messageData); + +void WindowInitiator::createWindow() { + const WNDCLASS windowClass = { + .lpfnWndProc = HandleWindowMessages, + .hInstance = GetModuleHandle(nullptr), + .lpszClassName = "BlackWindowClass" + }; + RegisterClass(&windowClass); + + const auto windowHandle = CreateWindowEx( + 0, + "BlackWindowClass", + "Black Screen Application", + WS_POPUP | WS_VISIBLE, + CW_USEDEFAULT, + CW_USEDEFAULT, + GetSystemMetrics(SM_CXSCREEN), + GetSystemMetrics(SM_CYSCREEN), + nullptr, + nullptr, + GetModuleHandle(nullptr), + nullptr + ); + + ShowCursor(false); + + ShowWindow(windowHandle, SW_SHOW); + UpdateWindow(windowHandle); + + MSG message; + while (GetMessage(&message, nullptr, 0, 0)) { + TranslateMessage(&message); + DispatchMessage(&message); + } +} + +LRESULT CALLBACK HandleWindowMessages(const HWND windowHandle, const UINT messageType, const WPARAM windowParameterValue, const LPARAM messageData) { // NOLINT(*-misplaced-const) + switch (messageType) { + case WM_CLOSE: + case WM_KEYDOWN: + case WM_DESTROY: + PostQuitMessage(0); + return 0; + case WM_ERASEBKGND: { + RECT clientRect; + GetClientRect(windowHandle, &clientRect); + FillRect(reinterpret_cast(windowParameterValue), &clientRect, static_cast(GetStockObject(BLACK_BRUSH))); + return 1; + } + default: + return DefWindowProc(windowHandle, messageType, windowParameterValue, messageData); + } +} + diff --git a/src/app/WindowInitiator.hpp b/src/app/WindowInitiator.hpp new file mode 100644 index 0000000..b4bf882 --- /dev/null +++ b/src/app/WindowInitiator.hpp @@ -0,0 +1,15 @@ +// +// Created by spoil on 04/14/2024. +// + +#ifndef WINDOWINITIATOR_HPP +#define WINDOWINITIATOR_HPP + + +class WindowInitiator { +public: + static void createWindow(); +}; + + +#endif //WINDOWINITIATOR_HPP diff --git a/src/app/main.cpp b/src/app/main.cpp new file mode 100644 index 0000000..dbce7f1 --- /dev/null +++ b/src/app/main.cpp @@ -0,0 +1,8 @@ +#include +#include "WindowInitiator.hpp" + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + WindowInitiator::createWindow(); + + return 0; +}