Keep C# program on top of all Windows messages.
I have a program that I'm trying to make secure, and keep users from accessing any Windows items, and the problem I'm having is whenever there's a Windows update message, or an Antivirus message from the task bar it shows up over my program, and I can't have that happen. How can I prevent this?
Kirtan PatelPosted Oct 21, 2009, 2:27 PM
and it will top of all Popups
thats it :)
check "do you like this answer" if it helps you :)
Kirtan PatelPosted Oct 21, 2009, 2:55 PM
it will put your window Top of all the Window even any dialog of Windows even if its not opened by ShowDialog()
check "Do you like this answer" if it helps you :)
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,int Y, int cx, int cy, uint uFlags);
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
static readonly IntPtr HWND_TOP = new IntPtr(0);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, this.Height, this.Width, TOPMOST_FLAGS);
}
BryanPosted Oct 21, 2009, 2:28 PM
I do that, and it still shows up. The problem is my program starts up the form automatically with the Application.Run(new Desktop), so it doesn't use ShowDialog.