【发布时间】:2019-03-04 12:18:10
【问题描述】:
我在 Visual Studio 中制作了运行 Qt 应用程序(Qt 版本 5.11.1)的单实例。第一次执行后,我的主窗口将打开,我将关闭它。它一直在后台运行。
当我第二次运行.exe时,我想打开我第一次打开的前一个主窗口。
我正在枚举可用的窗口标题,我得到 "Test Window" 标题。但是使用这个 HWND 我正在尝试使用SetForegroundWindow(hwnd); 在每个其他窗口的顶部设置前景。
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
if (IsWindowVisible(hwnd)) // check whether window is visible
{
char wnd_title[256];
GetWindowText(hwnd, wnd_title, sizeof(wnd_title));
MessageBox(0, wnd_title, "Installation Error", MB_OK | MB_ICONEXCLAMATION);
if (strcmp(wnd_title, "Test Window") == 0)
{
SetForegroundWindow(hwnd);
int err = GetLastError();
string msg = "error code " + std::to_string(err);
MessageBox(0, msg.c_str(),"Installation Error ", MB_OK | MB_ICONEXCLAMATION);
return false;
}
}
return true; // function must return true if you want to continue enumeration
}
当我第二次运行时,如何在所有其他窗口之上的 Qt MainWindow 上打开。
【问题讨论】: