user197967
user197967

Reputation:

C/C++/C# SetWindowPos: Window on top of others

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

Answers (4)

ZombieSheep
ZombieSheep

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

Pieter888
Pieter888

Reputation: 4992

C#

this.TopMost = true;

Upvotes: 1

Svetlozar Angelov
Svetlozar Angelov

Reputation: 21660

SetWindowPos with .NET

Upvotes: 2

Jon Benedicto
Jon Benedicto

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

Related Questions