如何在QT中获取背景应用程序窗口标题
How to get background application window title in QT?
在我的qt应用程序中,当我按下按钮时,我需要显示背景应用程序窗口标题。目前,我用来管理此操作,以便在"设置"调用之前调用" GetBackgroundWindowTitle"函数。因此,这为我返回了背景应用程序窗口标题。我目前的实现如下
MyWindow::MyWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MyWindow)
{
g_window_title = getBackgroundWindowTitle();
ui->setupUi(this);
}
void MyWindow::OnPushbuttonPressed()
{
ui->labelBackgroundWindowTitle.setText(g_window_title);
}
QString MyWindow::getBackgroundWindowTitle()
{
char buff[256];
HWND hwnd = GetForegroundWindow(); //currently this gives my current application window title
GetWindowText(hwnd, (LPWSTR) buff, 254);
QString title = QString::fromWCharArray((const wchar_t *)buff);
return title;
}
但是,此代码的问题是,当背景应用程序窗口更改时,我需要重新启动应用程序以再次获取背景标题,因为" GetBackgroundWindowTitle"需要在设置调用之前调用。
我正在寻找任何时间解决方案,以至于当用户按下按钮时,应检索背景应用程序窗口标题。
有人可以帮助我修改我的代码吗?
如果它是z-order中的上一个(或下一个,请参见链接(窗口,则可以使用: GetNextWindow
,例如:
QString MyWindow::getBackgroundWindowTitle()
{
char buff[256];
HWND myHwnd = GetForegroundWindow();
HWND hwnd = GetNextWindow(myHwnd, GW_HWNDNEXT);
GetWindowText(hwnd, (LPWSTR) buff, 254);
QString title = QString::fromWCharArray((const wchar_t *)buff);
return title;
}
现在,如果我理解您的问题,您只需要将呼叫转到getBackgroundWindowTitle
到您的按钮处理程序:
void MyWindow::OnPushbuttonPressed()
{
ui->labelBackgroundWindowTitle.setText(getBackgroundWindowTitle());
}
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- C++控制台应用程序阻止退出
- 码头化的C++应用程序是否向后兼容早期的内核版本
- 将应用程序从32位移植到64位时出现问题
- 如何改变c++应用程序的视觉效果
- WM_CTLCOLORSTATIC从未在WIN32应用程序中触发
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 如何在QT中获取背景应用程序窗口标题
- 从头开始创建C 背景Win32应用程序
- 打开不同的图像文件,并使用GDI 库在主应用程序窗口的背景上绘制它们
- QtGui应用程序背景颜色样式表
- 如何设置Windows窗体应用程序(c++)有一个Aero/Glass背景
- 如何从应用程序控制背景音乐