Last active
January 8, 2024 16:48
-
-
Save Alia5/5d8c48941d1f73c1ef14967a5ffe33d5 to your computer and use it in GitHub Desktop.
Transparent SFML Window
This file contains 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 characters
#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; | |
} |
Hello m1rz0, I tryed out the code. At first i don't get any errors. but then when i tryed to compile it i get this: "undefined reference to `DwmExtendFrameIntoClientArea' collect2.exe: error: ld returned 1 exit status". Can you or someone help. thanks! Rmi333
You need to link against Dwmapi.lib
link against? You mean i have to link dwmapi.dll in the def file? Also i am using Visual Studio Code. So i have to add the dll? where do i finde it?
Ah thanks i think i figured out what you ment. I added -ldwmapi to the command to compile and it worked. Thank you all! and for the Code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello m1rz0, I tryed out the code. At first i don't get any errors. but then when i tryed to compile it i get this: "undefined reference to `DwmExtendFrameIntoClientArea' collect2.exe: error: ld returned 1 exit status".
Can you or someone help.
thanks!
Rmi333