gpt4 book ai didi

c++ - 如何使窗口出现在所有内容之上(甚至是全屏游戏!)c++/Qt

转载 作者:可可西里 更新时间:2023-11-01 16:41:11 27 4
gpt4 key购买 nike

我正在尝试制作一个在屏幕中央显示十字准线并保持在其他所有内容之上的应用程序。目的是在某些不提供十字准线的 FPS 游戏中使用十字准线。除了游戏之外,我已经成功地将我的窗口置于最顶部:/

这是我的代码:(一切都是主要的,因为我只测试我的应用程序的核心功能,我对它进行了广泛的评论,试图让我的问题更容易理解)

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();

我的猜测是游戏等应用程序可以更直接地控制显示设备。我正在寻找这个问题的任何解决方案(不一定是涉及透明最顶层窗口的解决方案)。如果有人可以向我解释如何有效地使用 GetLastError(),以及为什么游戏的行为与普通窗口不同,还有旁注。

提前致谢。

最佳答案

我知道这对您没有帮助,但请查看 this post来自 Raymond Chen:How do I create a topmost window that is never covered by other topmost windows?

关于c++ - 如何使窗口出现在所有内容之上(甚至是全屏游戏!)c++/Qt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10210754/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com