KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to make an application displaying a crosshair at the center of the screen and staying on top of everything else. The aim is to have a crosshair in some FPS games that doesn't provide one. I've succesfully made my window topmost for everything except the games :/ Here is my code : (everything is in the main since im only testing the core functionalitys of my app, I've commented it extensively to try and make my problem more accessible) 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
Tags (comma-separated)
Save Edits
Cancel