Change foreground window

Christopher 弋 1 Reputation point
2022-06-08T17:12:55.467+00:00

Hi,

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,
Christopher

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.
2,710 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 86,496 Reputation points
    2022-06-08T17:27:17.53+00:00

    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);  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.