Estoy tratando de hacer que una aplicación muestre una cruz en el centro de la pantalla y esté al tanto de todo lo demás. El objetivo es tener una cruz en algunos juegos de FPS que no proporciona uno. He hecho con éxito mi ventana más alta para todo, excepto los juegos:/Cómo hacer que una ventana aparezca encima de todo (incluso juegos de pantalla completa) C++/Qt
Aquí está mi código: (todo está en general ya que solo estoy probando las funciones principales de mi aplicación, lo he comentado extensamente para probar y hacer que mi problema sea más accesible)
QApplication app(argc, argv);
DWORD error;
QWidget window;
QLabel *label = new QLabel(&window);
label->setText("<strong>O<strong>");//I'm using an "O" as a crosshair until I can figure out how to display image transparency.
window.setGeometry(960-label->width()/2,540-label->height()/2,label->width(),label->height());//here I'm making my window appear in the center of my screen
window.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);// here making the window frameless and topMost via qt
window.setAttribute(Qt::WA_TranslucentBackground);//making the window see through
window.setWindowTitle("Crosshair");
window.show();
//in this next part I tried using windows api to make my window appear on top of the game.
HWND handle, myHandle;
myHandle = FindWindow(NULL,TEXT("Crosshair"));//retieving my own application window handle
if(myHandle == 0){cout << "no own handle" << endl;}//it successfully retrieves it
handle = FindWindow(NULL,TEXT("Killing Floor"));//retrieving a game window handle
if(handle == 0){cout << "no KF handle" << endl;}//it successfully retrieves it
if(handle != 0 && myHandle != 0)
{
if(SetWindowPos(handle,myHandle,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE) == 0){cout << "couldnt set notopmost" << endl;}//here SetWindowPos returns 0 (function failed)
}
// I've also tried using SetWindowPos to set the game to Not TOPMOST, it didnt work either.
// here was my code : SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
error = GetLastError();// i tried using GetLastError to understand what was happening
cout << error << endl;// but it only returns "5", I've read that you can look in WINNT.H for information about the meanings of error codes
// however its a pretty big file and I wasn't able to understand where the relevant part was.
return app.exec();
mi conjetura es que la aplicación tales como juegos tienen un control más directo sobre el dispositivo de visualización. Estoy buscando alguna solución a este problema (no necesariamente uno que implica una ventana superior transparente). También en una nota al margen si alguien podría explicarme cómo usar efectivamente GetLastError(), y también por qué los juegos se comportan de manera diferente a una ventana común.
Gracias de antemano.
+1 para una solución de alta tecnología para dibujar un punto en la pantalla donde se encuentra el centro de mirillas: P – Bojangles
¡Oh! Lo sé uno por descuido. Es 'ACCESS_DENIED' :(Hay alguna API para obtener el mensaje de error real del número GetLastError(), pero lo he olvidado por ahora. –
Me gusta que esto use la etiqueta 'topmost'. :) – unwind