Win32 :: SetForegroundWindow()一直不工作 [英] Win32 ::SetForegroundWindow() not working all the time

查看:224
本文介绍了Win32 :: SetForegroundWindow()一直不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通讯工具。消息传递窗口是整个应用程序的一部分。收到一些消息时,我需要将窗口转到最前面。我正在使用此代码:

I'm working on a messenging tool. The messaging window is part of a whole application. I need the window to go to the front when there are some messages coming. I'am using this code :

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

I even tried to do a TOPMOST but still in some cases it does not work. I also Tried a ::BringToFront().

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

Anyone can help or give an explanation on why it doen not work ? Is it a known microsoft limitation.

推荐答案


系统限制了哪些进程可以设置前台窗口。只有在以下
条件之一为true的情况下,
进程才能设置前景窗口:

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:


  • 该进程为

  • 该过程由前台过程启动。

  • 该过程收到了最后一个输入事件。

  • 没有前台进程。

  • 正在调试前台进程。

  • 前台未锁定(请参见LockSetForegroundWindow)。

  • 前台锁定超时已到期(请参见SystemParametersInfo中的SPI_GETFOREGROUNDLOCKTIMEOUT)。

  • 没有菜单处于活动状态。

  • 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()文档

这篇关于Win32 :: SetForegroundWindow()一直不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆