Change foreground window

Christopher 弋 1 Reputation point


I found that I can only setForegroundWindow() once. If I do it again it'll raise error.

I need one of my apps to stay on top and a mask (Qt Application) will be added on top of that window. The mask can actually be seen, but it does not respond to keyboard events.

I have tried SetFocus() and SetActive() neither of them worked.

Many thanks,

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
1,893 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 65,371 Reputation points

    I need one of my apps to stay on top

    You can set it TopMost, like :

    SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);  

    To set windows to foreground, apps like Task Manager use :

     SwitchToThisWindow(hWnd, TRUE);