SFML Style Application Always On Top

1

I play a game of FPS with the class sniper, but the sniper does not appear the aim as in the other weapons, which disturbs me when looking at the enemy. I did a program that draws a crosshair. It is composed of a transparent window that has the same dimensions of the screen. But when I play the game I can not interact with it because the application of the crosshairs does not allow. How can I do so that I can play normally but with my application running? I want the application to be running in the background without disrupting my computer usage.

Here's my code:

#include <SFML/Graphics.hpp>
#include <Windows.h>
#include <dwmapi.h>

#pragma comment (lib, "Dwmapi.lib")

int main()
{
    sf::ContextSettings contextSettings;
    contextSettings.antialiasingLevel = 8;
    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Crosshair", sf::Style::Default, contextSettings);

    SetWindowPos(window.getSystemHandle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
    MARGINS margins;
    margins.cxLeftWidth = -1;

    SetWindowLong(window.getSystemHandle(), GWL_STYLE, WS_POPUP | WS_VISIBLE);
    DwmExtendFrameIntoClientArea(window.getSystemHandle(), &margins);

    sf::CircleShape crosshair(2.f);
    crosshair.setOrigin(2, 2);
    crosshair.setFillColor(sf::Color::Transparent);
    crosshair.setOutlineThickness(3);
    crosshair.setOutlineColor(sf::Color::Green);

    sf::Vector2f centerPoint(window.getSize().x / 2.f, window.getSize().y / 2.f);
    crosshair.setPosition(centerPoint);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color::Transparent);
        window.draw(crosshair);
        window.display();
    }

    return 0;
}
    
asked by anonymous 18.03.2017 / 00:17

0 answers