gpt4 book ai didi

c++ - Win32::SetForegroundWindow() 一直不工作

转载 作者:可可西里 更新时间:2023-11-01 13:22:53 24 4
gpt4 key购买 nike

我正在开发一个消息传递工具。消息窗口是整个应用程序的一部分。当有消息传来时,我需要窗口转到前面。我正在使用这段代码:

    if( m_hwnd == NULL || !::IsWindow(m_hwnd) )
return E_UNEXPECTED;

if(::IsIconic(m_hwnd))
{
::ShowWindowAsync( m_hwnd, SW_RESTORE );
}
::SetWindowPos(m_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
::SetForegroundWindow(m_hwnd);
if( pvbProcessed != NULL )
*pvbProcessed = VARIANT_TRUE;

return S_OK;

我什至尝试过 TOPMOST,但在某些情况下它仍然不起作用。我还尝试了::BringToFront()。

任何人都可以帮助或解释为什么它不起作用?这是已知的 Microsoft 限制吗?

最佳答案

The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:

  • The process is the foreground process.
  • The process was started by the foreground process.
  • The process received the last input event.
  • There is no foreground process.
  • The foreground process is being debugged.
  • The foreground is not locked (see LockSetForegroundWindow).
  • The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
  • No menus are active.

参见 SetForegroundWindow() docs了解更多详情。

关于c++ - Win32::SetForegroundWindow() 一直不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19136365/

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