tags:

views:

321

answers:

4

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
I do not understand this, how do I tell it which application to be on top?
Levo
The hWnd parameter specifies the window that should be moved to the top.
Jon Benedicto
+3  A: 

SetWindowPos with .NET

Svetlozar Angelov
How do I call "MakeTopMost"?
Levo
+1  A: 

C#

this.TopMost = true;
Pieter888
I don't know about C and C++ though...
Pieter888
This will not help for other windows except the application form.
Levo
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