1
I play an FPS game with the sniper class, but the sniper does not appear as the other weapons, which hinders me when targeting the enemy. I made a program that draws a sight on the screen. It is composed of a transparent window that has the same screen dimensions. But when I run the game I can not interact with it because the application of the aim does not allow. How can I do so that I can play normally but with my application running? I want the application to run in the background without disturbing my computer use.
Here is 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;
}
It is not that your application prevents you from interacting with the game, but the operating system that understands that the game is in the background (and thus the focus of the interaction is all given to your application). You can try to make your application be of the "Stay On Top" type, and return the focus to the game, but as the game probably uses Opengl and goes to full screen this "trick" probably won’t work. The most correct would be you make some plugin or some change directly in the game code (or play it as it was designed to be played).
– Luiz Vieira
Anyway, I have doubts whether this question is within the scope of the site.
– Luiz Vieira