मैं स्क्रीन के केंद्र में एक क्रॉसहेयर प्रदर्शित करने और बाकी सब कुछ के ऊपर रहने के लिए एक एप्लिकेशन बनाने की कोशिश कर रहा हूं। लक्ष्य कुछ एफपीएस खेलों में क्रॉसहेयर रखना है जो एक प्रदान नहीं करता है। मैंने सफलतापूर्वक गेम को छोड़कर सब कुछ के लिए अपनी खिड़की को सबसे ऊपर बनाया है:/सब कुछ के ऊपर एक विंडो कैसे दिखें (यहां तक कि पूर्ण स्क्रीन गेम!) C++/Qt
यहां मेरा कोड है: (सबकुछ मुख्य है क्योंकि मैं केवल अपने ऐप की मुख्य कार्यक्षमताओं का परीक्षण कर रहा हूं, मैंने इसे बड़े पैमाने पर टिप्पणी करने के लिए टिप्पणी की है और मेरी समस्या अधिक सुलभ बनाने)
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();
मेरा अनुमान है कि आवेदन के खेल प्रदर्शन उपकरण के ऊपर एक और अधिक प्रत्यक्ष नियंत्रण है इस तरह के रूप में है। मैं इस समस्या के किसी भी समाधान की तलाश में हूं (एक पारदर्शी शीर्षतम खिड़की से जुड़े neccesseraly नहीं)। एक sidenote पर भी अगर कोई मुझे समझ सकता है कि GetLastError() का प्रभावी ढंग से उपयोग कैसे करें, और यह भी एक आम खिड़की से अलग तरीके से क्यों व्यवहार कर रहे हैं।
अग्रिम धन्यवाद।
स्क्रीन पर एक बिंदु खींचने के लिए एक हाई-टेक समाधान के लिए +1 जहां ironsights केंद्र: पी – Bojangles
ओह! मैं जानता हूं कि एक-एक-दिल से। यह 'ACCESS_DENIED' है :(GetLastError() संख्या से वास्तविक त्रुटि संदेश प्राप्त करने के लिए कुछ API है, लेकिन मैं इसे अभी भूल गया हूं। –
मुझे आनंद मिलता है कि यह 'सबसे ऊपर' टैग का उपयोग करता है। :) – unwind