2012-04-18 11 views
8

मैं स्क्रीन के केंद्र में एक क्रॉसहेयर प्रदर्शित करने और बाकी सब कुछ के ऊपर रहने के लिए एक एप्लिकेशन बनाने की कोशिश कर रहा हूं। लक्ष्य कुछ एफपीएस खेलों में क्रॉसहेयर रखना है जो एक प्रदान नहीं करता है। मैंने सफलतापूर्वक गेम को छोड़कर सब कुछ के लिए अपनी खिड़की को सबसे ऊपर बनाया है:/सब कुछ के ऊपर एक विंडो कैसे दिखें (यहां तक ​​कि पूर्ण स्क्रीन गेम!) 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() का प्रभावी ढंग से उपयोग कैसे करें, और यह भी एक आम खिड़की से अलग तरीके से क्यों व्यवहार कर रहे हैं।

अग्रिम धन्यवाद।

+0

स्क्रीन पर एक बिंदु खींचने के लिए एक हाई-टेक समाधान के लिए +1 जहां ironsights केंद्र: पी – Bojangles

+0

ओह! मैं जानता हूं कि एक-एक-दिल से। यह 'ACCESS_DENIED' है :(GetLastError() संख्या से वास्तविक त्रुटि संदेश प्राप्त करने के लिए कुछ API है, लेकिन मैं इसे अभी भूल गया हूं। –

+0

मुझे आनंद मिलता है कि यह 'सबसे ऊपर' टैग का उपयोग करता है। :) – unwind

उत्तर

1

SetWindowPos() प्रलेखन से:

एक विंडो HWND_TOPMOST को hWndInsertAfter पैरामीटर और यह सुनिश्चित करना कि SWP_NOZORDER ध्वज सेट नहीं है द्वारा एक सर्वोच्च खिड़की या तो किया जा सकता है, या में एक खिड़की की स्थिति की स्थापना द्वारा ज़ेड ऑर्डर ताकि यह किसी मौजूदा शीर्ष विंडो से ऊपर हो। जब गैर-शीर्षतम विंडो शीर्ष पर बनाई जाती है, तो इसकी स्वामित्व वाली विंडो भी शीर्ष पर बनाई जाती हैं। हालांकि, इसके मालिक नहीं बदले गए हैं।

इसके अलावा एक ही पृष्ठ से

:

SetWindowPos का उपयोग करने के लिए, प्रक्रिया है कि खिड़की का मालिक SetForegroundWindow अनुमति होना आवश्यक है शीर्ष करने के लिए एक खिड़की को लाने के लिए।

हालांकि, मुझे लगता है कि लिंक विंडोज विस्टा और ऊपर के लिए है।

2

मैं जानता हूँ कि यह वास्तव में आप मदद नहीं करता है, लेकिन कृपया रेमंड चेन से this post पर एक नजर है: How do I create a topmost window that is never covered by other topmost windows?

+0

जैसे अलर्ट दिखाने के लिए ऐसा करना चाहता हूं यह स्थिति बहुत अलग है। –

1

मैंने पाया कि C++ पुस्तकालय DirectDrawOverlayLib यह करने के लिए सक्षम होना चाहिए।

एक अप्रबंधित सी ++ पुस्तकालय बनाने, प्रबंधित और DirectDraw ओवरले के लिए आकर्षित करने के लिए: वेबसाइट के शब्दों में। .NET क्लाइंट्स के लिए सी ++/सीएलआई रैपर शामिल है।

डायरेक्टड्रा ओवरले विशेष डायरेक्टड्रा सतह हैं जो पूर्ण स्क्रीन गेम और एप्लिकेशन सहित अन्य सभी चीज़ों पर दिखाए जाते हैं। उनका उपयोग XFire जैसे प्रोग्रामों को लागू करने के लिए किया जा सकता है जो पूर्णस्क्रीन गेम ऑपरेशन के दौरान जानकारी प्रदर्शित करते हैं।

संबंधित मुद्दे