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!
+1
A:
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 );
Jon Benedicto
2009-12-09 15:23:15
I do not understand this, how do I tell it which application to be on top?
Levo
2009-12-09 18:17:23
The hWnd parameter specifies the window that should be moved to the top.
Jon Benedicto
2009-12-09 18:49:09
A:
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
ZombieSheep
2009-12-09 15:30:43