简体   繁体   English

MFC/C++ Bring window to top 不再有效

[英]MFC/C++ Bring window to top no longer works

I have a 32-bit application built on MFC/C++.我有一个基于 MFC/C++ 构建的 32 位应用程序。 It was ported from Visual C++ (6.0) to Studio 2015.它从 Visual C++ (6.0) 移植到 Studio 2015。

The application needs to come to the top when new data appears.当新数据出现时,应用程序需要到达顶部。 On a couple of my customer systems the window does not come to the front as another application seems to want to stay on top.在我的几个客户系统上,window 没有出现在前面,因为另一个应用程序似乎想保持在最前面。 This code (in MainFrm.cpp) was working fine prior to the 2015 port (same "topmost" source code).此代码(在 MainFrm.cpp 中)在 2015 年端口(相同的“最顶层”源代码)之前运行良好。

... ...

HWND hCurrWnd;
int iMyTID;
int iCurrTID;

hCurrWnd = ::GetForegroundWindow();
iMyTID   = GetCurrentThreadId();
iCurrTID = GetWindowThreadProcessId(hCurrWnd,0);

::AttachThreadInput(iCurrTID, iMyTID, TRUE);
::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
::SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
::SetForegroundWindow(m_hWnd);
::SetFocus(m_hWnd);
::SetActiveWindow(m_hWnd);
::AttachThreadInput(iCurrTID, iMyTID, FALSE);

... ...

Is there another, more robust method for forcing a window to the top in MFC?是否有另一种更强大的方法可以将 window 强制到 MFC 的顶部?

Use MFC functions direct, not the underlying WinApi. I tested this in Win10 with VS2019.直接使用 MFC 函数,而不是底层 WinApi。我在 Win10 和 VS2019 中测试了这个。

RESULT CMainFrame::OnNewDataReceived_UM( WPARAM wParam, LPARAM lParam )
{
    :  
    if (IsIconic())
        ShowWindow(SW_RESTORE);
    SetForegroundWindow();
    :
  } 

   returen TRUE;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM