Last active
          July 28, 2025 12:30 
        
      - 
      
- 
        Save Alia5/5d8c48941d1f73c1ef14967a5ffe33d5 to your computer and use it in GitHub Desktop. 
Revisions
- 
        Alia5 revised this gist Nov 14, 2016 . 1 changed file with 48 additions and 114 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,126 +1,60 @@ #include <SFML/Graphics.hpp> #include <Windows.h> #include <Dwmapi.h> #pragma comment (lib, "Dwmapi.lib") int main() { sf::RenderWindow window(sf::VideoMode(1280, 720), "Transparent Window"); window.setFramerateLimit(60); MARGINS margins; margins.cxLeftWidth = -1; SetWindowLong(window.getSystemHandle(), GWL_STYLE, WS_POPUP | WS_VISIBLE); DwmExtendFrameIntoClientArea(window.getSystemHandle(), &margins); //CircleShape for DemoContent sf::CircleShape shape(360.f); shape.setFillColor(sf::Color::Green); //\ sf::Vector2i grabbedOffset; bool grabbedWindow = false; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed || event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) window.close(); else if (event.type == sf::Event::MouseButtonPressed) { if (event.mouseButton.button == sf::Mouse::Left) { grabbedOffset = window.getPosition() - sf::Mouse::getPosition(); grabbedWindow = true; } } else if (event.type == sf::Event::MouseButtonReleased) { if (event.mouseButton.button == sf::Mouse::Left) grabbedWindow = false; } else if (event.type == sf::Event::MouseMoved) { if (grabbedWindow) window.setPosition(sf::Mouse::getPosition() + grabbedOffset); } } window.clear(sf::Color::Transparent); //F*ck yeah it works as you would expect from the wording ;P window.draw(shape); window.display(); } return 0; } 
- 
        Alia5 renamed this gist Nov 13, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewingFile renamed without changes.
- 
        Alia5 created this gist Nov 13, 2016 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,126 @@ #include <SFML/Graphics.hpp> #include <cmath> #include <windows.h> bool setShape(HWND hWnd, const sf::Image& image) { const sf::Uint8* pixelData = image.getPixelsPtr(); HRGN hRegion = CreateRectRgn(0, 0, image.getSize().x, image.getSize().y); // Determine the visible region for (unsigned int y = 0; y < image.getSize().y; y++) { for (unsigned int x = 0; x < image.getSize().x; x++) { if (pixelData[y * image.getSize().x * 4 + x * 4 + 3] == 0) { HRGN hRegionDest = CreateRectRgn(0, 0, 1, 1); HRGN hRegionPixel = CreateRectRgn(x, y, x + 1, y + 1); CombineRgn(hRegionDest, hRegion, hRegionPixel, RGN_XOR); DeleteObject(hRegion); DeleteObject(hRegionPixel); hRegion = hRegionDest; } } } SetWindowRgn(hWnd, hRegion, true); DeleteObject(hRegion); return true; } bool setTransparency(HWND hWnd, unsigned char alpha) { SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); SetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA); return true; } int main() { sf::Vector2i grabbedOffset; bool grabbedWindow = false; const unsigned char opacity = 255; sf::Image backgroundImage; backgroundImage.loadFromFile("image.png"); sf::Vector2u pixsize = backgroundImage.getSize(); sf::RenderWindow window(sf::VideoMode(pixsize.x,pixsize.y, 32), "Transparent Window", sf::Style::None); setShape(window.getSystemHandle(), backgroundImage); setTransparency(window.getSystemHandle(), opacity); sf::Texture backgroundTexture; sf::Sprite backgroundSprite; backgroundTexture.loadFromImage(backgroundImage); backgroundSprite.setTexture(backgroundTexture); sf::RectangleShape rectangle; rectangle.setSize(sf::Vector2f(100, 50)); while (window.isOpen()) { SetWindowPos(window.getSystemHandle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { //obsługa zajścia zdarzenia wciśnięcia klawisza ESC window.close(); //np. zamknięcie aplikacji } //Drag&Drop else if (event.type == sf::Event::MouseButtonPressed) { if (event.mouseButton.button == sf::Mouse::Left) { grabbedOffset = window.getPosition() - sf::Mouse::getPosition(); grabbedWindow = true; } } else if (event.type == sf::Event::MouseButtonReleased) { if (event.mouseButton.button == sf::Mouse::Left) grabbedWindow = false; } else if (event.type == sf::Event::MouseMoved) { if (grabbedWindow) window.setPosition(sf::Mouse::getPosition() + grabbedOffset); } // } //while window.clear(sf::Color::Transparent); window.draw(backgroundSprite); window.display(); } //while return 0; }