Reputation:
I would like someone to give a working example of SetWindowPos on how to make a window "topmost" (be on top and stay there) using either C/C++/C#. Thanks in advance!
Upvotes: 5
Views: 9706
Reputation: 29953
I ran into this issue a while ago, and asked the question here. The actual details of my issue were probably not the same as yours, but just in case, I'll summarise my question and the answer.
I needed to keep a particular (WPF) application foremost all the time it was running to attempt to deny access to other software on the machine. I ended up running a timer every 1/4 second that makes a call out to user32.dll's SetForegroundWindow(IntPtr hWnd)
method to grab focus to the app, along with setting TopMost = true
on my window.
HTH
Upvotes: 1
Reputation: 10582
C/C++:
// This doesn't size or move the window, just makes it top-most.
SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
Upvotes: 4