В настоящее время я использую следующий код, чтобы открыть окно приложения:
Код: Выделить всё
appWindow->setWindowState(static_cast(appWindow->windowState() & ~Qt::WindowMinimized));
const auto winId = appWindow->winId();
#ifdef Q_OS_WIN
QWindowsWindowFunctions::setWindowActivationBehavior(QWindowsWindowFunctions::AlwaysActivateWindow);
appWindow->requestActivate();
// Setting rights for the process to move window to foreground
// They get reset after user input
AllowSetForegroundWindow(ASFW_ANY);
// Getting window handles for QApp and currently active process
HWND appWinHandle = HWND(winId);
HWND curWinHandle = GetForegroundWindow();
DWORD appWinThreadID = GetCurrentThreadId();
DWORD curWinThreadID = GetWindowThreadProcessId(curWinHandle, NULL);
// Forcing qWindow raise by setting it to be topmost and releasing right after
SetWindowPos(appWinHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
SetWindowPos(appWinHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
AllowSetForegroundWindow(curWinThreadID);
// Moving input thread from current process to qApp
// Simulate Alt press and release to ensure qApp process got focus
keybd_event(VK_MENU, 0, 0, 0);
SetForegroundWindow(appWinHandle);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
AttachThreadInput(curWinThreadID, appWinThreadID, FALSE);
SetFocus(appWinHandle);
SetActiveWindow(appWinHandle);
Подробнее здесь: https://stackoverflow.com/questions/793 ... tification